-3

I have a binary file which contains an image with header.

The details are as follows.

  • The first 1024 bytes contain header Then 32 bytes of header for each line
  • Then 4608 bytes constitute one line of image for next 5000 lines.

So this would become a 4608x5000 pixel image along with headers.

How should I read the binary file and how should I form and work with image?

Thanks in advance.

shobhit
  • 702
  • 2
  • 9
  • 21
Ishan Tomar
  • 1,488
  • 1
  • 16
  • 20

1 Answers1

2

You need to open the file (using binary mode if the code will run on Windows) then use the read(size) method to extract bytes. If the image format is described in bytes, then you just pull apart the data as required.

Alternatively, if you need to convert values to integers etc, then Python has a struct module that can be used to unpack binary data (so you would read the data as above, but use struct to convert to integers etc).

andrew cooke
  • 45,717
  • 10
  • 93
  • 143