Skip to content Skip to sidebar Skip to footer

Save Pixel Data In Txt Format In Pil

My program is to extract the pixel from an image and to save the pixel data in the text file for analysis. My picture is a binary image that gives only 255 and 0 's Here is the pro

Solution 1:

Just create a file writer object and write the value of the variable pixel to that.

from PIL import Image

im = Image.open("thresh.jpg")
fil = open('file', 'w')
pixel = im.load()
row, column = im.size
for y in range(column):
    for x in range(row):
        pixel = pix[x, y]
        fil.write(str(pixel) + '\n')
fil.close()

Post a Comment for "Save Pixel Data In Txt Format In Pil"