0

I would like to process a raw image using OpenCV. As far I know, it is not possible to open raw image using OpenCV. I fllowed the instaction.

My raw picture is RGB with 24bits (the first 3 bytes represents the color values of red, green and blue in the same pixel).

My aim is to be able to process my picture using OpenCV functions.

How should I reshape my raw data? I thought of (3, 1280, 1080) based on what i saw in the internet

How could I visualized the three pictures as "normal" picture? and how could I visualized he three pictures separably?

As small example I tried to reshape the bytes I read using:

a = np.arange(18).reshape(3,2,3, order='F')

a: [[[ 0  6 12]
     [ 3  9 15]]
    [[ 1  7 13]
     [ 4 10 16]]
    [[ 2  8 14]
     [ 5 11 17]]]
Eagle
  • 3,362
  • 5
  • 34
  • 46

1 Answers1

3

OpenCV is able to read NetPBM (Wikipedia entry for NetPBM) format images, see PPM Example on linked page.

So you could just put a P6 (i.e. binary RGB) NetPBM header on the front of your image like this, then OpenCV can open it:

{ printf "P6\n1280 1080\n255\n" ; cat YourImage.raw ; } > result.ppm

If you are unfortunate enough to be on Windows, you can probably do it something like this:

echo "P6"          > header.txt
echo "1280 1080"  >> header.txt
echo "255"        >> header.txt
copy /b header.txt+YourImage.raw result.ppm

Alternatively, if you are on Linux, you probably have ImageMagick, and it is available for macOS and Windows too. So, at the command line in Terminal, you could convert your image to a PNG like tis:

convert -depth 8 -size 1280x1080 rgb:YourImage.raw result.png

You can then separate the individual channels and append them beside each other with

convert result.png -separate +append 3channels.png   # or use `-append` instead

Or, with auto-level contrast:

convert result.png -separate +append -auto-level 3channels.png
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432