44#include "wand/studio.h"
45#include "wand/MagickWand.h"
46#include "wand/mogrify-private.h"
47#include "magick/image-private.h"
48#include "magick/string-private.h"
84static MagickBooleanType CompareUsage(
void)
88 " -debug events display copious debugging information\n"
89 " -help print program options\n"
90 " -list type print a list of supported option arguments\n"
91 " -log format format of debugging information",
93 " -brightness-contrast geometry\n"
94 " improve brightness / contrast of the image\n"
95 " -distort method args\n"
96 " distort images according to given method and args\n"
97 " -level value adjust the level of image contrast\n"
98 " -resize geometry resize the image\n"
99 " -rotate degrees apply Paeth rotation to the image\n"
100 " -sigmoidal-contrast geometry\n"
101 " increase the contrast without saturating highlights or\n"
102 " -trim trim image edges",
103 sequence_operators[] =
104 " -crop geometry cut out a rectangular region of the image\n"
105 " -separate separate an image channel into a grayscale image\n"
106 " -write filename write images to this file",
108 " -adjoin join images into a single multi-image file\n"
109 " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
110 " transparent, extract, background, or shape\n"
111 " -authenticate password\n"
112 " decipher image with this password\n"
113 " -background color background color\n"
114 " -channel type apply option to select image channels\n"
115 " -colorspace type alternate image colorspace\n"
116 " -compose operator set image composite operator\n"
117 " -compress type type of pixel compression when writing the image\n"
118 " -decipher filename convert cipher pixels to plain pixels\n"
119 " -define format:option\n"
120 " define one or more image format options\n"
121 " -density geometry horizontal and vertical density of the image\n"
122 " -depth value image depth\n"
123 " -dissimilarity-threshold value\n"
124 " maximum distortion for (sub)image match\n"
125 " -encipher filename convert plain pixels to cipher pixels\n"
126 " -extract geometry extract area from image\n"
127 " -format \"string\" output formatted image characteristics\n"
128 " -fuzz distance colors within this distance are considered equal\n"
129 " -gravity type horizontal and vertical text placement\n"
130 " -highlight-color color\n"
131 " emphasize pixel differences with this color\n"
132 " -identify identify the format and characteristics of the image\n"
133 " -interlace type type of image interlacing scheme\n"
134 " -limit type value pixel cache resource limit\n"
135 " -lowlight-color color\n"
136 " de-emphasize pixel differences with this color\n"
137 " -mask filename associate a mask with the image\n"
138 " -metric type measure differences between images with this metric\n"
139 " -monitor monitor progress\n"
140 " -passphrase filename get the passphrase from this file\n"
141 " -precision value maximum number of significant digits to print\n"
142 " -profile filename add, delete, or apply an image profile\n"
143 " -quality value JPEG/MIFF/PNG compression level\n"
144 " -quiet suppress all warning messages\n"
145 " -quantize colorspace reduce colors in this colorspace\n"
146 " -regard-warnings pay attention to warning messages\n"
147 " -repage geometry size and location of an image canvas\n"
148 " -respect-parentheses settings remain in effect until parenthesis boundary\n"
149 " -sampling-factor geometry\n"
150 " horizontal and vertical sampling factor\n"
151 " -seed value seed a new sequence of pseudo-random numbers\n"
152 " -set attribute value set an image attribute\n"
153 " -quality value JPEG/MIFF/PNG compression level\n"
154 " -similarity-threshold value\n"
155 " minimum distortion for (sub)image match\n"
156 " -size geometry width and height of image\n"
157 " -subimage-search search for subimage\n"
158 " -synchronize synchronize image to storage device\n"
159 " -taint declare the image as modified\n"
160 " -transparent-color color\n"
161 " transparent color\n"
162 " -type type image type\n"
163 " -verbose print detailed information about the image\n"
164 " -version print version information\n"
165 " -virtual-pixel method\n"
166 " virtual pixel access method",
168 " -delete indexes delete the image from the image sequence";
170 ListMagickVersion(stdout);
171 (void) printf(
"Usage: %s [options ...] image reconstruct difference\n",
173 (void) printf(
"\nImage Settings:\n");
174 (void) puts(settings);
175 (void) printf(
"\nImage Operators:\n");
176 (void) puts(operators);
177 (void) printf(
"\nImage Sequence Operators:\n");
178 (void) puts(sequence_operators);
179 (void) printf(
"\nImage Stack Operators:\n");
180 (void) puts(stack_operators);
181 (void) printf(
"\nMiscellaneous Options:\n");
182 (void) puts(miscellaneous);
184 "\nBy default, the image format of `file' is determined by its magic\n");
186 "number. To specify a particular image format, precede the filename\n");
188 "with an image format name and a colon (i.e. ps:image) or specify the\n");
190 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
191 (void) printf(
"'-' for standard input or output.\n");
195WandExport MagickBooleanType CompareImageCommand(ImageInfo *image_info,
196 int argc,
char **argv,
char **metadata,ExceptionInfo *exception)
198#define CompareEpsilon (1.0e-06)
199#define CompareConstantColorException \
200 "subimage search metric is unreliable for constant-color images"
201#define CompareEqualSizedException \
202 "subimage search metric is unreliable for equal-sized images"
203#define DefaultDissimilarityThreshold (1.0/MagickPI)
204#define DefaultSimilarityThreshold (-1.0)
205#define DestroyCompare() \
207 if (similarity_image != (Image *) NULL) \
208 similarity_image=DestroyImageList(similarity_image); \
209 if (difference_image != (Image *) NULL) \
210 difference_image=DestroyImageList(difference_image); \
211 DestroyImageStack(); \
212 for (i=0; i < (ssize_t) argc; i++) \
213 argv[i]=DestroyString(argv[i]); \
214 argv=(char **) RelinquishMagickMemory(argv); \
216#define ThrowCompareException(asperity,tag,option) \
218 if (exception->severity < (asperity)) \
219 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag, \
222 return(MagickFalse); \
224#define ThrowCompareInvalidArgumentException(option,argument) \
226 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
227 "InvalidArgument","`%s': %s",option,argument); \
229 return(MagickFalse); \
243 dissimilarity_threshold,
245 scale = (double) QuantumRange,
247 similarity_threshold;
251 *image = (Image *) NULL,
259 image_stack[MaxImageStackDepth+1];
265 similar = MagickTrue,
287 assert(image_info != (ImageInfo *) NULL);
288 assert(image_info->signature == MagickCoreSignature);
289 assert(exception != (ExceptionInfo *) NULL);
290 if (IsEventLogging() != MagickFalse)
291 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
295 if ((LocaleCompare(
"version",option+1) == 0) ||
296 (LocaleCompare(
"-version",option+1) == 0))
298 ListMagickVersion(stdout);
304 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
305 "MissingArgument",
"%s",
"");
306 (void) CompareUsage();
309 restore_info=image_info;
310 channels=DefaultChannels;
311 difference_image=NewImageList();
312 similarity_image=NewImageList();
313 dissimilarity_threshold=DefaultDissimilarityThreshold;
314 similarity_threshold=DefaultSimilarityThreshold;
316 format=(
char *) NULL;
319 metric=UndefinedErrorMetric;
321 option=(
char *) NULL;
323 reconstruct_image=NewImageList();
324 respect_parenthesis=MagickFalse;
326 subimage_search=MagickFalse;
330 ReadCommandlLine(argc,&argv);
331 status=ExpandFilenames(&argc,&argv);
332 if (status == MagickFalse)
333 ThrowCompareException(ResourceLimitError,
"MemoryAllocationFailed",
334 GetExceptionMessage(errno));
335 for (i=1; i < (ssize_t) (argc-1); i++)
338 if (LocaleCompare(option,
"(") == 0)
340 FireImageStack(MagickTrue,MagickTrue,pend);
341 if (k == MaxImageStackDepth)
342 ThrowCompareException(OptionError,
"ParenthesisNestedTooDeeply",
347 if (LocaleCompare(option,
")") == 0)
349 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
351 ThrowCompareException(OptionError,
"UnableToParseExpression",option);
355 if (IsCommandOption(option) == MagickFalse)
363 FireImageStack(MagickFalse,MagickFalse,pend);
365 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
367 (void) SetImageOption(image_info,
"filename",filename);
368 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
369 images=ReadImages(image_info,exception);
370 status&=(images != (Image *) NULL) &&
371 (exception->severity < ErrorException);
372 if (images == (Image *) NULL)
374 AppendImageStack(images);
377 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
382 if (LocaleCompare(
"adjoin",option+1) == 0)
384 if (LocaleCompare(
"alpha",option+1) == 0)
392 if (i == (ssize_t) argc)
393 ThrowCompareException(OptionError,
"MissingArgument",option);
394 type=ParseCommandOption(MagickAlphaOptions,MagickFalse,argv[i]);
396 ThrowCompareException(OptionError,
"UnrecognizedAlphaChannelType",
400 if (LocaleCompare(
"authenticate",option+1) == 0)
405 if (i == (ssize_t) argc)
406 ThrowCompareException(OptionError,
"MissingArgument",option);
409 ThrowCompareException(OptionError,
"UnrecognizedOption",option);
413 if (LocaleCompare(
"background",option+1) == 0)
418 if (i == (ssize_t) argc)
419 ThrowCompareException(OptionError,
"MissingArgument",option);
422 if (LocaleCompare(
"brightness-contrast",option+1) == 0)
425 if (i == (ssize_t) argc)
426 ThrowCompareException(OptionError,
"MissingArgument",option);
427 if (IsGeometry(argv[i]) == MagickFalse)
428 ThrowCompareInvalidArgumentException(option,argv[i]);
431 ThrowCompareException(OptionError,
"UnrecognizedOption",option);
435 if (LocaleCompare(
"cache",option+1) == 0)
440 if (i == (ssize_t) argc)
441 ThrowCompareException(OptionError,
"MissingArgument",option);
442 if (IsGeometry(argv[i]) == MagickFalse)
443 ThrowCompareInvalidArgumentException(option,argv[i]);
446 if (LocaleCompare(
"channel",option+1) == 0)
454 if (i == (ssize_t) argc)
455 ThrowCompareException(OptionError,
"MissingArgument",option);
456 channel=ParseChannelOption(argv[i]);
458 ThrowCompareException(OptionError,
"UnrecognizedChannelType",
460 channels=(ChannelType) channel;
463 if (LocaleCompare(
"colorspace",option+1) == 0)
471 if (i == (ssize_t) argc)
472 ThrowCompareException(OptionError,
"MissingArgument",option);
473 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
476 ThrowCompareException(OptionError,
"UnrecognizedColorspace",
480 if (LocaleCompare(
"compose",option+1) == 0)
488 if (i == (ssize_t) argc)
489 ThrowCompareException(OptionError,
"MissingArgument",option);
490 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
493 ThrowCompareException(OptionError,
"UnrecognizedComposeOperator",
497 if (LocaleCompare(
"compress",option+1) == 0)
505 if (i == (ssize_t) argc)
506 ThrowCompareException(OptionError,
"MissingArgument",option);
507 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
510 ThrowCompareException(OptionError,
"UnrecognizedImageCompression",
514 if (LocaleCompare(
"concurrent",option+1) == 0)
516 if (LocaleCompare(
"crop",option+1) == 0)
521 if (i == (ssize_t) argc)
522 ThrowCompareException(OptionError,
"MissingArgument",option);
523 if (IsGeometry(argv[i]) == MagickFalse)
524 ThrowCompareInvalidArgumentException(option,argv[i]);
527 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
531 if (LocaleCompare(
"debug",option+1) == 0)
539 if (i == (ssize_t) argc)
540 ThrowCompareException(OptionError,
"MissingArgument",option);
541 event_mask=SetLogEventMask(argv[i]);
542 if (event_mask == UndefinedEvents)
543 ThrowCompareException(OptionError,
"UnrecognizedEventType",
547 if (LocaleCompare(
"decipher",option+1) == 0)
552 if (i == (ssize_t) argc)
553 ThrowCompareException(OptionError,
"MissingArgument",option);
556 if (LocaleCompare(
"define",option+1) == 0)
559 if (i == (ssize_t) argc)
560 ThrowCompareException(OptionError,
"MissingArgument",option);
566 define=GetImageOption(image_info,argv[i]);
567 if (define == (
const char *) NULL)
568 ThrowCompareException(OptionError,
"NoSuchOption",argv[i]);
573 if (LocaleCompare(
"delete",option+1) == 0)
578 if (i == (ssize_t) argc)
579 ThrowCompareException(OptionError,
"MissingArgument",option);
580 if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
581 ThrowCompareInvalidArgumentException(option,argv[i]);
584 if (LocaleCompare(
"density",option+1) == 0)
589 if (i == (ssize_t) argc)
590 ThrowCompareException(OptionError,
"MissingArgument",option);
591 if (IsGeometry(argv[i]) == MagickFalse)
592 ThrowCompareInvalidArgumentException(option,argv[i]);
595 if (LocaleCompare(
"depth",option+1) == 0)
600 if (i == (ssize_t) argc)
601 ThrowCompareException(OptionError,
"MissingArgument",option);
602 if (IsGeometry(argv[i]) == MagickFalse)
603 ThrowCompareInvalidArgumentException(option,argv[i]);
606 if (LocaleCompare(
"dissimilarity-threshold",option+1) == 0)
611 if (i == (ssize_t) argc)
612 ThrowCompareException(OptionError,
"MissingArgument",option);
613 if (IsGeometry(argv[i]) == MagickFalse)
614 ThrowCompareInvalidArgumentException(option,argv[i]);
616 dissimilarity_threshold=DefaultDissimilarityThreshold;
618 dissimilarity_threshold=StringToDouble(argv[i],(
char **) NULL);
621 if (LocaleCompare(
"distort",option+1) == 0)
627 if (i == (ssize_t) argc)
628 ThrowCompareException(OptionError,
"MissingArgument",option);
629 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
631 ThrowCompareException(OptionError,
"UnrecognizedDistortMethod",
634 if (i == (ssize_t) argc)
635 ThrowCompareException(OptionError,
"MissingArgument",option);
638 if (LocaleCompare(
"duration",option+1) == 0)
643 if (i == (ssize_t) argc)
644 ThrowCompareException(OptionError,
"MissingArgument",option);
645 if (IsGeometry(argv[i]) == MagickFalse)
646 ThrowCompareInvalidArgumentException(option,argv[i]);
649 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
653 if (LocaleCompare(
"encipher",option+1) == 0)
658 if (i == (ssize_t) argc)
659 ThrowCompareException(OptionError,
"MissingArgument",option);
662 if (LocaleCompare(
"extract",option+1) == 0)
667 if (i == (ssize_t) argc)
668 ThrowCompareException(OptionError,
"MissingArgument",option);
669 if (IsGeometry(argv[i]) == MagickFalse)
670 ThrowCompareInvalidArgumentException(option,argv[i]);
673 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
677 if (LocaleCompare(
"format",option+1) == 0)
682 if (i == (ssize_t) argc)
683 ThrowCompareException(OptionError,
"MissingArgument",option);
687 if (LocaleCompare(
"fuzz",option+1) == 0)
692 if (i == (ssize_t) argc)
693 ThrowCompareException(OptionError,
"MissingArgument",option);
694 if (IsGeometry(argv[i]) == MagickFalse)
695 ThrowCompareInvalidArgumentException(option,argv[i]);
698 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
702 if (LocaleCompare(
"gravity",option+1) == 0)
710 if (i == (ssize_t) argc)
711 ThrowCompareException(OptionError,
"MissingArgument",option);
712 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
715 ThrowCompareException(OptionError,
"UnrecognizedGravityType",
719 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
723 if ((LocaleCompare(
"help",option+1) == 0) ||
724 (LocaleCompare(
"-help",option+1) == 0))
727 return(CompareUsage());
729 if (LocaleCompare(
"highlight-color",option+1) == 0)
734 if (i == (ssize_t) argc)
735 ThrowCompareException(OptionError,
"MissingArgument",option);
738 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
742 if (LocaleCompare(
"identify",option+1) == 0)
744 if (LocaleCompare(
"interlace",option+1) == 0)
752 if (i == (ssize_t) argc)
753 ThrowCompareException(OptionError,
"MissingArgument",option);
754 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
757 ThrowCompareException(OptionError,
"UnrecognizedInterlaceType",
761 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
765 if (LocaleCompare(
"level",option+1) == 0)
768 if (i == (ssize_t) argc)
769 ThrowCompareException(OptionError,
"MissingArgument",option);
770 if (IsGeometry(argv[i]) == MagickFalse)
771 ThrowCompareInvalidArgumentException(option,argv[i]);
774 if (LocaleCompare(
"limit",option+1) == 0)
788 if (i == (ssize_t) argc)
789 ThrowCompareException(OptionError,
"MissingArgument",option);
790 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
793 ThrowCompareException(OptionError,
"UnrecognizedResourceType",
796 if (i == (ssize_t) argc)
797 ThrowCompareException(OptionError,
"MissingArgument",option);
798 value=StringToDouble(argv[i],&p);
800 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
801 ThrowCompareInvalidArgumentException(option,argv[i]);
804 if (LocaleCompare(
"list",option+1) == 0)
812 if (i == (ssize_t) argc)
813 ThrowCompareException(OptionError,
"MissingArgument",option);
814 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
816 ThrowCompareException(OptionError,
"UnrecognizedListType",argv[i]);
817 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
820 return(status == 0 ? MagickFalse : MagickTrue);
822 if (LocaleCompare(
"log",option+1) == 0)
827 if ((i == (ssize_t) argc) || (strchr(argv[i],
'%') == (
char *) NULL))
828 ThrowCompareException(OptionError,
"MissingArgument",option);
831 if (LocaleCompare(
"lowlight-color",option+1) == 0)
836 if (i == (ssize_t) argc)
837 ThrowCompareException(OptionError,
"MissingArgument",option);
840 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
844 if (LocaleCompare(
"mask",option+1) == 0)
849 if (i == (ssize_t) argc)
850 ThrowCompareException(OptionError,
"MissingArgument",option);
853 if (LocaleCompare(
"matte",option+1) == 0)
855 if (LocaleCompare(
"metric",option+1) == 0)
863 if (i == (ssize_t) argc)
864 ThrowCompareException(OptionError,
"MissingArgument",option);
865 type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
867 ThrowCompareException(OptionError,
"UnrecognizedMetricType",
869 metric=(MetricType) type;
872 if (LocaleCompare(
"monitor",option+1) == 0)
874 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
878 if (LocaleCompare(
"precision",option+1) == 0)
883 if (i == (ssize_t) argc)
884 ThrowCompareException(OptionError,
"MissingArgument",option);
885 if (IsGeometry(argv[i]) == MagickFalse)
886 ThrowCompareInvalidArgumentException(option,argv[i]);
889 if (LocaleCompare(
"passphrase",option+1) == 0)
894 if (i == (ssize_t) argc)
895 ThrowCompareException(OptionError,
"MissingArgument",option);
898 if (LocaleCompare(
"profile",option+1) == 0)
901 if (i == (ssize_t) argc)
902 ThrowCompareException(OptionError,
"MissingArgument",option);
905 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
909 if (LocaleCompare(
"quality",option+1) == 0)
914 if (i == (ssize_t) argc)
915 ThrowCompareException(OptionError,
"MissingArgument",option);
916 if (IsGeometry(argv[i]) == MagickFalse)
917 ThrowCompareInvalidArgumentException(option,argv[i]);
920 if (LocaleCompare(
"quantize",option+1) == 0)
928 if (i == (ssize_t) argc)
929 ThrowCompareException(OptionError,
"MissingArgument",option);
930 colorspace=ParseCommandOption(MagickColorspaceOptions,
931 MagickFalse,argv[i]);
933 ThrowCompareException(OptionError,
"UnrecognizedColorspace",
937 if (LocaleCompare(
"quiet",option+1) == 0)
939 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
943 if (LocaleCompare(
"regard-warnings",option+1) == 0)
945 if (LocaleCompare(
"repage",option+1) == 0)
950 if (i == (ssize_t) argc)
951 ThrowCompareException(OptionError,
"MissingArgument",option);
952 if (IsGeometry(argv[i]) == MagickFalse)
953 ThrowCompareInvalidArgumentException(option,argv[i]);
956 if (LocaleCompare(
"resize",option+1) == 0)
961 if (i == (ssize_t) argc)
962 ThrowCompareException(OptionError,
"MissingArgument",option);
963 if (IsGeometry(argv[i]) == MagickFalse)
964 ThrowCompareInvalidArgumentException(option,argv[i]);
967 if (LocaleCompare(
"rotate",option+1) == 0)
970 if (i == (ssize_t) argc)
971 ThrowCompareException(OptionError,
"MissingArgument",option);
972 if (IsGeometry(argv[i]) == MagickFalse)
973 ThrowCompareInvalidArgumentException(option,argv[i]);
976 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
978 respect_parenthesis=(*option ==
'-') ? MagickTrue : MagickFalse;
981 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
985 if (LocaleCompare(
"sampling-factor",option+1) == 0)
990 if (i == (ssize_t) argc)
991 ThrowCompareException(OptionError,
"MissingArgument",option);
992 if (IsGeometry(argv[i]) == MagickFalse)
993 ThrowCompareInvalidArgumentException(option,argv[i]);
996 if (LocaleCompare(
"seed",option+1) == 0)
1001 if (i == (ssize_t) argc)
1002 ThrowCompareException(OptionError,
"MissingArgument",option);
1003 if (IsGeometry(argv[i]) == MagickFalse)
1004 ThrowCompareInvalidArgumentException(option,argv[i]);
1007 if (LocaleCompare(
"separate",option+1) == 0)
1009 if (LocaleCompare(
"set",option+1) == 0)
1012 if (i == (ssize_t) argc)
1013 ThrowCompareException(OptionError,
"MissingArgument",option);
1017 if (i == (ssize_t) argc)
1018 ThrowCompareException(OptionError,
"MissingArgument",option);
1021 if (LocaleCompare(
"sigmoidal-contrast",option+1) == 0)
1024 if (i == (ssize_t) argc)
1025 ThrowCompareException(OptionError,
"MissingArgument",option);
1026 if (IsGeometry(argv[i]) == MagickFalse)
1027 ThrowCompareInvalidArgumentException(option,argv[i]);
1030 if (LocaleCompare(
"similarity-threshold",option+1) == 0)
1035 if (i == (ssize_t) argc)
1036 ThrowCompareException(OptionError,
"MissingArgument",option);
1037 if (IsGeometry(argv[i]) == MagickFalse)
1038 ThrowCompareInvalidArgumentException(option,argv[i]);
1040 similarity_threshold=DefaultSimilarityThreshold;
1042 similarity_threshold=StringToDouble(argv[i],(
char **) NULL);
1045 if (LocaleCompare(
"size",option+1) == 0)
1050 if (i == (ssize_t) argc)
1051 ThrowCompareException(OptionError,
"MissingArgument",option);
1052 if (IsGeometry(argv[i]) == MagickFalse)
1053 ThrowCompareInvalidArgumentException(option,argv[i]);
1056 if (LocaleCompare(
"subimage-search",option+1) == 0)
1060 subimage_search=MagickFalse;
1063 subimage_search=MagickTrue;
1066 if (LocaleCompare(
"synchronize",option+1) == 0)
1068 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1072 if (LocaleCompare(
"taint",option+1) == 0)
1074 if (LocaleCompare(
"transparent-color",option+1) == 0)
1079 if (i == (ssize_t) argc)
1080 ThrowCompareException(OptionError,
"MissingArgument",option);
1083 if (LocaleCompare(
"trim",option+1) == 0)
1085 if (LocaleCompare(
"type",option+1) == 0)
1093 if (i == (ssize_t) argc)
1094 ThrowCompareException(OptionError,
"MissingArgument",option);
1095 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1097 ThrowCompareException(OptionError,
"UnrecognizedImageType",
1101 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1105 if (LocaleCompare(
"verbose",option+1) == 0)
1107 if ((LocaleCompare(
"version",option+1) == 0) ||
1108 (LocaleCompare(
"-version",option+1) == 0))
1110 ListMagickVersion(stdout);
1113 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
1121 if (i == (ssize_t) argc)
1122 ThrowCompareException(OptionError,
"MissingArgument",option);
1123 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1126 ThrowCompareException(OptionError,
1127 "UnrecognizedVirtualPixelMethod",argv[i]);
1130 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1134 if (LocaleCompare(
"write",option+1) == 0)
1137 if (i == (ssize_t) argc)
1138 ThrowCompareException(OptionError,
"MissingArgument",option);
1141 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1146 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1148 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1149 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1150 if (fire != MagickFalse)
1151 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
1154 ThrowCompareException(OptionError,
"UnbalancedParenthesis",argv[i]);
1155 if (i-- != (ssize_t) (argc-1))
1156 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1157 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1158 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1159 FinalizeImageSettings(image_info,image,MagickTrue);
1160 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1161 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1162 image=GetImageFromList(image,0);
1163 reconstruct_image=GetImageFromList(image,1);
1166 if (subimage_search != MagickFalse)
1169 artifact[MaxTextExtent];
1171 (void) FormatLocaleString(artifact,MaxTextExtent,
"%g",
1172 similarity_threshold);
1173 (void) SetImageArtifact(image,
"compare:similarity-threshold",artifact);
1174 similarity_image=SimilarityMetricImage(image,reconstruct_image,metric,
1175 &offset,&similarity_metric,exception);
1176 if (similarity_metric > dissimilarity_threshold)
1177 (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning,
1178 "ImagesTooDissimilar",
"`%s'",image->filename);
1180 if (similarity_image == (Image *) NULL)
1181 difference_image=CompareImageChannels(image,reconstruct_image,channels,
1182 metric,&distortion,exception);
1191 composite_image=CloneImage(image,0,0,MagickTrue,exception);
1192 if (composite_image == (Image *) NULL)
1193 difference_image=CompareImageChannels(image,reconstruct_image,
1194 channels,metric,&distortion,exception);
1203 (void) CompositeImage(composite_image,CopyCompositeOp,
1204 reconstruct_image,offset.x,offset.y);
1205 difference_image=CompareImageChannels(image,composite_image,
1206 channels,metric,&distortion,exception);
1207 if (difference_image != (Image *) NULL)
1209 difference_image->page.x=offset.x;
1210 difference_image->page.y=offset.y;
1212 composite_image=DestroyImage(composite_image);
1213 page.width=reconstruct_image->columns;
1214 page.height=reconstruct_image->rows;
1217 distort_image=CropImage(image,&page,exception);
1218 if (distort_image != (Image *) NULL)
1223 sans_image=CompareImageChannels(distort_image,reconstruct_image,
1224 channels,metric,&distortion,exception);
1225 distort_image=DestroyImage(distort_image);
1226 if (sans_image != (Image *) NULL)
1227 sans_image=DestroyImage(sans_image);
1230 if (difference_image != (Image *) NULL)
1232 AppendImageToList(&difference_image,similarity_image);
1233 similarity_image=(Image *) NULL;
1236 if (fabs(distortion) > CompareEpsilon)
1237 similar=MagickFalse;
1240 case AbsoluteErrorMetric:
1242 scale=(double) image->columns*image->rows;
1245 case NormalizedCrossCorrelationErrorMetric:
1251 (void) GetImageRange(reconstruct_image,&minima,&maxima,exception);
1252 if (((subimage_search != MagickFalse) &&
1253 (image->columns == reconstruct_image->columns) &&
1254 (image->rows == reconstruct_image->rows)) &&
1255 (fabs(maxima-minima) < MagickEpsilon))
1256 (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning,
1257 CompareConstantColorException,
"(%s)",CommandOptionToMnemonic(
1258 MagickMetricOptions,(ssize_t) metric));
1259 if (distortion == INFINITY)
1261 distortion=1.0-distortion;
1262 similarity_metric=1.0-similarity_metric;
1265 case PerceptualHashErrorMetric:
1267 if ((subimage_search != MagickFalse) &&
1268 (image->columns == reconstruct_image->columns) &&
1269 (image->rows == reconstruct_image->rows))
1270 (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning,
1271 CompareEqualSizedException,
"(%s)",CommandOptionToMnemonic(
1272 MagickMetricOptions,(ssize_t) metric));
1275 case PeakAbsoluteErrorMetric:
1277 if ((subimage_search != MagickFalse) &&
1278 (image->columns == reconstruct_image->columns) &&
1279 (image->rows == reconstruct_image->rows))
1280 (void) ThrowMagickException(exception,GetMagickModule(),ImageWarning,
1281 CompareEqualSizedException,
"(%s)",CommandOptionToMnemonic(
1282 MagickMetricOptions,(ssize_t) metric));
1285 case PeakSignalToNoiseRatioMetric:
1287 scale=MagickPSNRDistortion;
1293 if (difference_image == (Image *) NULL)
1297 if (image_info->verbose != MagickFalse)
1298 (void) IsImagesEqual(image,reconstruct_image);
1299 if (*difference_image->magick ==
'\0')
1300 (void) CopyMagickString(difference_image->magick,image->magick,
1302 if (image_info->verbose == MagickFalse)
1306 case MeanErrorPerPixelMetric:
1308 (void) FormatLocaleFile(stderr,
"%.*g (%.*g, %.*g)",
1309 GetMagickPrecision(),QuantumRange*distortion,
1310 GetMagickPrecision(),image->error.normalized_mean_error,
1311 GetMagickPrecision(),image->error.normalized_maximum_error);
1316 (void) FormatLocaleFile(stderr,
"%.*g (%.*g)",GetMagickPrecision(),
1317 scale*distortion,GetMagickPrecision(),distortion);
1321 if (subimage_search != MagickFalse)
1322 (void) FormatLocaleFile(stderr,
" @ %.20g,%.20g [%.*g]",
1323 (
double) offset.x,(
double) offset.y,GetMagickPrecision(),
1329 *channel_distortion;
1331 channel_distortion=GetImageChannelDistortions(image,reconstruct_image,
1332 metric,&image->exception);
1333 (void) FormatLocaleFile(stderr,
"Image: %s\n",image->filename);
1334 if ((reconstruct_image->columns != image->columns) ||
1335 (reconstruct_image->rows != image->rows))
1336 (void) FormatLocaleFile(stderr,
"Offset: %.20g,%.20g\n",(
double)
1337 difference_image->page.x,(
double) difference_image->page.y);
1338 (void) FormatLocaleFile(stderr,
" Channel distortion: %s\n",
1339 CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
1342 case FuzzErrorMetric:
1343 case MeanAbsoluteErrorMetric:
1344 case MeanSquaredErrorMetric:
1345 case PeakAbsoluteErrorMetric:
1346 case RootMeanSquaredErrorMetric:
1348 switch (image->colorspace)
1353 (void) FormatLocaleFile(stderr,
" red: %.*g (%.*g)\n",
1354 GetMagickPrecision(),scale*channel_distortion[RedChannel],
1355 GetMagickPrecision(),channel_distortion[RedChannel]);
1356 (void) FormatLocaleFile(stderr,
" green: %.*g (%.*g)\n",
1357 GetMagickPrecision(),scale*channel_distortion[GreenChannel],
1358 GetMagickPrecision(),channel_distortion[GreenChannel]);
1359 (void) FormatLocaleFile(stderr,
" blue: %.*g (%.*g)\n",
1360 GetMagickPrecision(),scale*channel_distortion[BlueChannel],
1361 GetMagickPrecision(),channel_distortion[BlueChannel]);
1362 if (image->matte != MagickFalse)
1363 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1364 GetMagickPrecision(),scale*channel_distortion[OpacityChannel],
1365 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1368 case CMYKColorspace:
1370 (void) FormatLocaleFile(stderr,
" cyan: %.*g (%.*g)\n",
1371 GetMagickPrecision(),scale*channel_distortion[CyanChannel],
1372 GetMagickPrecision(),channel_distortion[CyanChannel]);
1373 (void) FormatLocaleFile(stderr,
" magenta: %.*g (%.*g)\n",
1374 GetMagickPrecision(),scale*channel_distortion[MagentaChannel],
1375 GetMagickPrecision(),channel_distortion[MagentaChannel]);
1376 (void) FormatLocaleFile(stderr,
" yellow: %.*g (%.*g)\n",
1377 GetMagickPrecision(),scale*channel_distortion[YellowChannel],
1378 GetMagickPrecision(),channel_distortion[YellowChannel]);
1379 (void) FormatLocaleFile(stderr,
" black: %.*g (%.*g)\n",
1380 GetMagickPrecision(),scale*channel_distortion[BlackChannel],
1381 GetMagickPrecision(),channel_distortion[BlackChannel]);
1382 if (image->matte != MagickFalse)
1383 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1384 GetMagickPrecision(),scale*channel_distortion[OpacityChannel],
1385 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1388 case LinearGRAYColorspace:
1389 case GRAYColorspace:
1391 (void) FormatLocaleFile(stderr,
" gray: %.*g (%.*g)\n",
1392 GetMagickPrecision(),scale*channel_distortion[GrayChannel],
1393 GetMagickPrecision(),channel_distortion[GrayChannel]);
1394 if (image->matte != MagickFalse)
1395 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1396 GetMagickPrecision(),scale*channel_distortion[OpacityChannel],
1397 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1401 (void) FormatLocaleFile(stderr,
" all: %.*g (%.*g)\n",
1402 GetMagickPrecision(),scale*channel_distortion[CompositeChannels],
1403 GetMagickPrecision(),channel_distortion[CompositeChannels]);
1406 case AbsoluteErrorMetric:
1407 case NormalizedCrossCorrelationErrorMetric:
1408 case PeakSignalToNoiseRatioMetric:
1409 case PerceptualHashErrorMetric:
1411 switch (image->colorspace)
1416 (void) FormatLocaleFile(stderr,
" red: %.*g\n",
1417 GetMagickPrecision(),channel_distortion[RedChannel]);
1418 (void) FormatLocaleFile(stderr,
" green: %.*g\n",
1419 GetMagickPrecision(),channel_distortion[GreenChannel]);
1420 (void) FormatLocaleFile(stderr,
" blue: %.*g\n",
1421 GetMagickPrecision(),channel_distortion[BlueChannel]);
1422 if (image->matte != MagickFalse)
1423 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1424 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1427 case CMYKColorspace:
1429 (void) FormatLocaleFile(stderr,
" cyan: %.*g\n",
1430 GetMagickPrecision(),channel_distortion[CyanChannel]);
1431 (void) FormatLocaleFile(stderr,
" magenta: %.*g\n",
1432 GetMagickPrecision(),channel_distortion[MagentaChannel]);
1433 (void) FormatLocaleFile(stderr,
" yellow: %.*g\n",
1434 GetMagickPrecision(),channel_distortion[YellowChannel]);
1435 (void) FormatLocaleFile(stderr,
" black: %.*g\n",
1436 GetMagickPrecision(),channel_distortion[BlackChannel]);
1437 if (image->matte != MagickFalse)
1438 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1439 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1442 case LinearGRAYColorspace:
1443 case GRAYColorspace:
1445 (void) FormatLocaleFile(stderr,
" gray: %.*g\n",
1446 GetMagickPrecision(),channel_distortion[GrayChannel]);
1447 if (image->matte != MagickFalse)
1448 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1449 GetMagickPrecision(),channel_distortion[OpacityChannel]);
1453 (void) FormatLocaleFile(stderr,
" all: %.*g\n",
1454 GetMagickPrecision(),channel_distortion[CompositeChannels]);
1457 case MeanErrorPerPixelMetric:
1459 (void) FormatLocaleFile(stderr,
" %.*g (%.*g, %.*g)\n",
1460 GetMagickPrecision(),channel_distortion[CompositeChannels],
1461 GetMagickPrecision(),image->error.normalized_mean_error,
1462 GetMagickPrecision(),image->error.normalized_maximum_error);
1465 case UndefinedErrorMetric:
1468 channel_distortion=(
double *) RelinquishMagickMemory(
1469 channel_distortion);
1470 if (subimage_search != MagickFalse)
1472 (void) FormatLocaleFile(stderr,
" Offset: %.20g,%.20g\n",
1473 (
double) difference_image->page.x,(
double)
1474 difference_image->page.y);
1475 (void) FormatLocaleFile(stderr,
" Similarity metric: %.*g\n",
1476 GetMagickPrecision(),similarity_metric);
1479 (void) ResetImagePage(difference_image,
"0x0+0+0");
1480 if (difference_image->next != (Image *) NULL)
1481 (void) ResetImagePage(difference_image->next,
"0x0+0+0");
1482 status&=WriteImages(image_info,difference_image,argv[argc-1],exception);
1483 if ((metadata != (
char **) NULL) && (format != (
char *) NULL))
1488 text=InterpretImageProperties(image_info,difference_image,format);
1489 InheritException(exception,&image->exception);
1490 if (text == (
char *) NULL)
1491 ThrowCompareException(ResourceLimitError,
"MemoryAllocationFailed",
1492 GetExceptionMessage(errno));
1493 (void) ConcatenateString(&(*metadata),text);
1494 text=DestroyString(text);
1496 difference_image=DestroyImageList(difference_image);
1499 image_info=restore_info;
1500 if (similar == MagickFalse)
1501 (void) SetImageOption(image_info,
"compare:dissimilar",
"true");
1502 return(status != 0 ? MagickTrue : MagickFalse);