| Thomas Richter 2005-02-14, 8:55 am |
| Hi,
> 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?
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
|