-1

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 program:

from PIL import Image

im = Image.open("thresh.jpg")
pixel = im.load()
row, column = im.size
for y in range(column)
    for x in range(row)
        pixel = pix[x, y]

Question:

I want to save the pixel data in a text file. Suggest me some techniques to save the data.

Phoenix
  • 3,996
  • 4
  • 29
  • 40
Naveen Raja
  • 193
  • 1
  • 2
  • 8

1 Answers1

2

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()
Josh Peak
  • 5,898
  • 4
  • 40
  • 52
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274