% Image Comparison Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% December 2003 %
% %
% %
-% Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
" de-emphasize pixel differences with this color",
"-metric type measure differences between images with this metric",
"-monitor monitor progress",
- "-passphrase filename get the passphrase from this file",
"-profile filename add, delete, or apply an image profile",
"-quality value JPEG/MIFF/PNG compression level",
"-quiet suppress all warning messages",
"-seed value seed a new sequence of pseudo-random numbers",
"-set attribute value set an image attribute",
"-quality value JPEG/MIFF/PNG compression level",
+ "-similarity-threshold value",
+ " minimum distortion for (sub)image match",
"-size geometry width and height of image",
"-subimage-search search for subimage",
+ "-synchronize synchronize image to storage device",
+ "-taint declare the image as modified",
"-transparent-color color",
" transparent color",
"-type type image type",
(char *) NULL
};
- (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
- (void) printf("Copyright: %s\n",GetMagickCopyright());
- (void) printf("Features: %s\n\n",GetMagickFeatures());
+ ListMagickVersion(stdout);
(void) printf("Usage: %s [options ...] image reconstruct difference\n",
GetClientName());
(void) printf("\nImage Settings:\n");
for (p=miscellaneous; *p != (char *) NULL; p++)
(void) printf(" %s\n",*p);
(void) printf(
- "\nBy default, the image format of `file' is determined by its magic\n");
+ "\nBy default, the image format of 'file' is determined by its magic\n");
(void) printf(
"number. To specify a particular image format, precede the filename\n");
(void) printf(
WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
int argc,char **argv,char **metadata,ExceptionInfo *exception)
{
+#define CompareEpsilon (1.0e-06)
#define DefaultDissimilarityThreshold 0.31830988618379067154
+#define DefaultSimilarityThreshold (-1.0)
#define DestroyCompare() \
{ \
if (similarity_image != (Image *) NULL) \
#define ThrowCompareInvalidArgumentException(option,argument) \
{ \
(void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
- "InvalidArgument","`%s': %s",option,argument); \
+ "InvalidArgument","'%s': %s",option,argument); \
DestroyCompare(); \
return(MagickFalse); \
}
double
dissimilarity_threshold,
distortion,
- similarity_metric;
+ similarity_metric,
+ similarity_threshold;
Image
*difference_image,
if ((LocaleCompare("version",option+1) == 0) ||
(LocaleCompare("-version",option+1) == 0))
{
- (void) FormatLocaleFile(stdout,"Version: %s\n",
- GetMagickVersion((size_t *) NULL));
- (void) FormatLocaleFile(stdout,"Copyright: %s\n",
- GetMagickCopyright());
- (void) FormatLocaleFile(stdout,"Features: %s\n\n",
- GetMagickFeatures());
+ ListMagickVersion(stdout);
return(MagickFalse);
}
}
difference_image=NewImageList();
similarity_image=NewImageList();
dissimilarity_threshold=DefaultDissimilarityThreshold;
+ similarity_threshold=DefaultSimilarityThreshold;
distortion=0.0;
format=(char *) NULL;
j=1;
k=0;
- metric=UndefinedMetric;
+ metric=UndefinedErrorMetric;
NewImageStack();
option=(char *) NULL;
pend=MagickFalse;
i++;
if (i == (ssize_t) argc)
ThrowCompareException(OptionError,"MissingArgument",option);
- type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
+ type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,argv[i]);
if (type < 0)
- ThrowCompareException(OptionError,"UnrecognizedAlphaChannelType",
+ ThrowCompareException(OptionError,"UnrecognizedAlphaChannelOption",
argv[i]);
break;
}
if (channel < 0)
ThrowCompareException(OptionError,"UnrecognizedChannelType",
argv[i]);
- SetPixelChannelMapMask(image,(ChannelType) channel);
+ SetPixelChannelMask(image,(ChannelType) channel);
break;
}
if (LocaleCompare("colorspace",option+1) == 0)
ThrowCompareException(OptionError,"MissingArgument",option);
break;
}
+ if (LocaleCompare("similarity-threshold",option+1) == 0)
+ {
+ if (*option == '+')
+ break;
+ i++;
+ if (i == (ssize_t) argc)
+ ThrowCompareException(OptionError,"MissingArgument",option);
+ if (IsGeometry(argv[i]) == MagickFalse)
+ ThrowCompareInvalidArgumentException(option,argv[i]);
+ if (*option == '+')
+ similarity_threshold=DefaultSimilarityThreshold;
+ else
+ similarity_threshold=StringToDouble(argv[i],(char **) NULL);
+ break;
+ }
if (LocaleCompare("size",option+1) == 0)
{
if (*option == '+')
if ((LocaleCompare("version",option+1) == 0) ||
(LocaleCompare("-version",option+1) == 0))
{
- (void) FormatLocaleFile(stdout,"Version: %s\n",
- GetMagickVersion((size_t *) NULL));
- (void) FormatLocaleFile(stdout,"Copyright: %s\n",
- GetMagickCopyright());
- (void) FormatLocaleFile(stdout,"Features: %s\n\n",
- GetMagickFeatures());
+ ListMagickVersion(stdout);
break;
}
if (LocaleCompare("virtual-pixel",option+1) == 0)
ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
image=GetImageFromList(image,0);
reconstruct_image=GetImageFromList(image,1);
+ offset.x=0;
+ offset.y=0;
if (subimage_search != MagickFalse)
{
- similarity_image=SimilarityImage(image,reconstruct_image,metric,&offset,
- &similarity_metric,exception);
+ similarity_image=SimilarityImage(image,reconstruct_image,metric,
+ similarity_threshold,&offset,&similarity_metric,exception);
if (similarity_metric > dissimilarity_threshold)
ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename);
}
if ((reconstruct_image->columns == image->columns) &&
- (reconstruct_image->rows == image->rows))
+ (reconstruct_image->rows == image->rows))
difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
exception);
else
if (similarity_image == (Image *) NULL)
- ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
- image->filename)
+ {
+ if (metric == PerceptualHashErrorMetric)
+ difference_image=CompareImages(image,reconstruct_image,metric,
+ &distortion,exception);
+ else
+ ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
+ image->filename);
+ }
else
{
Image
&distortion,exception);
else
{
+ Image
+ *distort_image;
+
+ RectangleInfo
+ page;
+
(void) CompositeImage(composite_image,reconstruct_image,
- CopyCompositeOp,MagickFalse,offset.x,offset.y,exception);
+ CopyCompositeOp,MagickTrue,offset.x,offset.y,exception);
difference_image=CompareImages(image,composite_image,metric,
&distortion,exception);
if (difference_image != (Image *) NULL)
difference_image->page.y=offset.y;
}
composite_image=DestroyImage(composite_image);
+ page.width=reconstruct_image->columns;
+ page.height=reconstruct_image->rows;
+ page.x=offset.x;
+ page.y=offset.y;
+ distort_image=CropImage(image,&page,exception);
+ if (distort_image != (Image *) NULL)
+ {
+ Image
+ *sans_image;
+
+ sans_image=CompareImages(distort_image,reconstruct_image,metric,
+ &distortion,exception);
+ distort_image=DestroyImage(distort_image);
+ if (sans_image != (Image *) NULL)
+ sans_image=DestroyImage(sans_image);
+ }
}
if (difference_image != (Image *) NULL)
{
case FuzzErrorMetric:
case MeanAbsoluteErrorMetric:
case MeanSquaredErrorMetric:
- case RootMeanSquaredErrorMetric:
case PeakAbsoluteErrorMetric:
+ case RootMeanSquaredErrorMetric:
{
(void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion,
(double) distortion);
- if ((reconstruct_image->columns != image->columns) ||
- (reconstruct_image->rows != image->rows))
- (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
- difference_image->page.x,(double) difference_image->page.y);
- (void) FormatLocaleFile(stderr,"\n");
break;
}
case AbsoluteErrorMetric:
case NormalizedCrossCorrelationErrorMetric:
- case PeakSignalToNoiseRatioMetric:
+ case PeakSignalToNoiseRatioErrorMetric:
+ case PerceptualHashErrorMetric:
{
(void) FormatLocaleFile(stderr,"%g",distortion);
- if ((reconstruct_image->columns != image->columns) ||
- (reconstruct_image->rows != image->rows))
- (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
- difference_image->page.x,(double) difference_image->page.y);
- (void) FormatLocaleFile(stderr,"\n");
break;
}
- case MeanErrorPerPixelMetric:
+ case MeanErrorPerPixelErrorMetric:
{
(void) FormatLocaleFile(stderr,"%g (%g, %g)",distortion,
image->error.normalized_mean_error,
image->error.normalized_maximum_error);
- if ((reconstruct_image->columns != image->columns) ||
- (reconstruct_image->rows != image->rows))
- (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
- difference_image->page.x,(double) difference_image->page.y);
- (void) FormatLocaleFile(stderr,"\n");
break;
}
- case UndefinedMetric:
+ case UndefinedErrorMetric:
break;
}
+ if (subimage_search != MagickFalse)
+ (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
+ difference_image->page.x,(double) difference_image->page.y);
}
else
{
case FuzzErrorMetric:
case MeanAbsoluteErrorMetric:
case MeanSquaredErrorMetric:
- case RootMeanSquaredErrorMetric:
case PeakAbsoluteErrorMetric:
+ case RootMeanSquaredErrorMetric:
{
switch (image->colorspace)
{
(void) FormatLocaleFile(stderr," blue: %g (%g)\n",
QuantumRange*channel_distortion[BluePixelChannel],
channel_distortion[BluePixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
QuantumRange*channel_distortion[AlphaPixelChannel],
channel_distortion[AlphaPixelChannel]);
(void) FormatLocaleFile(stderr," black: %g (%g)\n",
QuantumRange*channel_distortion[BlackPixelChannel],
channel_distortion[BlackPixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
QuantumRange*channel_distortion[AlphaPixelChannel],
channel_distortion[AlphaPixelChannel]);
(void) FormatLocaleFile(stderr," gray: %g (%g)\n",
QuantumRange*channel_distortion[GrayPixelChannel],
channel_distortion[GrayPixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
QuantumRange*channel_distortion[AlphaPixelChannel],
channel_distortion[AlphaPixelChannel]);
}
case AbsoluteErrorMetric:
case NormalizedCrossCorrelationErrorMetric:
- case PeakSignalToNoiseRatioMetric:
+ case PeakSignalToNoiseRatioErrorMetric:
+ case PerceptualHashErrorMetric:
{
switch (image->colorspace)
{
channel_distortion[GreenPixelChannel]);
(void) FormatLocaleFile(stderr," blue: %g\n",
channel_distortion[BluePixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g\n",
channel_distortion[AlphaPixelChannel]);
break;
channel_distortion[YellowPixelChannel]);
(void) FormatLocaleFile(stderr," black: %g\n",
channel_distortion[BlackPixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g\n",
channel_distortion[AlphaPixelChannel]);
break;
{
(void) FormatLocaleFile(stderr," gray: %g\n",
channel_distortion[GrayPixelChannel]);
- if (image->matte != MagickFalse)
+ if (image->alpha_trait == BlendPixelTrait)
(void) FormatLocaleFile(stderr," alpha: %g\n",
channel_distortion[AlphaPixelChannel]);
break;
channel_distortion[MaxPixelChannels]);
break;
}
- case MeanErrorPerPixelMetric:
+ case MeanErrorPerPixelErrorMetric:
{
(void) FormatLocaleFile(stderr," %g (%g, %g)\n",
channel_distortion[MaxPixelChannels],
image->error.normalized_maximum_error);
break;
}
- case UndefinedMetric:
+ case UndefinedErrorMetric:
break;
}
channel_distortion=(double *) RelinquishMagickMemory(
channel_distortion);
+ if (subimage_search != MagickFalse)
+ (void) FormatLocaleFile(stderr," Offset: %.20g,%.20g\n",(double)
+ difference_image->page.x,(double) difference_image->page.y);
}
status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
if ((metadata != (char **) NULL) && (format != (char *) NULL))
ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
GetExceptionMessage(errno));
(void) ConcatenateString(&(*metadata),text);
- (void) ConcatenateString(&(*metadata),"\n");
text=DestroyString(text);
}
difference_image=DestroyImageList(difference_image);
}
DestroyCompare();
+ if ((metric == NormalizedCrossCorrelationErrorMetric) ||
+ (metric == UndefinedErrorMetric))
+ {
+ if (fabs(distortion-1.0) > CompareEpsilon)
+ (void) SetImageOption(image_info,"compare:dissimilar","true");
+ }
+ else
+ if (fabs(distortion) > CompareEpsilon)
+ (void) SetImageOption(image_info,"compare:dissimilar","true");
return(status != 0 ? MagickTrue : MagickFalse);
}