Page 1 of 1

24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-29T23:38:00-07:00
by cam
Hello,

This is my first time with ImageMagick. I read a 24bit BMP file (8 bits per channel) and when i iterate pixel by pixel the pixels are 16bits per channel. What is happening?

this is my code:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <wand/MagickWand.h>
#include <string.h>


int main(int argc,char **argv)
{
	MagickWand *imagen, *imagen_salida;
	PixelIterator *iterator;
	
	imagen = NewMagickWand();
	MagickReadImage(imagen,argv[1]);
	
	PixelWand **pixels;
	
	iterator = NewPixelIterator(imagen);
	
	MagickPixelPacket pixel;
	
	///////////
	register ssize_t x;
	size_t width;
	ssize_t y;
	///////////


	//******************ITERACION PIXEL POR PIXEL***********************
	for (y=0; y < (ssize_t) MagickGetImageHeight(imagen); y++)
	{
		pixels = PixelGetNextIteratorRow(iterator,&width);
		if (pixels == (PixelWand **) NULL) break;
		
		for (x=0; x < (ssize_t) width; x++)
		{
			PixelGetMagickColor(pixels[x],&pixel);
			
			pixel.red = 65535 - pixel.red;
			pixel.green = 65535 - pixel.green;
			pixel.blue = 65535 - pixel.blue;
			//pixel.index = SigmoidalContrast(pixel.index);
			//printf("\nr: %g", pixel.red);
			PixelSetMagickColor(pixels[x],&pixel);
		}
		(void) PixelSyncIterator(iterator);
	}
	//******************************************************************
	

	/* Write the image then destroy it. */
	MagickWriteImages(imagen,argv[2],MagickTrue);
	imagen = DestroyMagickWand(imagen);
	iterator = DestroyPixelIterator(iterator);
  
	MagickWandTerminus();
	
	return 0;
}

If i read a 24 bits image i think i should edit it like a 24 bits image. what can i do?

Thanks a lot!.

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T00:27:35-07:00
by dlemstra
You are probably using the Q16 version of ImageMagick that uses 16 bits per channel. You can find a detailed explanation here: http://www.imagemagick.org/script/architecture.php

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T10:06:16-07:00
by cam
Hi,

and how can i change my MagicWand version to Q8? Any idea?

Thank you very much

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T10:11:06-07:00
by magick
Set the image depth to 8 before you write it. That should fix the problem, the Q8 version of ImageMagick is not required.

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T11:19:11-07:00
by fmw42
convert image ...processing... -depth 8 result

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T13:08:33-07:00
by cam
The image that i open is 24bits and the image that my code writes in disk is 24bits, but in pixel iterators i treat the image as it was 48bits (16bits per channel).

I want to treat the image as 24bits (0-255 for each channel, not 0-65535 for each channel) image.

Thank you very much for your time.

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-11-30T13:41:30-07:00
by dlemstra
Can you explain why it is a problem that the pixel iterator has 16 bits per channel? And instead of modifying the pixels by yourself you could also call the MagickNegateImage method that does the same as what you are trying to do.

Re: 24Bit BMP image treated as a 48Bits image?

Posted: 2013-12-01T18:39:50-07:00
by cam
Hi,

I reinstalled imagemagick with Q8 option and now every image has 8bits per channel with this command in the instalation from console:

Code: Select all

./configure --with-quantum-depth=8
Thanks a lot.