2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6 % CCCC OOO M M PPPP AAA RRRR EEEEE %
7 % C O O MM MM P P A A R R E %
8 % C O O M M M PPPP AAAAA RRRR EEE %
9 % C O O M M P A A R R E %
10 % CCCC OOO M M P A A R R EEEEE %
13 % Image Comparison Methods %
20 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
28 % Unless required by applicable law or agreed to in writing, software %
29 % distributed under the License is distributed on an "AS IS" BASIS, %
30 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31 % See the License for the specific language governing permissions and %
32 % limitations under the License. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36 % Use the compare program to mathematically and visually annotate the
37 % difference between an image and its reconstruction.
44 #include "MagickWand/studio.h"
45 #include "MagickWand/MagickWand.h"
46 #include "MagickWand/mogrify-private.h"
47 #include "MagickCore/string-private.h"
50 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 % C o m p a r e I m a g e C o m m a n d %
58 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 % CompareImagesCommand() compares two images and returns the difference between
61 % them as a distortion metric and as a new image visually annotating their
64 % The format of the CompareImagesCommand method is:
66 % MagickBooleanType CompareImagesCommand(ImageInfo *image_info,int argc,
67 % char **argv,char **metadata,ExceptionInfo *exception)
69 % A description of each parameter follows:
71 % o image_info: the image info.
73 % o argc: the number of elements in the argument vector.
75 % o argv: A text array containing the command line arguments.
77 % o metadata: any metadata is returned here.
79 % o exception: return any errors or warnings in this structure.
83 static MagickBooleanType CompareUsage(void)
91 "-debug events display copious debugging information",
92 "-help print program options",
93 "-list type print a list of supported option arguments",
94 "-log format format of debugging information",
99 "-alpha option on, activate, off, deactivate, set, opaque, copy",
100 " transparent, extract, background, or shape",
101 "-authenticate password",
102 " decipher image with this password",
103 "-channel type apply option to select image channels",
104 "-colorspace type alternate image colorspace",
105 "-compose operator set image composite operator",
106 "-compress type type of pixel compression when writing the image",
107 "-decipher filename convert cipher pixels to plain pixels",
108 "-define format:option",
109 " define one or more image format options",
110 "-density geometry horizontal and vertical density of the image",
111 "-depth value image depth",
112 "-dissimilarity-threshold value",
113 " maximum distortion for (sub)image match",
114 "-encipher filename convert plain pixels to cipher pixels",
115 "-extract geometry extract area from image",
116 "-format \"string\" output formatted image characteristics",
117 "-fuzz distance colors within this distance are considered equal",
118 "-highlight-color color",
119 " empasize pixel differences with this color",
120 "-identify identify the format and characteristics of the image",
121 "-interlace type type of image interlacing scheme",
122 "-limit type value pixel cache resource limit",
123 "-lowlight-color color",
124 " de-emphasize pixel differences with this color",
125 "-metric type measure differences between images with this metric",
126 "-monitor monitor progress",
127 "-passphrase filename get the passphrase from this file",
128 "-profile filename add, delete, or apply an image profile",
129 "-quality value JPEG/MIFF/PNG compression level",
130 "-quiet suppress all warning messages",
131 "-quantize colorspace reduce colors in this colorspace",
132 "-regard-warnings pay attention to warning messages",
133 "-respect-parentheses settings remain in effect until parenthesis boundary",
134 "-sampling-factor geometry",
135 " horizontal and vertical sampling factor",
136 "-seed value seed a new sequence of pseudo-random numbers",
137 "-set attribute value set an image attribute",
138 "-quality value JPEG/MIFF/PNG compression level",
139 "-size geometry width and height of image",
140 "-subimage-search search for subimage",
141 "-transparent-color color",
142 " transparent color",
143 "-type type image type",
144 "-verbose print detailed information about the image",
145 "-version print version information",
146 "-virtual-pixel method",
147 " virtual pixel access method",
151 (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
152 (void) printf("Copyright: %s\n",GetMagickCopyright());
153 (void) printf("Features: %s\n\n",GetMagickFeatures());
154 (void) printf("Usage: %s [options ...] image reconstruct difference\n",
156 (void) printf("\nImage Settings:\n");
157 for (p=settings; *p != (char *) NULL; p++)
158 (void) printf(" %s\n",*p);
159 (void) printf("\nMiscellaneous Options:\n");
160 for (p=miscellaneous; *p != (char *) NULL; p++)
161 (void) printf(" %s\n",*p);
163 "\nBy default, the image format of `file' is determined by its magic\n");
165 "number. To specify a particular image format, precede the filename\n");
167 "with an image format name and a colon (i.e. ps:image) or specify the\n");
169 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
170 (void) printf("'-' for standard input or output.\n");
174 WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
175 int argc,char **argv,char **metadata,ExceptionInfo *exception)
177 #define DefaultDissimilarityThreshold 0.31830988618379067154
178 #define DestroyCompare() \
180 if (similarity_image != (Image *) NULL) \
181 similarity_image=DestroyImageList(similarity_image); \
182 if (difference_image != (Image *) NULL) \
183 difference_image=DestroyImageList(difference_image); \
184 DestroyImageStack(); \
185 for (i=0; i < (ssize_t) argc; i++) \
186 argv[i]=DestroyString(argv[i]); \
187 argv=(char **) RelinquishMagickMemory(argv); \
189 #define ThrowCompareException(asperity,tag,option) \
191 if (exception->severity < (asperity)) \
192 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
195 return(MagickFalse); \
197 #define ThrowCompareInvalidArgumentException(option,argument) \
199 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
200 "InvalidArgument","`%s': %s",option,argument); \
202 return(MagickFalse); \
213 dissimilarity_threshold,
224 image_stack[MaxImageStackDepth+1];
251 assert(image_info != (ImageInfo *) NULL);
252 assert(image_info->signature == MagickSignature);
253 if (image_info->debug != MagickFalse)
254 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
255 assert(exception != (ExceptionInfo *) NULL);
259 if ((LocaleCompare("version",option+1) == 0) ||
260 (LocaleCompare("-version",option+1) == 0))
262 (void) FormatLocaleFile(stdout,"Version: %s\n",
263 GetMagickVersion((size_t *) NULL));
264 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
265 GetMagickCopyright());
266 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
267 GetMagickFeatures());
272 return(CompareUsage());
273 difference_image=NewImageList();
274 similarity_image=NewImageList();
275 dissimilarity_threshold=DefaultDissimilarityThreshold;
277 format=(char *) NULL;
280 metric=UndefinedMetric;
282 option=(char *) NULL;
284 reconstruct_image=NewImageList();
285 respect_parenthesis=MagickFalse;
287 subimage_search=MagickFalse;
291 ReadCommandlLine(argc,&argv);
292 status=ExpandFilenames(&argc,&argv);
293 if (status == MagickFalse)
294 ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
295 GetExceptionMessage(errno));
296 for (i=1; i < (ssize_t) (argc-1); i++)
299 if (LocaleCompare(option,"(") == 0)
301 FireImageStack(MagickTrue,MagickTrue,pend);
302 if (k == MaxImageStackDepth)
303 ThrowCompareException(OptionError,"ParenthesisNestedTooDeeply",
308 if (LocaleCompare(option,")") == 0)
310 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
312 ThrowCompareException(OptionError,"UnableToParseExpression",option);
316 if (IsCommandOption(option) == MagickFalse)
324 FireImageStack(MagickFalse,MagickFalse,pend);
326 if ((LocaleCompare(filename,"--") == 0) && (i < (ssize_t) (argc-1)))
328 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
329 images=ReadImages(image_info,exception);
330 status&=(images != (Image *) NULL) &&
331 (exception->severity < ErrorException);
332 if (images == (Image *) NULL)
334 AppendImageStack(images);
337 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
342 if (LocaleCompare("alpha",option+1) == 0)
350 if (i == (ssize_t) argc)
351 ThrowCompareException(OptionError,"MissingArgument",option);
352 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
354 ThrowCompareException(OptionError,"UnrecognizedAlphaChannelType",
358 if (LocaleCompare("authenticate",option+1) == 0)
363 if (i == (ssize_t) argc)
364 ThrowCompareException(OptionError,"MissingArgument",option);
367 ThrowCompareException(OptionError,"UnrecognizedOption",option);
371 if (LocaleCompare("cache",option+1) == 0)
376 if (i == (ssize_t) argc)
377 ThrowCompareException(OptionError,"MissingArgument",option);
378 if (IsGeometry(argv[i]) == MagickFalse)
379 ThrowCompareInvalidArgumentException(option,argv[i]);
382 if (LocaleCompare("channel",option+1) == 0)
390 if (i == (ssize_t) (argc-1))
391 ThrowCompareException(OptionError,"MissingArgument",option);
392 channel=ParseChannelOption(argv[i]);
394 ThrowCompareException(OptionError,"UnrecognizedChannelType",
396 SetPixelChannelMap(image,(ChannelType) channel);
399 if (LocaleCompare("colorspace",option+1) == 0)
407 if (i == (ssize_t) (argc-1))
408 ThrowCompareException(OptionError,"MissingArgument",option);
409 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
412 ThrowCompareException(OptionError,"UnrecognizedColorspace",
416 if (LocaleCompare("compose",option+1) == 0)
424 if (i == (ssize_t) argc)
425 ThrowCompareException(OptionError,"MissingArgument",option);
426 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
429 ThrowCompareException(OptionError,"UnrecognizedComposeOperator",
433 if (LocaleCompare("compress",option+1) == 0)
441 if (i == (ssize_t) (argc-1))
442 ThrowCompareException(OptionError,"MissingArgument",option);
443 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
446 ThrowCompareException(OptionError,"UnrecognizedImageCompression",
450 if (LocaleCompare("concurrent",option+1) == 0)
452 ThrowCompareException(OptionError,"UnrecognizedOption",option)
456 if (LocaleCompare("debug",option+1) == 0)
464 if (i == (ssize_t) argc)
465 ThrowCompareException(OptionError,"MissingArgument",option);
466 event_mask=SetLogEventMask(argv[i]);
467 if (event_mask == UndefinedEvents)
468 ThrowCompareException(OptionError,"UnrecognizedEventType",
472 if (LocaleCompare("decipher",option+1) == 0)
477 if (i == (ssize_t) (argc-1))
478 ThrowCompareException(OptionError,"MissingArgument",option);
481 if (LocaleCompare("define",option+1) == 0)
484 if (i == (ssize_t) argc)
485 ThrowCompareException(OptionError,"MissingArgument",option);
491 define=GetImageOption(image_info,argv[i]);
492 if (define == (const char *) NULL)
493 ThrowCompareException(OptionError,"NoSuchOption",argv[i]);
498 if (LocaleCompare("density",option+1) == 0)
503 if (i == (ssize_t) argc)
504 ThrowCompareException(OptionError,"MissingArgument",option);
505 if (IsGeometry(argv[i]) == MagickFalse)
506 ThrowCompareInvalidArgumentException(option,argv[i]);
509 if (LocaleCompare("depth",option+1) == 0)
514 if (i == (ssize_t) argc)
515 ThrowCompareException(OptionError,"MissingArgument",option);
516 if (IsGeometry(argv[i]) == MagickFalse)
517 ThrowCompareInvalidArgumentException(option,argv[i]);
520 if (LocaleCompare("dissimilarity-threshold",option+1) == 0)
525 if (i == (ssize_t) argc)
526 ThrowCompareException(OptionError,"MissingArgument",option);
527 if (IsGeometry(argv[i]) == MagickFalse)
528 ThrowCompareInvalidArgumentException(option,argv[i]);
530 dissimilarity_threshold=DefaultDissimilarityThreshold;
532 dissimilarity_threshold=InterpretLocaleValue(argv[i],
536 if (LocaleCompare("duration",option+1) == 0)
541 if (i == (ssize_t) (argc-1))
542 ThrowCompareException(OptionError,"MissingArgument",option);
543 if (IsGeometry(argv[i]) == MagickFalse)
544 ThrowCompareInvalidArgumentException(option,argv[i]);
547 ThrowCompareException(OptionError,"UnrecognizedOption",option)
551 if (LocaleCompare("encipher",option+1) == 0)
556 if (i == (ssize_t) (argc-1))
557 ThrowCompareException(OptionError,"MissingArgument",option);
560 if (LocaleCompare("extract",option+1) == 0)
565 if (i == (ssize_t) (argc-1))
566 ThrowCompareException(OptionError,"MissingArgument",option);
567 if (IsGeometry(argv[i]) == MagickFalse)
568 ThrowCompareInvalidArgumentException(option,argv[i]);
571 ThrowCompareException(OptionError,"UnrecognizedOption",option)
575 if (LocaleCompare("format",option+1) == 0)
580 if (i == (ssize_t) argc)
581 ThrowCompareException(OptionError,"MissingArgument",option);
585 if (LocaleCompare("fuzz",option+1) == 0)
590 if (i == (ssize_t) (argc-1))
591 ThrowCompareException(OptionError,"MissingArgument",option);
592 if (IsGeometry(argv[i]) == MagickFalse)
593 ThrowCompareInvalidArgumentException(option,argv[i]);
596 ThrowCompareException(OptionError,"UnrecognizedOption",option)
600 if ((LocaleCompare("help",option+1) == 0) ||
601 (LocaleCompare("-help",option+1) == 0))
602 return(CompareUsage());
603 if (LocaleCompare("highlight-color",option+1) == 0)
608 if (i == (ssize_t) (argc-1))
609 ThrowCompareException(OptionError,"MissingArgument",option);
612 ThrowCompareException(OptionError,"UnrecognizedOption",option)
616 if (LocaleCompare("identify",option+1) == 0)
618 if (LocaleCompare("interlace",option+1) == 0)
626 if (i == (ssize_t) argc)
627 ThrowCompareException(OptionError,"MissingArgument",option);
628 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
631 ThrowCompareException(OptionError,"UnrecognizedInterlaceType",
635 ThrowCompareException(OptionError,"UnrecognizedOption",option)
639 if (LocaleCompare("limit",option+1) == 0)
653 if (i == (ssize_t) argc)
654 ThrowCompareException(OptionError,"MissingArgument",option);
655 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
658 ThrowCompareException(OptionError,"UnrecognizedResourceType",
661 if (i == (ssize_t) argc)
662 ThrowCompareException(OptionError,"MissingArgument",option);
663 value=InterpretLocaleValue(argv[i],&p);
665 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
666 ThrowCompareInvalidArgumentException(option,argv[i]);
669 if (LocaleCompare("list",option+1) == 0)
677 if (i == (ssize_t) argc)
678 ThrowCompareException(OptionError,"MissingArgument",option);
679 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
681 ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]);
682 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
685 return(status != 0 ? MagickFalse : MagickTrue);
687 if (LocaleCompare("log",option+1) == 0)
692 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
693 ThrowCompareException(OptionError,"MissingArgument",option);
696 if (LocaleCompare("lowlight-color",option+1) == 0)
701 if (i == (ssize_t) (argc-1))
702 ThrowCompareException(OptionError,"MissingArgument",option);
705 ThrowCompareException(OptionError,"UnrecognizedOption",option)
709 if (LocaleCompare("matte",option+1) == 0)
711 if (LocaleCompare("metric",option+1) == 0)
719 if (i == (ssize_t) argc)
720 ThrowCompareException(OptionError,"MissingArgument",option);
721 type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
723 ThrowCompareException(OptionError,"UnrecognizedMetricType",
725 metric=(MetricType) type;
728 if (LocaleCompare("monitor",option+1) == 0)
730 ThrowCompareException(OptionError,"UnrecognizedOption",option)
734 if (LocaleCompare("passphrase",option+1) == 0)
739 if (i == (ssize_t) argc)
740 ThrowCompareException(OptionError,"MissingArgument",option);
743 if (LocaleCompare("profile",option+1) == 0)
746 if (i == (ssize_t) (argc-1))
747 ThrowCompareException(OptionError,"MissingArgument",option);
750 ThrowCompareException(OptionError,"UnrecognizedOption",option)
754 if (LocaleCompare("quality",option+1) == 0)
759 if (i == (ssize_t) (argc-1))
760 ThrowCompareException(OptionError,"MissingArgument",option);
761 if (IsGeometry(argv[i]) == MagickFalse)
762 ThrowCompareInvalidArgumentException(option,argv[i]);
765 if (LocaleCompare("quantize",option+1) == 0)
773 if (i == (ssize_t) (argc-1))
774 ThrowCompareException(OptionError,"MissingArgument",option);
775 colorspace=ParseCommandOption(MagickColorspaceOptions,
776 MagickFalse,argv[i]);
778 ThrowCompareException(OptionError,"UnrecognizedColorspace",
782 if (LocaleCompare("quiet",option+1) == 0)
784 ThrowCompareException(OptionError,"UnrecognizedOption",option)
788 if (LocaleCompare("regard-warnings",option+1) == 0)
790 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
792 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
795 ThrowCompareException(OptionError,"UnrecognizedOption",option)
799 if (LocaleCompare("sampling-factor",option+1) == 0)
804 if (i == (ssize_t) argc)
805 ThrowCompareException(OptionError,"MissingArgument",option);
806 if (IsGeometry(argv[i]) == MagickFalse)
807 ThrowCompareInvalidArgumentException(option,argv[i]);
810 if (LocaleCompare("seed",option+1) == 0)
815 if (i == (ssize_t) (argc-1))
816 ThrowCompareException(OptionError,"MissingArgument",option);
817 if (IsGeometry(argv[i]) == MagickFalse)
818 ThrowCompareInvalidArgumentException(option,argv[i]);
821 if (LocaleCompare("set",option+1) == 0)
824 if (i == (ssize_t) argc)
825 ThrowCompareException(OptionError,"MissingArgument",option);
829 if (i == (ssize_t) argc)
830 ThrowCompareException(OptionError,"MissingArgument",option);
833 if (LocaleCompare("size",option+1) == 0)
838 if (i == (ssize_t) argc)
839 ThrowCompareException(OptionError,"MissingArgument",option);
840 if (IsGeometry(argv[i]) == MagickFalse)
841 ThrowCompareInvalidArgumentException(option,argv[i]);
844 if (LocaleCompare("subimage-search",option+1) == 0)
848 subimage_search=MagickFalse;
851 subimage_search=MagickTrue;
854 if (LocaleCompare("synchronize",option+1) == 0)
856 ThrowCompareException(OptionError,"UnrecognizedOption",option)
860 if (LocaleCompare("taint",option+1) == 0)
862 if (LocaleCompare("transparent-color",option+1) == 0)
867 if (i == (ssize_t) (argc-1))
868 ThrowCompareException(OptionError,"MissingArgument",option);
871 if (LocaleCompare("type",option+1) == 0)
879 if (i == (ssize_t) argc)
880 ThrowCompareException(OptionError,"MissingArgument",option);
881 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
883 ThrowCompareException(OptionError,"UnrecognizedImageType",
887 ThrowCompareException(OptionError,"UnrecognizedOption",option)
891 if (LocaleCompare("verbose",option+1) == 0)
893 if ((LocaleCompare("version",option+1) == 0) ||
894 (LocaleCompare("-version",option+1) == 0))
896 (void) FormatLocaleFile(stdout,"Version: %s\n",
897 GetMagickVersion((size_t *) NULL));
898 (void) FormatLocaleFile(stdout,"Copyright: %s\n",
899 GetMagickCopyright());
900 (void) FormatLocaleFile(stdout,"Features: %s\n\n",
901 GetMagickFeatures());
904 if (LocaleCompare("virtual-pixel",option+1) == 0)
912 if (i == (ssize_t) (argc-1))
913 ThrowCompareException(OptionError,"MissingArgument",option);
914 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
917 ThrowCompareException(OptionError,
918 "UnrecognizedVirtualPixelMethod",argv[i]);
921 ThrowCompareException(OptionError,"UnrecognizedOption",option)
926 ThrowCompareException(OptionError,"UnrecognizedOption",option)
928 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
929 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
930 if (fire != MagickFalse)
931 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
934 ThrowCompareException(OptionError,"UnbalancedParenthesis",argv[i]);
935 if (i-- != (ssize_t) (argc-1))
936 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
937 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
938 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
939 FinalizeImageSettings(image_info,image,MagickTrue);
940 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
941 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
942 image=GetImageFromList(image,0);
943 reconstruct_image=GetImageFromList(image,1);
944 if (subimage_search != MagickFalse)
946 similarity_image=SimilarityImage(image,reconstruct_image,metric,&offset,
947 &similarity_metric,exception);
948 if (similarity_metric > dissimilarity_threshold)
949 ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename);
951 if ((reconstruct_image->columns == image->columns) &&
952 (reconstruct_image->rows == image->rows))
953 difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
956 if (similarity_image == (Image *) NULL)
957 ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
965 Determine if reconstructed image is a subimage of the image.
967 composite_image=CloneImage(image,0,0,MagickTrue,exception);
968 if (composite_image == (Image *) NULL)
969 difference_image=CompareImages(image,reconstruct_image,metric,
970 &distortion,exception);
973 (void) CompositeImage(composite_image,CopyCompositeOp,
974 reconstruct_image,offset.x,offset.y,exception);
975 difference_image=CompareImages(image,composite_image,metric,
976 &distortion,exception);
977 if (difference_image != (Image *) NULL)
979 difference_image->page.x=offset.x;
980 difference_image->page.y=offset.y;
982 composite_image=DestroyImage(composite_image);
984 if (difference_image != (Image *) NULL)
986 AppendImageToList(&difference_image,similarity_image);
987 similarity_image=(Image *) NULL;
990 if (difference_image == (Image *) NULL)
994 if (image_info->verbose != MagickFalse)
995 (void) IsImagesEqual(image,reconstruct_image,exception);
996 if (*difference_image->magick == '\0')
997 (void) CopyMagickString(difference_image->magick,image->magick,
999 if (image_info->verbose == MagickFalse)
1003 case FuzzErrorMetric:
1004 case MeanAbsoluteErrorMetric:
1005 case MeanSquaredErrorMetric:
1006 case RootMeanSquaredErrorMetric:
1007 case PeakAbsoluteErrorMetric:
1009 (void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion,
1010 (double) distortion);
1011 if ((reconstruct_image->columns != image->columns) ||
1012 (reconstruct_image->rows != image->rows))
1013 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
1014 difference_image->page.x,(double) difference_image->page.y);
1015 (void) FormatLocaleFile(stderr,"\n");
1018 case AbsoluteErrorMetric:
1019 case NormalizedCrossCorrelationErrorMetric:
1020 case PeakSignalToNoiseRatioMetric:
1022 (void) FormatLocaleFile(stderr,"%g",distortion);
1023 if ((reconstruct_image->columns != image->columns) ||
1024 (reconstruct_image->rows != image->rows))
1025 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
1026 difference_image->page.x,(double) difference_image->page.y);
1027 (void) FormatLocaleFile(stderr,"\n");
1030 case MeanErrorPerPixelMetric:
1032 (void) FormatLocaleFile(stderr,"%g (%g, %g)",distortion,
1033 image->error.normalized_mean_error,
1034 image->error.normalized_maximum_error);
1035 if ((reconstruct_image->columns != image->columns) ||
1036 (reconstruct_image->rows != image->rows))
1037 (void) FormatLocaleFile(stderr," @ %.20g,%.20g",(double)
1038 difference_image->page.x,(double) difference_image->page.y);
1039 (void) FormatLocaleFile(stderr,"\n");
1042 case UndefinedMetric:
1049 *channel_distortion;
1051 channel_distortion=GetImageDistortions(image,reconstruct_image,
1052 metric,&image->exception);
1053 (void) FormatLocaleFile(stderr,"Image: %s\n",image->filename);
1054 if ((reconstruct_image->columns != image->columns) ||
1055 (reconstruct_image->rows != image->rows))
1056 (void) FormatLocaleFile(stderr,"Offset: %.20g,%.20g\n",(double)
1057 difference_image->page.x,(double) difference_image->page.y);
1058 (void) FormatLocaleFile(stderr," Channel distortion: %s\n",
1059 CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
1062 case FuzzErrorMetric:
1063 case MeanAbsoluteErrorMetric:
1064 case MeanSquaredErrorMetric:
1065 case RootMeanSquaredErrorMetric:
1066 case PeakAbsoluteErrorMetric:
1068 switch (image->colorspace)
1073 (void) FormatLocaleFile(stderr," red: %g (%g)\n",
1074 QuantumRange*channel_distortion[RedPixelChannel],
1075 channel_distortion[RedPixelChannel]);
1076 (void) FormatLocaleFile(stderr," green: %g (%g)\n",
1077 QuantumRange*channel_distortion[GreenPixelChannel],
1078 channel_distortion[GreenPixelChannel]);
1079 (void) FormatLocaleFile(stderr," blue: %g (%g)\n",
1080 QuantumRange*channel_distortion[BluePixelChannel],
1081 channel_distortion[BluePixelChannel]);
1082 if (image->matte != MagickFalse)
1083 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
1084 QuantumRange*channel_distortion[AlphaPixelChannel],
1085 channel_distortion[AlphaPixelChannel]);
1088 case CMYKColorspace:
1090 (void) FormatLocaleFile(stderr," cyan: %g (%g)\n",
1091 QuantumRange*channel_distortion[CyanPixelChannel],
1092 channel_distortion[CyanPixelChannel]);
1093 (void) FormatLocaleFile(stderr," magenta: %g (%g)\n",
1094 QuantumRange*channel_distortion[MagentaPixelChannel],
1095 channel_distortion[MagentaPixelChannel]);
1096 (void) FormatLocaleFile(stderr," yellow: %g (%g)\n",
1097 QuantumRange*channel_distortion[YellowPixelChannel],
1098 channel_distortion[YellowPixelChannel]);
1099 (void) FormatLocaleFile(stderr," black: %g (%g)\n",
1100 QuantumRange*channel_distortion[BlackPixelChannel],
1101 channel_distortion[BlackPixelChannel]);
1102 if (image->matte != MagickFalse)
1103 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
1104 QuantumRange*channel_distortion[AlphaPixelChannel],
1105 channel_distortion[AlphaPixelChannel]);
1108 case GRAYColorspace:
1110 (void) FormatLocaleFile(stderr," gray: %g (%g)\n",
1111 QuantumRange*channel_distortion[GrayPixelChannel],
1112 channel_distortion[GrayPixelChannel]);
1113 if (image->matte != MagickFalse)
1114 (void) FormatLocaleFile(stderr," alpha: %g (%g)\n",
1115 QuantumRange*channel_distortion[AlphaPixelChannel],
1116 channel_distortion[AlphaPixelChannel]);
1120 (void) FormatLocaleFile(stderr," all: %g (%g)\n",
1121 QuantumRange*channel_distortion[MaxPixelChannels],
1122 channel_distortion[MaxPixelChannels]);
1125 case AbsoluteErrorMetric:
1126 case NormalizedCrossCorrelationErrorMetric:
1127 case PeakSignalToNoiseRatioMetric:
1129 switch (image->colorspace)
1134 (void) FormatLocaleFile(stderr," red: %g\n",
1135 channel_distortion[RedPixelChannel]);
1136 (void) FormatLocaleFile(stderr," green: %g\n",
1137 channel_distortion[GreenPixelChannel]);
1138 (void) FormatLocaleFile(stderr," blue: %g\n",
1139 channel_distortion[BluePixelChannel]);
1140 if (image->matte != MagickFalse)
1141 (void) FormatLocaleFile(stderr," alpha: %g\n",
1142 channel_distortion[AlphaPixelChannel]);
1145 case CMYKColorspace:
1147 (void) FormatLocaleFile(stderr," cyan: %g\n",
1148 channel_distortion[CyanPixelChannel]);
1149 (void) FormatLocaleFile(stderr," magenta: %g\n",
1150 channel_distortion[MagentaPixelChannel]);
1151 (void) FormatLocaleFile(stderr," yellow: %g\n",
1152 channel_distortion[YellowPixelChannel]);
1153 (void) FormatLocaleFile(stderr," black: %g\n",
1154 channel_distortion[BlackPixelChannel]);
1155 if (image->matte != MagickFalse)
1156 (void) FormatLocaleFile(stderr," alpha: %g\n",
1157 channel_distortion[AlphaPixelChannel]);
1160 case GRAYColorspace:
1162 (void) FormatLocaleFile(stderr," gray: %g\n",
1163 channel_distortion[GrayPixelChannel]);
1164 if (image->matte != MagickFalse)
1165 (void) FormatLocaleFile(stderr," alpha: %g\n",
1166 channel_distortion[AlphaPixelChannel]);
1170 (void) FormatLocaleFile(stderr," all: %g\n",
1171 channel_distortion[MaxPixelChannels]);
1174 case MeanErrorPerPixelMetric:
1176 (void) FormatLocaleFile(stderr," %g (%g, %g)\n",
1177 channel_distortion[MaxPixelChannels],
1178 image->error.normalized_mean_error,
1179 image->error.normalized_maximum_error);
1182 case UndefinedMetric:
1185 channel_distortion=(double *) RelinquishMagickMemory(
1186 channel_distortion);
1188 status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
1189 if ((metadata != (char **) NULL) && (format != (char *) NULL))
1194 text=InterpretImageProperties(image_info,difference_image,format,
1196 if (text == (char *) NULL)
1197 ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
1198 GetExceptionMessage(errno));
1199 (void) ConcatenateString(&(*metadata),text);
1200 (void) ConcatenateString(&(*metadata),"\n");
1201 text=DestroyString(text);
1203 difference_image=DestroyImageList(difference_image);
1206 return(status != 0 ? MagickTrue : MagickFalse);