Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image #Import the Image module from the PIL library
- image = Image.open('image.png') #Create a path to the image file
- rgb_image = image.convert('RGB') #Convert the image to RGB
- width, height = image.size #Assign the image's width and height to variables
- new_image = Image.new('RGB', (width,height)) #Create a grid for the output image
- new2_image = Image.new('RGB', (width,height))
- new3_image = Image.new('RGB', (width,height))
- grey_image = Image.new('RGB', (width,height))
- grey2_image = Image.new('RGB', (width,height))
- grey3_image = Image.new('RGB', (width,height))
- #Set up loops to modify each pixel within the image
- for row in range(height):
- for col in range(width):
- r, g, b = rgb_image.getpixel((col, row))
- # a black white filter
- bw =round( max(r,g,b) /255) *255
- bw2=round( ((r+g+b)/3) /255) *255
- bw3=round( min(r,g,b) /255) *255
- gr =max(r,g,b)
- gr2=round( (r+g+b)/3)
- gr3=min(r,g,b)
- new_image.putpixel( (col, row), (bw,bw,bw) )
- new2_image.putpixel( (col, row), (bw2,bw2,bw2) )
- new3_image.putpixel( (col, row), (bw3,bw3,bw3) )
- grey_image.putpixel( (col, row), (gr,gr,gr) )
- grey2_image.putpixel( (col, row), (gr2,gr2,gr2) )
- grey3_image.putpixel( (col, row), (gr3,gr3,gr3) )
- #new_image.save("black-white.png")
- new_image.show()
- new2_image.show()
- new3_image.show()
- grey_image.show()
- grey2_image.show()
- grey3_image.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement