howto use MagickGetImageHistogram

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
ghety
Posts: 2
Joined: 2011-06-20T23:42:59-07:00
Authentication code: 8675308

howto use MagickGetImageHistogram

Post 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
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: howto use MagickGetImageHistogram

Post 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);
ghety
Posts: 2
Joined: 2011-06-20T23:42:59-07:00
Authentication code: 8675308

Re: howto use MagickGetImageHistogram

Post 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?
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: howto use MagickGetImageHistogram

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
Post Reply