Hi everybody,
I am a researcher in image processing algorithms and I am currently using
ImageMagick as the
library for reading and writing images. In general, I am interested in reading
and writing BMP or
TIFF files, no JPEG since it introduces losses in the image.
For the image processing algorithms I am using an own DblImage class, which
is basically a
gray-scale image with pixels of double precision. In order to write RGB images
images to disc, I use
the function included below. In the case I need to save a gray-scale image, I
call the function with
imR = imG = imB = image_to_save. Moreover, in all cases my DblImages images are
within the range
[0..255]. When storing a DblImage in TIFF format I do lose precision, but this
does not bother me.
For me its important to be able to view the image with generic image displayers
(some of them
implemented by us), which expect in most of the cases 8 bit/pixel images.
I always use 8 bit/pixel (gray or full color) BMP or TIFF images as input.
When reading images, I
have to divide each pixel by 257 (not 256) in order to get the correct value
that is stored on disc.
In a similar way, when storing images to disc (see code below), I have to
multiply each pixel value
by 257. In fact, I do not understand exactly why do I have to multiply by 257
and not 256. I think
that this may be related to the value of QuantumDepth, which is 16.
My questions are:
- The current code works on those machines that have imagemagick installed
with QuantumDepth
equal to 16. But in my office there are other distributions where
imagemagick
is compiled with QuantumDepth equal to 8. So, the code shown below does
not work on such
machines. The question is, how to I know during run-time which is the
value of QuantumDepth
that has been used to compile the libraries that are currently installed
on the machine ?
It seems that QuantumDepth is a sort of #define, so no access to its value
during execution
is available...
- The current code stores gray-scale images in 16 bit/pixel image. How can I
force imagemagick
storing the images in 8 bit/pixel ? This is what really interests me...
- Why do I have to multiply and divide by 257 each pixel when writing and
reading, respectively,
8 bit/pixel images from disc. Why not 256 ?
Thank you very much,
Best regards,
Luis
void writeimage(char *fname, DblImage & imR, DblImage & imG, DblImage & imB)
{
int ncol=imR.cols();
int nrow=imR.fils();
Image image;
image.size(Geometry(ncol,nrow));
image.modifyImage();
PixelPacket* pix = image.getPixels(0,0,ncol,nrow);
PixelPacket* tmp;
tmp = pix;
for (int i=0; i<nrow; i++) {
for (int j=0; j<ncol; j++,tmp++) {
tmp->red = (int) (imR(i,j)) * 257;
tmp->green = (int) (imG(i,j)) * 257;
tmp->blue = (int) (imB(i,j)) * 257;
}
}
image.syncPixels();
image.write(fname);
return;
};
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users