Convert strange raw image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sfreak

Convert strange raw image

Post by sfreak »

Hi!

I have some files here that are 800x600, 1 byte per pixel. Each byte has the following bits: (MSB) 0000000RGB (LSB) , 1 bit per color makes 8 colors. Can I 'convert' this to a sane image format using ImageMagick?

Thanks,
Sebastian
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert strange raw image

Post by anthony »

the 'stream' command does have formating output to handle this type of weird image. But I am not certain of the syntax.
Check on the main IM website.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sfreak

Re: Convert strange raw image

Post by sfreak »

Hi,

I had a look at the stream command. It appears to only be good in the image -> raw data direction. I need to go the other way though, from strange raw data to some standard image format.

I guess I will have to write a little program myself...

Sebastian
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Convert strange raw image

Post by el_supremo »

I've been playing with this problem for a while this morning because I thought that using a colour lookup table should work.
I wrote a program to create a test binary file (bits.rgb) and reading that raw data back in is easy:

Code: Select all

convert -size 800x600 -depth 8 gray:bits.rgb bits_raw.png
Converting this to rgb wasn't so easy, mainly because I couldn't come up with a way to create the required colour lookup table with IM, so I wrote a program to create one (bits_clut.png which is here: http://members.shaw.ca/digipete/bits_clut.png )
Note that the clut must have 256 colours. I tried to make one that had just 8 colours but the -clut operation seems to interpolate between colours whether you like it or not if the clut is less than 256 colours. So the clut that I generated has the first 8 colours set to the required RGB values and the rest are black.

Then converting to an rgb image is also easy:

Code: Select all

convert bits_raw.png bits_clut.png -interpolate Integer -clut bits_new.png
The Integer -interpolate tells IM not to interpolate the colours.

Putting the two together in one command:

Code: Select all

convert -size 800x600 -depth 8 gray:bits.rgb bits_clut.png -interpolate Integer -clut bits_new.png
Pete
sfreak

Re: Convert strange raw image

Post by sfreak »

Hey Pete,

thank you! That is exactly what I was looking for! I had no idea the -clut option even existed since I used a slightly outdated ImageMagick version. After updating your commands work like a charm.

I guess there is nothing that can't be done with ImageMagick after all! :-)

Cheers,
Sebastian
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Convert strange raw image

Post by el_supremo »

FWIW:
I figured out how to generate the clut image with IM's -fx operator:

Code: Select all

convert -size 1x256 ( xc:black -fx "j&4" ) ( xc:black -fx "j&2" ) ( xc:black -fx "j&1" ) -combine bits_clut.png
Pete
Post Reply