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
Convert strange raw image
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert strange raw image
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.
Check on the main IM website.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
Re: Convert strange raw image
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
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
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Convert strange raw image
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:
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:
The Integer -interpolate tells IM not to interpolate the colours.
Putting the two together in one command:
Pete
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
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
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
Re: Convert strange raw image
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
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
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Convert strange raw image
FWIW:
I figured out how to generate the clut image with IM's -fx operator:
Pete
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