Code Comments
Programming Forum and web based access to our favorite programming groups.Hi:
I use the jasper encoder to compress a 8-bit grayscale image in matlab
as follows:
I=imread('lena.bmp');
imwrite(I,'temp1.ppm');
%encode
!jasper -f temp1.ppm -F lena.jp2 -T jp2 -O rate=0.01
%decode
!jasper -f lena.jp2 -F temp2.ppm -T pnm
J=imread('temp2.ppm');
Now the uncompressed image J becomes 32-bit RGB image instead of a 8-bit
grayscale image. It seems the PPM file can only represent 32-bit RGB images.
How can I store the 8-bit grayscale image into a PPM file without expanding
its bit-depth? Thanks.
Post Follow-up to this messageHi,
> I=imread('lena.bmp');
> imwrite(I,'temp1.ppm');
> %encode
> !jasper -f temp1.ppm -F lena.jp2 -T jp2 -O rate=0.01
> %decode
> !jasper -f lena.jp2 -F temp2.ppm -T pnm
> J=imread('temp2.ppm');
> Now the uncompressed image J becomes 32-bit RGB image instead of a 8-bit
> grayscale image. It seems the PPM file can only represent 32-bit RGB image
s.
> How can I store the 8-bit grayscale image into a PPM file without expandin
g
> its bit-depth?
PPM files are 24 bit color images, and BMP files typically are color images
as well. Thus, to be sure to do the right thing:
a) Make sure your BMP input image *is* grey scale. That means, the bmp
header has to classify this image as *palette image* with 256 levels of
grey. Otherwise, it is just an RGB image using only grey colors. Use an
image manipulation program to store the data as greyscale otherwise, e.g.
gimp or xv. Recommended grey-scale format would be pgm (a pnm variant).
Few programs are able to write b&w bmp images because they actually use
a different (not-so-common) encoding, and I'm not sure either whether
jasper would then be able to read these images.
b) I don't know whether this is jasper specific, but the suffix "ppm"
indicates color images. What you want to look at are "pgm" images.
So long,
Thomas
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.