Page 1 of 1

howto use MagickGetImageHistogram

Posted: 2011-06-21T00:20:20-07:00
by ghety
hi guys
this is my first post :-)

the question: how can i use MagickGetImageHistogram in iPhone SDK (Objective C)?

Simple code

Code: Select all

MagickWandGenesis();
	magick_wand = NewMagickWand();
	NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"myimage.jpg"]);
	
    MagickBooleanType status;

    status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
    
	if (status == MagickFalse) {
		ThrowWandException(magick_wand);
	}

PixelWand *p_wand;
    p_wand = NewPixelWand();

I'm interested in the method

Code: Select all

MagickGetImageHistogram(magick_wand, size_t * );
who is "size_t"?

MagickGetImageHistogram is an array or something?

Thanks

Re: howto use MagickGetImageHistogram

Posted: 2011-06-21T04:54:38-07:00
by magick
MagickGetImageHistogram() returns an array of PixelWand's. The second parameter is the number of pixel wands returned in the array:
  • pixel_wands = MagickGetImageHistogram( magick_wand, &number_wands);

Re: howto use MagickGetImageHistogram

Posted: 2011-06-24T02:10:42-07:00
by ghety
Thanks magick
but this is my simple code with exit error:

Code: Select all

MagickWandGenesis();
magick_wand = NewMagickWand();
NSData * dataObject = UIImagePNGRepresentation([UIImage imageNamed:@"myimage.jpg"]);
	
MagickBooleanType status;

status = MagickReadImageBlob(magick_wand, [dataObject bytes], [dataObject length]);
    
if (status == MagickFalse) {
	ThrowWandException(magick_wand);
}

PixelWand * p_wand;

p_wand = NewPixelWand();

PixelSetColor(p_wand,"red");

Code: Select all

MagickGetImageHistogram(magick_wand , 1); 
warning: passing argument 2 of 'MagickGetImageHistogram' makes pointer from integer without a cast

Code: Select all

MagickGetImageHistogram(magick_wand , PixelGetColorCount(p_wand)); 
warning: passing argument 2 of 'MagickGetImageHistogram' makes pointer from integer without a cast

I have no idea.

Can you help me to fix the code?

Re: howto use MagickGetImageHistogram

Posted: 2011-06-25T12:49:49-07:00
by el_supremo
Both your examples are wrong. As Magick said, MagickGetImageHistogram returns an array of PixelWands and the second argument is a *pointer* to an integer which *returns* the number of wands (unique colours). You are trying to pass an integer to MagickGetImageHistogram when you should be receiving one from it.
e.g.

Code: Select all

int num_wands;
PixelWand **pw_array;
.
.
.
pw_array = MagickGetImageHistogram(magick_wand , &num_wands);
// Check for valid result
if(!pw_array || !num_wands) {
     // Handle the error - there's no histogram
    .
    .
}
// Now handle the pixel wands returned
Pete