return(y);
}
-static MagickRealType FxChannelStatistics(FxInfo *fx_info,const Image *image,
+static MagickRealType FxChannelStatistics(FxInfo *fx_info,Image *image,
PixelChannel channel,const char *symbol,ExceptionInfo *exception)
{
+ ChannelType
+ channel_mask;
+
char
key[MaxTextExtent],
statistic[MaxTextExtent];
register const char
*p;
+ channel_mask=UndefinedChannel;
for (p=symbol; (*p != '.') && (*p != '\0'); p++) ;
if (*p == '.')
- switch (*++p) /* e.g. depth.r */
{
- case 'r': channel=RedPixelChannel; break;
- case 'g': channel=GreenPixelChannel; break;
- case 'b': channel=BluePixelChannel; break;
- case 'c': channel=CyanPixelChannel; break;
- case 'm': channel=MagentaPixelChannel; break;
- case 'y': channel=YellowPixelChannel; break;
- case 'k': channel=BlackPixelChannel; break;
- default: break;
+ ssize_t
+ option;
+
+ option=ParseCommandOption(MagickPixelChannelOptions,MagickTrue,p+1);
+ if (option >= 0)
+ {
+ channel=(PixelChannel) option;
+ channel_mask=(ChannelType) (channel_mask | (1 << channel));
+ SetPixelChannelMapMask(image,channel_mask);
+ }
}
(void) FormatLocaleString(key,MaxTextExtent,"%p.%.20g.%s",(void *) image,
(double) channel,symbol);
value=(const char *) GetValueFromSplayTree(fx_info->symbols,key);
if (value != (const char *) NULL)
- return(QuantumScale*StringToDouble(value,(char **) NULL));
+ {
+ if (channel_mask != UndefinedChannel)
+ SetPixelChannelMapMask(image,channel_mask);
+ return(QuantumScale*StringToDouble(value,(char **) NULL));
+ }
(void) DeleteNodeFromSplayTree(fx_info->symbols,key);
if (LocaleNCompare(symbol,"depth",5) == 0)
{
(void) FormatLocaleString(statistic,MaxTextExtent,"%g",
standard_deviation);
}
+ if (channel_mask != UndefinedChannel)
+ SetPixelChannelMapMask(image,channel_mask);
(void) AddValueToSplayTree(fx_info->symbols,ConstantString(key),
ConstantString(statistic));
return(QuantumScale*StringToDouble(statistic,(char **) NULL));
(LocaleCompare("min",property) == 0) ||
(LocaleCompare("min",property) == 0) )
{
- (void) ThrowMagickException(exception,GetMagickModule(),
- OptionError,"SetReadOnlyProperty","'%s'",property);
+ (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
+ "SetReadOnlyProperty","'%s'",property);
status=MagickFalse;
break;
}
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetImageMean() returns the mean and standard deviation of one or more
-% image channels.
+% GetImageMean() returns the mean and standard deviation of one or more image
+% channels.
%
% The format of the GetImageMean method is:
%
MagickExport MagickBooleanType GetImageMean(const Image *image,double *mean,
double *standard_deviation,ExceptionInfo *exception)
{
+ double
+ area;
+
ChannelStatistics
*channel_statistics;
register ssize_t
i;
- size_t
- area;
-
assert(image != (Image *) NULL);
assert(image->signature == MagickSignature);
if (image->debug != MagickFalse)
channel_statistics=GetImageStatistics(image,exception);
if (channel_statistics == (ChannelStatistics *) NULL)
return(MagickFalse);
- area=0;
+ area=0.0;
channel_statistics[CompositePixelChannel].mean=0.0;
channel_statistics[CompositePixelChannel].standard_deviation=0.0;
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% GetImageStatistics() returns statistics for each channel in the
-% image. The statistics include the channel depth, its minima, maxima, mean,
-% standard deviation, kurtosis and skewness. You can access the red channel
-% mean, for example, like this:
+% GetImageStatistics() returns statistics for each channel in the image. The
+% statistics include the channel depth, its minima, maxima, mean, standard
+% deviation, kurtosis and skewness. You can access the red channel mean, for
+% example, like this:
%
% channel_statistics=GetImageStatistics(image,exception);
% red_mean=channel_statistics[RedPixelChannel].mean;
ChannelStatistics
*channel_statistics;
- double
- area;
-
MagickStatusType
initialize,
status;
(void) ResetMagickMemory(channel_statistics,0,(MaxPixelChannels+1)*
sizeof(*channel_statistics));
for (i=0; i <= (ssize_t) MaxPixelChannels; i++)
- {
channel_statistics[i].depth=1;
- channel_statistics[i].maxima=0.0;
- channel_statistics[i].minima=0.0;
- }
initialize=MagickTrue;
for (y=0; y < (ssize_t) image->rows; y++)
{
channel_statistics[channel].sum_cubed+=(double) p[i]*p[i]*p[i];
channel_statistics[channel].sum_fourth_power+=(double) p[i]*p[i]*p[i]*
p[i];
+ channel_statistics[channel].area++;
}
p+=GetPixelChannels(image);
}
}
- area=(double) image->columns*image->rows;
for (i=0; i < (ssize_t) MaxPixelChannels; i++)
{
- channel_statistics[i].sum/=area;
- channel_statistics[i].sum_squared/=area;
- channel_statistics[i].sum_cubed/=area;
- channel_statistics[i].sum_fourth_power/=area;
+ if (channel_statistics[i].area != 0.0)
+ channel_statistics[i].sum/=channel_statistics[i].area;
+ channel_statistics[i].sum_squared/=channel_statistics[i].area;
+ channel_statistics[i].sum_cubed/=channel_statistics[i].area;
+ channel_statistics[i].sum_fourth_power/=channel_statistics[i].area;
channel_statistics[i].mean=channel_statistics[i].sum;
channel_statistics[i].variance=channel_statistics[i].sum_squared;
channel_statistics[i].standard_deviation=sqrt(
depth;
double
+ area,
minima,
maxima,
sum,
"-interlace type type of image interlacing scheme",
"-interpolate method pixel color interpolation method",
"-limit type value pixel cache resource limit",
+ "-mask filename associate a mask with the image",
"-monitor monitor progress",
"-ping efficiently determine image attributes",
"-quiet suppress all warning messages",
}
case 'm':
{
+ if (LocaleCompare("mask",option+1) == 0)
+ {
+ if (*option == '+')
+ break;
+ i++;
+ if (i == (ssize_t) (argc-1))
+ ThrowIdentifyException(OptionError,"MissingArgument",option);
+ break;
+ }
if (LocaleCompare("matte",option+1) == 0)
break;
if (LocaleCompare("monitor",option+1) == 0)
\-limit type value pixel cache resource limit
\-list type Color, Configure, Delegate, Format, Magic, Module,
Resource, or Type
+ \-mask filename associate a mask with the image
\-matte store matte channel if the image has one
\-monitor monitor progress
\-ping efficiently determine image attributes