0

I need to read 64x64 pgm plain format image files and put the resulting values in a numpy matrix. I can do it only if I use Opencv and PIL functions to open the image, but the final numpy matrix yielded has 3-channel and the values returned are 0 and 255, instead of 0 and 1 (the image is binary). I also tried to use genfromtxt but it can't put the values in a numpy matrix.

I only want a 1 channel numpy matrix with 0 and 1's from the pgm image. How can I do that with python?

mad
  • 2,677
  • 8
  • 35
  • 78

1 Answers1

0

If PIL opens your image files as RGB but you want them in binary, I think your only choice is to convert after opening.

im = Image.open('imagefile').convert('1')
Dan Allan
  • 34,073
  • 6
  • 70
  • 63