Page 1 of 1
Convert strange raw image
Posted: 2008-09-15T19:38:29-07:00
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
Re: Convert strange raw image
Posted: 2008-09-17T00:26:56-07:00
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.
Re: Convert strange raw image
Posted: 2008-09-17T01:45:11-07:00
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
Re: Convert strange raw image
Posted: 2008-09-17T10:20:20-07:00
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
Re: Convert strange raw image
Posted: 2008-09-17T17:45:34-07:00
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
Re: Convert strange raw image
Posted: 2008-09-18T10:31:01-07:00
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