Python Imaging Library makes an image reddish -


i have opened grayscale image using python imaging library, copied every pixel value image variable of same size , saved it. when open new image image viewer looks reddish. have used image.new() method , without "white" , "black" arguments got same reddish output.

my code:

from pil import image import math  def run():     im = image.open("hrabowski.jpg")     pix = im.load()     print im.size     # print pix[0, 1]      im2 = image.new("rgb", (2400, 2400))      in range(im.size[0]):         j in range(im.size[0]):             im2.putpixel((i, j), pix[i, j])      im2.save("hrabowski-2400-2400.jpg") 

original image (scaled down 500 x 500):

enter image description here

python output of code (scaled down 500 x 500):

enter image description here

could please tell me doing wrong?

your problem want create rgb image has 3 channels. therefore 1 pixel value consists of 3 values , not 1 (in case use gray value of original image each of channels).

i have modified code accordingly.

a side remark: sure there better way want achieve, there no need loop through single pixels, not sure after.

from pil import image import math  def run():     im = image.open("zhig0.jpg")     pix = im.load()     print im.size     # print pix[0, 1]      im2 = image.new("rgb", (2400, 2400))      in range(im.size[0]):         j in range(im.size[0]):             im2.putpixel((i, j), (pix[i, j],pix[i, j],pix[i, j]))      im2.save("zhig0-2400-2400.jpg") run() 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -