From cb9af4ac6134e7e15e7d344489e9e0f634e1b4c1 Mon Sep 17 00:00:00 2001 From: cristy Date: Wed, 5 Feb 2014 13:31:55 +0000 Subject: [PATCH] --- MagickCore/compare.c | 6 ++++-- MagickCore/feature.c | 6 ++++-- MagickCore/identify.c | 47 ++++++++++++++++++++++++------------------ MagickCore/statistic.c | 26 +++++++++++------------ 4 files changed, 47 insertions(+), 38 deletions(-) diff --git a/MagickCore/compare.c b/MagickCore/compare.c index 31cab10a6..24cd31e04 100644 --- a/MagickCore/compare.c +++ b/MagickCore/compare.c @@ -1090,8 +1090,10 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image, static inline double MagickLog10(const double x) { - if (fabs(x) < MagickMinimumValue) - return(log10(MagickMinimumValue)); +#define Log10Epsilon (1.0e-25) + + if (fabs(x) < Log10Epsilon) + return(log10(Log10Epsilon)); return(log10(fabs(x))); } diff --git a/MagickCore/feature.c b/MagickCore/feature.c index 5da263ada..c03f7b836 100644 --- a/MagickCore/feature.c +++ b/MagickCore/feature.c @@ -138,8 +138,10 @@ static inline ssize_t MagickAbsoluteValue(const ssize_t x) static inline double MagickLog10(const double x) { - if (fabs(x) < MagickMinimumValue) - return(log10(MagickMinimumValue)); +#define Log10Epsilon (1.0e-25) + + if (fabs(x) < Log10Epsilon) + return(log10(Log10Epsilon)); return(log10(fabs(x))); } diff --git a/MagickCore/identify.c b/MagickCore/identify.c index 8d57509ab..ae94b6a3b 100644 --- a/MagickCore/identify.c +++ b/MagickCore/identify.c @@ -349,8 +349,11 @@ static ssize_t PrintChannelLocations(FILE *file,const Image *image, } static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel, - const char *name,const ChannelMoments *channel_moments) + const char *name,const double scale,const ChannelMoments *channel_moments) { + double + powers[8] = { 1.0, 2.0, 3.0, 3.0, 6.0, 4.0, 6.0, 4.0 }; + register ssize_t i; @@ -368,11 +371,14 @@ static ssize_t PrintChannelMoments(FILE *file,const PixelChannel channel, GetMagickPrecision(),channel_moments[channel].ellipse_angle); n+=FormatLocaleFile(file," Ellipse eccentricity: %.*g\n", GetMagickPrecision(),channel_moments[channel].ellipse_eccentricity); - n+=FormatLocaleFile(file," Ellipse intensity: %.*g\n", - GetMagickPrecision(),channel_moments[channel].ellipse_intensity); + n+=FormatLocaleFile(file," Ellipse intensity: %.*g (%.*g)\n", + GetMagickPrecision(),pow(scale,powers[0])* + channel_moments[channel].ellipse_intensity,GetMagickPrecision(), + channel_moments[channel].ellipse_intensity); for (i=0; i < 8; i++) - n+=FormatLocaleFile(file," I%.20g: %.*g\n",i+1.0,GetMagickPrecision(), - channel_moments[channel].I[i]); + n+=FormatLocaleFile(file," I%.20g: %.*g (%.*g)\n",i+1.0, + GetMagickPrecision(),channel_moments[channel].I[i]/pow(scale,powers[i]), + GetMagickPrecision(),channel_moments[channel].I[i]); return(n); } @@ -433,6 +439,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, double elapsed_time, + scale, user_time; ImageType @@ -449,8 +456,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, x; size_t - distance, - scale; + distance; ssize_t y; @@ -663,7 +669,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, channel_moments=(ChannelMoments *) NULL; channel_features=(ChannelFeatures *) NULL; colorspace=image->colorspace; - scale=1; + scale=1.0; if (ping == MagickFalse) { size_t @@ -726,9 +732,9 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, if (image->alpha_trait == BlendPixelTrait) (void) FormatLocaleFile(file," alpha: %.20g-bit\n",(double) channel_statistics[AlphaPixelChannel].depth); - scale=1; + scale=1.0; if (image->depth <= MAGICKCORE_QUANTUM_DEPTH) - scale=QuantumRange/((size_t) QuantumRange >> ((size_t) + scale=(double) QuantumRange/((size_t) QuantumRange >> ((size_t) MAGICKCORE_QUANTUM_DEPTH-image->depth)); } if (channel_statistics != (ChannelStatistics *) NULL) @@ -782,47 +788,48 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file, } if (channel_moments != (ChannelMoments *) NULL) { + scale=(double) ((1UL << image->depth)-1); (void) FormatLocaleFile(file," Channel moments:\n"); switch (colorspace) { case RGBColorspace: default: { - (void) PrintChannelMoments(file,RedPixelChannel,"Red", + (void) PrintChannelMoments(file,RedPixelChannel,"Red",scale, channel_moments); - (void) PrintChannelMoments(file,GreenPixelChannel,"Green", + (void) PrintChannelMoments(file,GreenPixelChannel,"Green",scale, channel_moments); - (void) PrintChannelMoments(file,BluePixelChannel,"Blue", + (void) PrintChannelMoments(file,BluePixelChannel,"Blue",scale, channel_moments); break; } case CMYKColorspace: { - (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan", + (void) PrintChannelMoments(file,CyanPixelChannel,"Cyan",scale, channel_moments); - (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta", + (void) PrintChannelMoments(file,MagentaPixelChannel,"Magenta",scale, channel_moments); - (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow", + (void) PrintChannelMoments(file,YellowPixelChannel,"Yellow",scale, channel_moments); - (void) PrintChannelMoments(file,BlackPixelChannel,"Black", + (void) PrintChannelMoments(file,BlackPixelChannel,"Black",scale, channel_moments); break; } case GRAYColorspace: { - (void) PrintChannelMoments(file,GrayPixelChannel,"Gray", + (void) PrintChannelMoments(file,GrayPixelChannel,"Gray",scale, channel_moments); break; } } if (image->alpha_trait == BlendPixelTrait) - (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha", + (void) PrintChannelMoments(file,AlphaPixelChannel,"Alpha",scale, channel_moments); if (colorspace != GRAYColorspace) { (void) FormatLocaleFile(file," Image moments:\n"); (void) PrintChannelMoments(file,(PixelChannel) MaxPixelChannels, - "Overall",channel_moments); + "Overall",scale,channel_moments); } channel_moments=(ChannelMoments *) RelinquishMagickMemory( channel_moments); diff --git a/MagickCore/statistic.c b/MagickCore/statistic.c index 9264931c5..ba879ab29 100644 --- a/MagickCore/statistic.c +++ b/MagickCore/statistic.c @@ -1384,8 +1384,7 @@ MagickExport ChannelMoments *GetImageMoments(const Image *image, M20[MaxPixelChannels+1], M21[MaxPixelChannels+1], M22[MaxPixelChannels+1], - M30[MaxPixelChannels+1], - scale; + M30[MaxPixelChannels+1]; PointInfo centroid[MaxPixelChannels+1]; @@ -1416,7 +1415,6 @@ MagickExport ChannelMoments *GetImageMoments(const Image *image, (void) ResetMagickMemory(M21,0,sizeof(M21)); (void) ResetMagickMemory(M22,0,sizeof(M22)); (void) ResetMagickMemory(M30,0,sizeof(M30)); - scale=(double) ((1UL << image->depth)-1)/QuantumRange; image_view=AcquireVirtualCacheView(image,exception); for (y=0; y < (ssize_t) image->rows; y++) { @@ -1450,9 +1448,9 @@ MagickExport ChannelMoments *GetImageMoments(const Image *image, continue; if ((traits & UpdatePixelTrait) == 0) continue; - M00[channel]+=scale*p[i]; - M10[channel]+=x*scale*p[i]; - M01[channel]+=y*scale*p[i]; + M00[channel]+=QuantumScale*p[i]; + M10[channel]+=x*QuantumScale*p[i]; + M01[channel]+=y*QuantumScale*p[i]; } p+=GetPixelChannels(image); } @@ -1506,21 +1504,21 @@ MagickExport ChannelMoments *GetImageMoments(const Image *image, if ((traits & UpdatePixelTrait) == 0) continue; M11[channel]+=(x-centroid[channel].x)*(y-centroid[channel].y)* - scale*p[i]; + QuantumScale*p[i]; M20[channel]+=(x-centroid[channel].x)*(x-centroid[channel].x)* - scale*p[i]; + QuantumScale*p[i]; M02[channel]+=(y-centroid[channel].y)*(y-centroid[channel].y)* - scale*p[i]; + QuantumScale*p[i]; M21[channel]+=(x-centroid[channel].x)*(x-centroid[channel].x)* - (y-centroid[channel].y)*scale*p[i]; + (y-centroid[channel].y)*QuantumScale*p[i]; M12[channel]+=(x-centroid[channel].x)*(y-centroid[channel].y)* - (y-centroid[channel].y)*scale*p[i]; + (y-centroid[channel].y)*QuantumScale*p[i]; M22[channel]+=(x-centroid[channel].x)*(x-centroid[channel].x)* - (y-centroid[channel].y)*(y-centroid[channel].y)*scale*p[i]; + (y-centroid[channel].y)*(y-centroid[channel].y)*QuantumScale*p[i]; M30[channel]+=(x-centroid[channel].x)*(x-centroid[channel].x)* - (x-centroid[channel].x)*scale*p[i]; + (x-centroid[channel].x)*QuantumScale*p[i]; M03[channel]+=(y-centroid[channel].y)*(y-centroid[channel].y)* - (y-centroid[channel].y)*scale*p[i]; + (y-centroid[channel].y)*QuantumScale*p[i]; } p+=GetPixelChannels(image); } -- 2.40.0