Page 1 of 1

Image statistics - need help

Posted: 2013-03-23T06:36:44-07:00
by TheWho
Hey guys,
I was trying to get image statistics using MagickWand but I get wrong results. Obviously I'm doing something wrong, but I can't figure out what. I'm reading JPEG file. My code is as follows:

Code: Select all

  MagickBooleanType status;
  MagickWand  *magick_wand;
  ChannelStatistics *chan_stat;
  double mean_red, std_red;

  /*
    Read an image.
  */
  MagickWandGenesis();
  magick_wand=NewMagickWand();
  status=MagickReadImage(magick_wand,pFilename);
  if (status == MagickFalse)
    ThrowWandException(magick_wand);

  /*
   Get stats
  */
 chan_stat=MagickGetImageChannelStatistics(magick_wand);
  mean_red=chan_stat[RedChannel].mean;

 /*
    Close session
  */
  magick_wand=DestroyMagickWand(magick_wand);
  MagickWandTerminus();
Seems that chan_stat structure is not being initialized, since the figures are garbage. When I run command line 'identify -verbose' all numbers are ok. Any advice?

Re: Image statistics - need help

Posted: 2013-03-23T08:34:37-07:00
by el_supremo
At the moment I can't see anything wrong with the code except that when you are done you should free up the channel statistics:

Code: Select all

    MagickRelinquishMemory(chan_stat);
Pete

Re: Image statistics - need help

Posted: 2013-03-23T10:07:18-07:00
by el_supremo
Show us some of the statistics you get when you use the builtin logo: image.

Pete