![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programming Guru
![]() |
Grayscale Converter with Pygame
Yeah, I was bored, so I made a pic --> grayscale program in Pygame.
fileName = "python.gif"
red = False
green = True
blue = False
########################
from pygame.image import load, save
pic = load(fileName)
for x in range(pic.get_width()):
for y in range(pic.get_height()):
c = list(pic.get_at((x,y))[:3])
deg = (c[0]*red + c[1]*green + c[2]*blue) / (red + green + blue)
pic.fill( [deg]*3, ((x,y),(1,1)) )
save(pic, "%s_%s%s%s.bmp"%(fileName.split('.')[0],
'R'*red,
'G'*green,
'B'*blue))The user can select if it measures the degree based on R, G or B. Or any combination of the latter. A good example of manipulating boolean values I guess. Here's an example: http://netpub.cstudies.ubc.ca/oleary/images/python.gif Outputs: http://img204.imageshack.us/img204/8374/pythong4qm.png I think it actually works quite beautifully. Bleeeeh. ^_^ |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Heh, cool. You might wanna try and write the PIL equivalent - should be easy peasy using the Image.point function.
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
Python Image Library?
But that would mean I'd have to learn new functions... hmmm... >_> I'm thinking of maybe doing more image conversions/manipulations. Any ideas? And by the way, in my program, if you replace the True/False with a number. It'll take that number and use it as a percentage/weight. Pretty cool. |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5
![]() |
Maybe:
from PIL import Image, ImageEnhance image = Image.open(filename) greyscale_image = ImageEnhance.Color(image).enhance(0.0) |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Feb 2005
Posts: 434
Rep Power: 4
![]() |
Going from a color .jpg to grayscale:
# PIL convert to grayscale mode "L"
import Image
im1 = Image.open("Arevos.jpg")
im2 = im1.convert("L")
im2.show()
im2.save("ArevosGray.jpg")
__________________
I looked it up on the Intergnats! |
|
|
|
|
|
#6 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
<troll>
Now make one that goes from black and white to color </troll> I think i'd tweak the red/green/blue values to be integers or even doubles, to provide a different weighting of colors. IIRC a blue generally shows up 'darker' than a simiairly bright green. Overall though good job, and interresting use of boolean 'division' -MBirchmeier |
|
|
|
|
|
#8 | |
|
Programming Guru
![]() |
"I think i'd tweak the red/green/blue values to be integers or even doubles, to provide a different weighting of colors. IIRC a blue generally shows up 'darker' than a simiairly bright green."
Quote:
>_> |
|
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
**Disclaimer : Anything stupid I say in this post and previous and/or future posts are subject to mockery, however any information in said posts are not to be used for any legal or for trade applications. Additionally any failure to fully read or comprehend the posts of others shall in no way detract from or preclude my ability to sound like a 'know-it-all' or expert.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|