0

I have an image file called "test.png"

I want to be able to read the image file as follows:

with open("test.png", "rb") as f:
        input = f.read()

#Do some pre-processing on "input"

input_array = #some operation on the variable "input" to convert it to a numpy array

#processing "input_array"

output_dat = #some operation to convert input_array into the same format as variable "input"

Now, I want to be able to turn this input data into a numpy array. How would I go about doing this, and vice-versa i.e., I also want to be able to convert it back to the format as input is in.

  1. Convert input to a numpy array format
  2. Convert numpy array back to the same format as input
Blue
  • 653
  • 1
  • 11
  • 26
  • Have you seen : https://stackoverflow.com/questions/31386096/importing-png-files-into-numpy ? – JacobIRR Feb 05 '18 at 18:34
  • I am required to read the files in the way I have mentioned above because there is some processing done on the data in that format. – Blue Feb 05 '18 at 18:36
  • 1
    It seems that `imageio.imread` also works when you pass `input` as the argument instead of the filename – brm Feb 05 '18 at 18:51
  • Oh great! It does work. Is there also a way to turn a numpy array into the format that the variable `input` is in? – Blue Feb 05 '18 at 18:56

0 Answers0