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):
python output of code (scaled down 500 x 500):
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
Post a Comment