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-2010 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 "wand/studio.h"
45 #include "wand/MagickWand.h"
46 #include "wand/mogrify-private.h"
47 #include "magick/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 % CompareImageCommand() 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 CompareImageCommand method is:
66 % MagickBooleanType CompareImageCommand(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 RMSE 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 CompareImageCommand(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); \
216 dissimilarity_threshold,
227 image_stack[MaxImageStackDepth+1];
253 assert(image_info != (ImageInfo *) NULL);
254 assert(image_info->signature == MagickSignature);
255 if (image_info->debug != MagickFalse)
256 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
257 assert(exception != (ExceptionInfo *) NULL);
261 if ((LocaleCompare("version",option+1) == 0) ||
262 (LocaleCompare("-version",option+1) == 0))
264 (void) fprintf(stdout,"Version: %s\n",
265 GetMagickVersion((size_t *) NULL));
266 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
267 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
272 return(CompareUsage());
273 channels=AllChannels;
274 difference_image=NewImageList();
275 similarity_image=NewImageList();
276 dissimilarity_threshold=DefaultDissimilarityThreshold;
278 format=(char *) NULL;
281 metric=UndefinedMetric;
283 option=(char *) NULL;
285 reconstruct_image=NewImageList();
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 (IsMagickOption(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=ParseMagickOption(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 channels=(ChannelType) channel;
399 if (LocaleCompare("colorspace",option+1) == 0)
407 if (i == (ssize_t) (argc-1))
408 ThrowCompareException(OptionError,"MissingArgument",option);
409 colorspace=ParseMagickOption(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=ParseMagickOption(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=ParseMagickOption(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=StringToDouble(argv[i]);
535 if (LocaleCompare("duration",option+1) == 0)
540 if (i == (ssize_t) (argc-1))
541 ThrowCompareException(OptionError,"MissingArgument",option);
542 if (IsGeometry(argv[i]) == MagickFalse)
543 ThrowCompareInvalidArgumentException(option,argv[i]);
546 ThrowCompareException(OptionError,"UnrecognizedOption",option)
550 if (LocaleCompare("encipher",option+1) == 0)
555 if (i == (ssize_t) (argc-1))
556 ThrowCompareException(OptionError,"MissingArgument",option);
559 if (LocaleCompare("extract",option+1) == 0)
564 if (i == (ssize_t) (argc-1))
565 ThrowCompareException(OptionError,"MissingArgument",option);
566 if (IsGeometry(argv[i]) == MagickFalse)
567 ThrowCompareInvalidArgumentException(option,argv[i]);
570 ThrowCompareException(OptionError,"UnrecognizedOption",option)
574 if (LocaleCompare("format",option+1) == 0)
579 if (i == (ssize_t) argc)
580 ThrowCompareException(OptionError,"MissingArgument",option);
584 if (LocaleCompare("fuzz",option+1) == 0)
589 if (i == (ssize_t) (argc-1))
590 ThrowCompareException(OptionError,"MissingArgument",option);
591 if (IsGeometry(argv[i]) == MagickFalse)
592 ThrowCompareInvalidArgumentException(option,argv[i]);
595 ThrowCompareException(OptionError,"UnrecognizedOption",option)
599 if ((LocaleCompare("help",option+1) == 0) ||
600 (LocaleCompare("-help",option+1) == 0))
601 return(CompareUsage());
602 if (LocaleCompare("highlight-color",option+1) == 0)
607 if (i == (ssize_t) (argc-1))
608 ThrowCompareException(OptionError,"MissingArgument",option);
611 ThrowCompareException(OptionError,"UnrecognizedOption",option)
615 if (LocaleCompare("identify",option+1) == 0)
617 if (LocaleCompare("interlace",option+1) == 0)
625 if (i == (ssize_t) argc)
626 ThrowCompareException(OptionError,"MissingArgument",option);
627 interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
630 ThrowCompareException(OptionError,"UnrecognizedInterlaceType",
634 ThrowCompareException(OptionError,"UnrecognizedOption",option)
638 if (LocaleCompare("limit",option+1) == 0)
652 if (i == (ssize_t) argc)
653 ThrowCompareException(OptionError,"MissingArgument",option);
654 resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
657 ThrowCompareException(OptionError,"UnrecognizedResourceType",
660 if (i == (ssize_t) argc)
661 ThrowCompareException(OptionError,"MissingArgument",option);
662 value=strtod(argv[i],&p);
663 if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
664 ThrowCompareInvalidArgumentException(option,argv[i]);
667 if (LocaleCompare("list",option+1) == 0)
675 if (i == (ssize_t) argc)
676 ThrowCompareException(OptionError,"MissingArgument",option);
677 list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
679 ThrowCompareException(OptionError,"UnrecognizedListType",argv[i]);
680 status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
683 return(status != 0 ? MagickFalse : MagickTrue);
685 if (LocaleCompare("log",option+1) == 0)
690 if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
691 ThrowCompareException(OptionError,"MissingArgument",option);
694 if (LocaleCompare("lowlight-color",option+1) == 0)
699 if (i == (ssize_t) (argc-1))
700 ThrowCompareException(OptionError,"MissingArgument",option);
703 ThrowCompareException(OptionError,"UnrecognizedOption",option)
707 if (LocaleCompare("matte",option+1) == 0)
709 if (LocaleCompare("metric",option+1) == 0)
717 if (i == (ssize_t) argc)
718 ThrowCompareException(OptionError,"MissingArgument",option);
719 type=ParseMagickOption(MagickMetricOptions,MagickTrue,argv[i]);
721 ThrowCompareException(OptionError,"UnrecognizedMetricType",
723 metric=(MetricType) type;
726 if (LocaleCompare("monitor",option+1) == 0)
728 ThrowCompareException(OptionError,"UnrecognizedOption",option)
732 if (LocaleCompare("passphrase",option+1) == 0)
737 if (i == (ssize_t) argc)
738 ThrowCompareException(OptionError,"MissingArgument",option);
741 if (LocaleCompare("profile",option+1) == 0)
744 if (i == (ssize_t) (argc-1))
745 ThrowCompareException(OptionError,"MissingArgument",option);
748 ThrowCompareException(OptionError,"UnrecognizedOption",option)
752 if (LocaleCompare("quality",option+1) == 0)
757 if (i == (ssize_t) (argc-1))
758 ThrowCompareException(OptionError,"MissingArgument",option);
759 if (IsGeometry(argv[i]) == MagickFalse)
760 ThrowCompareInvalidArgumentException(option,argv[i]);
763 if (LocaleCompare("quantize",option+1) == 0)
771 if (i == (ssize_t) (argc-1))
772 ThrowCompareException(OptionError,"MissingArgument",option);
773 colorspace=ParseMagickOption(MagickColorspaceOptions,
774 MagickFalse,argv[i]);
776 ThrowCompareException(OptionError,"UnrecognizedColorspace",
780 if (LocaleCompare("quiet",option+1) == 0)
782 ThrowCompareException(OptionError,"UnrecognizedOption",option)
786 if (LocaleCompare("regard-warnings",option+1) == 0)
788 if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
790 respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
793 ThrowCompareException(OptionError,"UnrecognizedOption",option)
797 if (LocaleCompare("sampling-factor",option+1) == 0)
802 if (i == (ssize_t) argc)
803 ThrowCompareException(OptionError,"MissingArgument",option);
804 if (IsGeometry(argv[i]) == MagickFalse)
805 ThrowCompareInvalidArgumentException(option,argv[i]);
808 if (LocaleCompare("seed",option+1) == 0)
813 if (i == (ssize_t) (argc-1))
814 ThrowCompareException(OptionError,"MissingArgument",option);
815 if (IsGeometry(argv[i]) == MagickFalse)
816 ThrowCompareInvalidArgumentException(option,argv[i]);
819 if (LocaleCompare("set",option+1) == 0)
822 if (i == (ssize_t) argc)
823 ThrowCompareException(OptionError,"MissingArgument",option);
827 if (i == (ssize_t) argc)
828 ThrowCompareException(OptionError,"MissingArgument",option);
831 if (LocaleCompare("size",option+1) == 0)
836 if (i == (ssize_t) argc)
837 ThrowCompareException(OptionError,"MissingArgument",option);
838 if (IsGeometry(argv[i]) == MagickFalse)
839 ThrowCompareInvalidArgumentException(option,argv[i]);
842 if (LocaleCompare("subimage-search",option+1) == 0)
846 subimage_search=MagickFalse;
849 subimage_search=MagickTrue;
852 if (LocaleCompare("synchronize",option+1) == 0)
854 ThrowCompareException(OptionError,"UnrecognizedOption",option)
858 if (LocaleCompare("taint",option+1) == 0)
860 if (LocaleCompare("transparent-color",option+1) == 0)
865 if (i == (ssize_t) (argc-1))
866 ThrowCompareException(OptionError,"MissingArgument",option);
869 if (LocaleCompare("type",option+1) == 0)
877 if (i == (ssize_t) argc)
878 ThrowCompareException(OptionError,"MissingArgument",option);
879 type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
881 ThrowCompareException(OptionError,"UnrecognizedImageType",
885 ThrowCompareException(OptionError,"UnrecognizedOption",option)
889 if (LocaleCompare("verbose",option+1) == 0)
891 if ((LocaleCompare("version",option+1) == 0) ||
892 (LocaleCompare("-version",option+1) == 0))
894 (void) fprintf(stdout,"Version: %s\n",
895 GetMagickVersion((size_t *) NULL));
896 (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
897 (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
900 if (LocaleCompare("virtual-pixel",option+1) == 0)
908 if (i == (ssize_t) (argc-1))
909 ThrowCompareException(OptionError,"MissingArgument",option);
910 method=ParseMagickOption(MagickVirtualPixelOptions,MagickFalse,
913 ThrowCompareException(OptionError,
914 "UnrecognizedVirtualPixelMethod",argv[i]);
917 ThrowCompareException(OptionError,"UnrecognizedOption",option)
922 ThrowCompareException(OptionError,"UnrecognizedOption",option)
924 fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
925 MagickFalse : MagickTrue;
926 if (fire != MagickFalse)
927 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
930 ThrowCompareException(OptionError,"UnbalancedParenthesis",argv[i]);
931 if (i-- != (ssize_t) (argc-1))
932 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
933 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
934 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
935 FinalizeImageSettings(image_info,image,MagickTrue);
936 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
937 ThrowCompareException(OptionError,"MissingAnImageFilename",argv[i]);
938 image=GetImageFromList(image,0);
939 reconstruct_image=GetImageFromList(image,1);
940 if (subimage_search != MagickFalse)
942 similarity_image=SimilarityImage(image,reconstruct_image,&offset,
943 &similarity_metric,exception);
944 if (similarity_metric > dissimilarity_threshold)
945 ThrowCompareException(ImageError,"ImagesTooDissimilar",image->filename);
947 if ((reconstruct_image->columns == image->columns) &&
948 (reconstruct_image->rows == image->rows))
949 difference_image=CompareImageChannels(image,reconstruct_image,channels,
950 metric,&distortion,exception);
952 if (similarity_image == (Image *) NULL)
953 ThrowCompareException(OptionError,"ImageWidthsOrHeightsDiffer",
961 Determine if reconstructed image is a subimage of the image.
963 composite_image=CloneImage(image,0,0,MagickTrue,exception);
964 if (composite_image == (Image *) NULL)
965 difference_image=CompareImageChannels(image,reconstruct_image,
966 channels,metric,&distortion,exception);
969 (void) CompositeImage(composite_image,CopyCompositeOp,
970 reconstruct_image,offset.x,offset.y);
971 difference_image=CompareImageChannels(image,composite_image,
972 channels,metric,&distortion,exception);
973 if (difference_image != (Image *) NULL)
975 difference_image->page.x=offset.x;
976 difference_image->page.y=offset.y;
978 composite_image=DestroyImage(composite_image);
980 if (difference_image != (Image *) NULL)
982 AppendImageToList(&difference_image,similarity_image);
983 similarity_image=(Image *) NULL;
986 if (difference_image == (Image *) NULL)
990 if (image_info->verbose != MagickFalse)
991 (void) IsImagesEqual(image,reconstruct_image);
992 if (*difference_image->magick == '\0')
993 (void) CopyMagickString(difference_image->magick,image->magick,
995 if (image_info->verbose == MagickFalse)
999 case MeanAbsoluteErrorMetric:
1000 case MeanSquaredErrorMetric:
1001 case RootMeanSquaredErrorMetric:
1002 case PeakAbsoluteErrorMetric:
1004 (void) fprintf(stderr,"%g (%g)",QuantumRange*distortion,
1005 (double) distortion);
1006 if ((reconstruct_image->columns != image->columns) ||
1007 (reconstruct_image->rows != image->rows))
1008 (void) fprintf(stderr," @ %.20g,%.20g",(double)
1009 difference_image->page.x,(double) difference_image->page.y);
1010 (void) fprintf(stderr,"\n");
1013 case AbsoluteErrorMetric:
1014 case PeakSignalToNoiseRatioMetric:
1016 (void) fprintf(stderr,"%g",distortion);
1017 if ((reconstruct_image->columns != image->columns) ||
1018 (reconstruct_image->rows != image->rows))
1019 (void) fprintf(stderr," @ %.20g,%.20g",(double)
1020 difference_image->page.x,(double) difference_image->page.y);
1021 (void) fprintf(stderr,"\n");
1024 case MeanErrorPerPixelMetric:
1026 (void) fprintf(stderr,"%g (%g, %g)",distortion,
1027 image->error.normalized_mean_error,
1028 image->error.normalized_maximum_error);
1029 if ((reconstruct_image->columns != image->columns) ||
1030 (reconstruct_image->rows != image->rows))
1031 (void) fprintf(stderr," @ %.20g,%.20g",(double)
1032 difference_image->page.x,(double) difference_image->page.y);
1033 (void) fprintf(stderr,"\n");
1036 case UndefinedMetric:
1043 *channel_distortion;
1045 channel_distortion=GetImageChannelDistortions(image,reconstruct_image,
1046 metric,&image->exception);
1047 (void) fprintf(stderr,"Image: %s\n",image->filename);
1048 if ((reconstruct_image->columns != image->columns) ||
1049 (reconstruct_image->rows != image->rows))
1050 (void) fprintf(stderr,"Offset: %.20g,%.20g\n",(double)
1051 difference_image->page.x,(double) difference_image->page.y);
1052 (void) fprintf(stderr," Channel distortion: %s\n",
1053 MagickOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
1056 case MeanAbsoluteErrorMetric:
1057 case MeanSquaredErrorMetric:
1058 case RootMeanSquaredErrorMetric:
1059 case PeakAbsoluteErrorMetric:
1061 switch (image->colorspace)
1066 (void) fprintf(stderr," red: %g (%g)\n",
1067 QuantumRange*channel_distortion[RedChannel],
1068 channel_distortion[RedChannel]);
1069 (void) fprintf(stderr," green: %g (%g)\n",
1070 QuantumRange*channel_distortion[GreenChannel],
1071 channel_distortion[GreenChannel]);
1072 (void) fprintf(stderr," blue: %g (%g)\n",
1073 QuantumRange*channel_distortion[BlueChannel],
1074 channel_distortion[BlueChannel]);
1075 if (image->matte != MagickFalse)
1076 (void) fprintf(stderr," alpha: %g (%g)\n",
1077 QuantumRange*channel_distortion[OpacityChannel],
1078 channel_distortion[OpacityChannel]);
1081 case CMYKColorspace:
1083 (void) fprintf(stderr," cyan: %g (%g)\n",
1084 QuantumRange*channel_distortion[CyanChannel],
1085 channel_distortion[CyanChannel]);
1086 (void) fprintf(stderr," magenta: %g (%g)\n",
1087 QuantumRange*channel_distortion[MagentaChannel],
1088 channel_distortion[MagentaChannel]);
1089 (void) fprintf(stderr," yellow: %g (%g)\n",
1090 QuantumRange*channel_distortion[YellowChannel],
1091 channel_distortion[YellowChannel]);
1092 (void) fprintf(stderr," black: %g (%g)\n",
1093 QuantumRange*channel_distortion[BlackChannel],
1094 channel_distortion[BlackChannel]);
1095 if (image->matte != MagickFalse)
1096 (void) fprintf(stderr," alpha: %g (%g)\n",
1097 QuantumRange*channel_distortion[OpacityChannel],
1098 channel_distortion[OpacityChannel]);
1101 case GRAYColorspace:
1103 (void) fprintf(stderr," gray: %g (%g)\n",
1104 QuantumRange*channel_distortion[GrayChannel],
1105 channel_distortion[GrayChannel]);
1106 if (image->matte != MagickFalse)
1107 (void) fprintf(stderr," alpha: %g (%g)\n",
1108 QuantumRange*channel_distortion[OpacityChannel],
1109 channel_distortion[OpacityChannel]);
1113 (void) fprintf(stderr," all: %g (%g)\n",
1114 QuantumRange*channel_distortion[AllChannels],
1115 channel_distortion[AllChannels]);
1118 case AbsoluteErrorMetric:
1119 case PeakSignalToNoiseRatioMetric:
1121 switch (image->colorspace)
1126 (void) fprintf(stderr," red: %g\n",
1127 channel_distortion[RedChannel]);
1128 (void) fprintf(stderr," green: %g\n",
1129 channel_distortion[GreenChannel]);
1130 (void) fprintf(stderr," blue: %g\n",
1131 channel_distortion[BlueChannel]);
1132 if (image->matte != MagickFalse)
1133 (void) fprintf(stderr," alpha: %g\n",
1134 channel_distortion[OpacityChannel]);
1137 case CMYKColorspace:
1139 (void) fprintf(stderr," cyan: %g\n",
1140 channel_distortion[CyanChannel]);
1141 (void) fprintf(stderr," magenta: %g\n",
1142 channel_distortion[MagentaChannel]);
1143 (void) fprintf(stderr," yellow: %g\n",
1144 channel_distortion[YellowChannel]);
1145 (void) fprintf(stderr," black: %g\n",
1146 channel_distortion[BlackChannel]);
1147 if (image->matte != MagickFalse)
1148 (void) fprintf(stderr," alpha: %g\n",
1149 channel_distortion[OpacityChannel]);
1152 case GRAYColorspace:
1154 (void) fprintf(stderr," gray: %g\n",
1155 channel_distortion[GrayChannel]);
1156 if (image->matte != MagickFalse)
1157 (void) fprintf(stderr," alpha: %g\n",
1158 channel_distortion[OpacityChannel]);
1162 (void) fprintf(stderr," all: %g\n",
1163 channel_distortion[AllChannels]);
1166 case MeanErrorPerPixelMetric:
1168 (void) fprintf(stderr," %g (%g, %g)\n",
1169 channel_distortion[AllChannels],
1170 image->error.normalized_mean_error,
1171 image->error.normalized_maximum_error);
1174 case UndefinedMetric:
1177 channel_distortion=(double *) RelinquishMagickMemory(
1178 channel_distortion);
1180 status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
1181 if ((metadata != (char **) NULL) && (format != (char *) NULL))
1186 text=InterpretImageProperties(image_info,difference_image,format);
1187 if (text == (char *) NULL)
1188 ThrowCompareException(ResourceLimitError,"MemoryAllocationFailed",
1189 GetExceptionMessage(errno));
1190 (void) ConcatenateString(&(*metadata),text);
1191 (void) ConcatenateString(&(*metadata),"\n");
1192 text=DestroyString(text);
1194 difference_image=DestroyImageList(difference_image);
1197 return(status != 0 ? MagickTrue : MagickFalse);