44#include "MagickWand/studio.h"
45#include "MagickWand/MagickWand.h"
46#include "MagickWand/mogrify-private.h"
47#include "MagickCore/string-private.h"
83static MagickBooleanType CompareUsage(
void)
87 " -separate separate an image channel into a grayscale image",
89 " -channel mask set the image channel mask\n"
90 " -debug events display copious debugging information\n"
91 " -help print program options\n"
92 " -list type print a list of supported option arguments\n"
93 " -log format format of debugging information",
95 " -auto-orient automagically orient (rotate) image\n"
96 " -brightness-contrast geometry\n"
97 " improve brightness / contrast of the image\n"
98 " -distort method args\n"
99 " distort images according to given method and args\n"
100 " -level value adjust the level of image contrast\n"
101 " -resize geometry resize the image\n"
102 " -rotate degrees apply Paeth rotation to the image\n"
103 " -sigmoidal-contrast geometry\n"
104 " increase the contrast without saturating highlights or\n"
105 " -trim trim image edges\n"
106 " -write filename write images to this file",
107 sequence_operators[] =
108 " -crop geometry cut out a rectangular region of the image",
110 " -alpha option on, activate, off, deactivate, set, opaque, copy\n"
111 " transparent, extract, background, or shape\n"
112 " -authenticate password\n"
113 " decipher image with this password\n"
114 " -background color background color\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 " -metric type measure differences between images with this metric\n"
138 " -monitor monitor progress\n"
139 " -negate replace every pixel with its complementary color \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 " -read-mask filename associate a read mask with the image\n"
147 " -regard-warnings pay attention to warning messages\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 " -repage geometry size and location of an image canvas\n"
155 " -similarity-threshold value\n"
156 " minimum distortion for (sub)image match\n"
157 " -size geometry width and height of image\n"
158 " -subimage-search search for subimage\n"
159 " -synchronize synchronize image to storage device\n"
160 " -taint declare the image as modified\n"
161 " -transparent-color color\n"
162 " transparent color\n"
163 " -type type image type\n"
164 " -verbose print detailed information about the image\n"
165 " -version print version information\n"
166 " -virtual-pixel method\n"
167 " virtual pixel access method\n"
168 " -write-mask filename associate a write mask with the image",
170 " -delete indexes delete the image from the image sequence";
172 ListMagickVersion(stdout);
173 (void) printf(
"Usage: %s [options ...] image reconstruct difference\n",
175 (void) printf(
"\nImage Settings:\n");
176 (void) puts(settings);
177 (void) printf(
"\nImage Operators:\n");
178 (void) puts(operators);
179 (void) printf(
"\nImage Channel Operators:\n");
180 (void) puts(channel_operators);
181 (void) printf(
"\nImage Sequence Operators:\n");
182 (void) puts(sequence_operators);
183 (void) printf(
"\nImage Stack Operators:\n");
184 (void) puts(stack_operators);
185 (void) printf(
"\nMiscellaneous Options:\n");
186 (void) puts(miscellaneous);
188 "\nBy default, the image format of 'file' is determined by its magic\n");
190 "number. To specify a particular image format, precede the filename\n");
192 "with an image format name and a colon (i.e. ps:image) or specify the\n");
194 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
195 (void) printf(
"'-' for standard input or output.\n");
199WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
200 int argc,
char **argv,
char **metadata,ExceptionInfo *exception)
202#define CompareEpsilon (1.0e-06)
203#define DefaultDissimilarityThreshold 0.31830988618379067154
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); \
240 dissimilarity_threshold,
243 similarity_threshold;
247 *image = (Image *) NULL,
252 image_stack[MaxImageStackDepth+1];
279 assert(image_info != (ImageInfo *) NULL);
280 assert(image_info->signature == MagickCoreSignature);
281 assert(exception != (ExceptionInfo *) NULL);
282 if (IsEventLogging() != MagickFalse)
283 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
287 if ((LocaleCompare(
"version",option+1) == 0) ||
288 (LocaleCompare(
"-version",option+1) == 0))
290 ListMagickVersion(stdout);
296 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
297 "MissingArgument",
"%s",
"");
298 (void) CompareUsage();
301 difference_image=NewImageList();
302 similarity_image=NewImageList();
303 dissimilarity_threshold=DefaultDissimilarityThreshold;
304 similarity_threshold=DefaultSimilarityThreshold;
306 format=(
char *) NULL;
309 metric=UndefinedErrorMetric;
311 option=(
char *) NULL;
313 reconstruct_image=NewImageList();
314 respect_parentheses=MagickFalse;
316 subimage_search=MagickFalse;
320 ReadCommandlLine(argc,&argv);
321 status=ExpandFilenames(&argc,&argv);
322 if (status == MagickFalse)
323 ThrowCompareException(ResourceLimitError,
"MemoryAllocationFailed",
324 GetExceptionMessage(errno));
325 for (i=1; i < (ssize_t) (argc-1); i++)
328 if (LocaleCompare(option,
"(") == 0)
330 FireImageStack(MagickTrue,MagickTrue,pend);
331 if (k == MaxImageStackDepth)
332 ThrowCompareException(OptionError,
"ParenthesisNestedTooDeeply",
337 if (LocaleCompare(option,
")") == 0)
339 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
341 ThrowCompareException(OptionError,
"UnableToParseExpression",option);
345 if (IsCommandOption(option) == MagickFalse)
353 FireImageStack(MagickFalse,MagickFalse,pend);
355 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
357 images=ReadImages(image_info,filename,exception);
358 status&=(MagickStatusType) (images != (Image *) NULL) &&
359 (exception->severity < ErrorException);
360 if (images == (Image *) NULL)
362 AppendImageStack(images);
365 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
370 if (LocaleCompare(
"alpha",option+1) == 0)
378 if (i == (ssize_t) argc)
379 ThrowCompareException(OptionError,
"MissingArgument",option);
380 type=ParseCommandOption(MagickAlphaChannelOptions,MagickFalse,
383 ThrowCompareException(OptionError,
384 "UnrecognizedAlphaChannelOption",argv[i]);
387 if (LocaleCompare(
"auto-orient",option+1) == 0)
389 if (LocaleCompare(
"authenticate",option+1) == 0)
394 if (i == (ssize_t) argc)
395 ThrowCompareException(OptionError,
"MissingArgument",option);
398 ThrowCompareException(OptionError,
"UnrecognizedOption",option);
402 if (LocaleCompare(
"background",option+1) == 0)
407 if (i == (ssize_t) argc)
408 ThrowCompareException(OptionError,
"MissingArgument",option);
411 if (LocaleCompare(
"brightness-contrast",option+1) == 0)
414 if (i == (ssize_t) argc)
415 ThrowCompareException(OptionError,
"MissingArgument",option);
416 if (IsGeometry(argv[i]) == MagickFalse)
417 ThrowCompareInvalidArgumentException(option,argv[i]);
420 ThrowCompareException(OptionError,
"UnrecognizedOption",option);
424 if (LocaleCompare(
"cache",option+1) == 0)
429 if (i == (ssize_t) argc)
430 ThrowCompareException(OptionError,
"MissingArgument",option);
431 if (IsGeometry(argv[i]) == MagickFalse)
432 ThrowCompareInvalidArgumentException(option,argv[i]);
435 if (LocaleCompare(
"channel",option+1) == 0)
443 if (i == (ssize_t) argc)
444 ThrowCompareException(OptionError,
"MissingArgument",option);
445 channel=ParseChannelOption(argv[i]);
447 ThrowCompareException(OptionError,
"UnrecognizedChannelType",
451 if (LocaleCompare(
"colorspace",option+1) == 0)
459 if (i == (ssize_t) argc)
460 ThrowCompareException(OptionError,
"MissingArgument",option);
461 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
464 ThrowCompareException(OptionError,
"UnrecognizedColorspace",
468 if (LocaleCompare(
"compose",option+1) == 0)
476 if (i == (ssize_t) argc)
477 ThrowCompareException(OptionError,
"MissingArgument",option);
478 compose=ParseCommandOption(MagickComposeOptions,MagickFalse,
481 ThrowCompareException(OptionError,
"UnrecognizedComposeOperator",
485 if (LocaleCompare(
"compress",option+1) == 0)
493 if (i == (ssize_t) argc)
494 ThrowCompareException(OptionError,
"MissingArgument",option);
495 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
498 ThrowCompareException(OptionError,
"UnrecognizedImageCompression",
502 if (LocaleCompare(
"concurrent",option+1) == 0)
504 if (LocaleCompare(
"crop",option+1) == 0)
509 if (i == (ssize_t) argc)
510 ThrowCompareException(OptionError,
"MissingArgument",option);
511 if (IsGeometry(argv[i]) == MagickFalse)
512 ThrowCompareInvalidArgumentException(option,argv[i]);
515 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
519 if (LocaleCompare(
"debug",option+1) == 0)
527 if (i == (ssize_t) argc)
528 ThrowCompareException(OptionError,
"MissingArgument",option);
529 event_mask=SetLogEventMask(argv[i]);
530 if (event_mask == UndefinedEvents)
531 ThrowCompareException(OptionError,
"UnrecognizedEventType",
535 if (LocaleCompare(
"decipher",option+1) == 0)
540 if (i == (ssize_t) argc)
541 ThrowCompareException(OptionError,
"MissingArgument",option);
544 if (LocaleCompare(
"define",option+1) == 0)
547 if (i == (ssize_t) argc)
548 ThrowCompareException(OptionError,
"MissingArgument",option);
554 define=GetImageOption(image_info,argv[i]);
555 if (define == (
const char *) NULL)
556 ThrowCompareException(OptionError,
"NoSuchOption",argv[i]);
561 if (LocaleCompare(
"delete",option+1) == 0)
566 if (i == (ssize_t) argc)
567 ThrowCompareException(OptionError,
"MissingArgument",option);
568 if (IsSceneGeometry(argv[i],MagickFalse) == MagickFalse)
569 ThrowCompareInvalidArgumentException(option,argv[i]);
572 if (LocaleCompare(
"density",option+1) == 0)
577 if (i == (ssize_t) argc)
578 ThrowCompareException(OptionError,
"MissingArgument",option);
579 if (IsGeometry(argv[i]) == MagickFalse)
580 ThrowCompareInvalidArgumentException(option,argv[i]);
583 if (LocaleCompare(
"depth",option+1) == 0)
588 if (i == (ssize_t) argc)
589 ThrowCompareException(OptionError,
"MissingArgument",option);
590 if (IsGeometry(argv[i]) == MagickFalse)
591 ThrowCompareInvalidArgumentException(option,argv[i]);
594 if (LocaleCompare(
"dissimilarity-threshold",option+1) == 0)
599 if (i == (ssize_t) argc)
600 ThrowCompareException(OptionError,
"MissingArgument",option);
601 if (IsGeometry(argv[i]) == MagickFalse)
602 ThrowCompareInvalidArgumentException(option,argv[i]);
604 dissimilarity_threshold=DefaultDissimilarityThreshold;
606 dissimilarity_threshold=StringToDouble(argv[i],(
char **) NULL);
609 if (LocaleCompare(
"distort",option+1) == 0)
615 if (i == (ssize_t) argc)
616 ThrowCompareException(OptionError,
"MissingArgument",option);
617 op=ParseCommandOption(MagickDistortOptions,MagickFalse,argv[i]);
619 ThrowCompareException(OptionError,
"UnrecognizedDistortMethod",
622 if (i == (ssize_t) argc)
623 ThrowCompareException(OptionError,
"MissingArgument",option);
626 if (LocaleCompare(
"duration",option+1) == 0)
631 if (i == (ssize_t) argc)
632 ThrowCompareException(OptionError,
"MissingArgument",option);
633 if (IsGeometry(argv[i]) == MagickFalse)
634 ThrowCompareInvalidArgumentException(option,argv[i]);
637 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
641 if (LocaleCompare(
"encipher",option+1) == 0)
646 if (i == (ssize_t) argc)
647 ThrowCompareException(OptionError,
"MissingArgument",option);
650 if (LocaleCompare(
"extract",option+1) == 0)
655 if (i == (ssize_t) argc)
656 ThrowCompareException(OptionError,
"MissingArgument",option);
657 if (IsGeometry(argv[i]) == MagickFalse)
658 ThrowCompareInvalidArgumentException(option,argv[i]);
661 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
665 if (LocaleCompare(
"format",option+1) == 0)
670 if (i == (ssize_t) argc)
671 ThrowCompareException(OptionError,
"MissingArgument",option);
675 if (LocaleCompare(
"fuzz",option+1) == 0)
680 if (i == (ssize_t) argc)
681 ThrowCompareException(OptionError,
"MissingArgument",option);
682 if (IsGeometry(argv[i]) == MagickFalse)
683 ThrowCompareInvalidArgumentException(option,argv[i]);
686 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
690 if (LocaleCompare(
"gravity",option+1) == 0)
698 if (i == (ssize_t) argc)
699 ThrowCompareException(OptionError,
"MissingArgument",option);
700 gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,
703 ThrowCompareException(OptionError,
"UnrecognizedGravityType",
707 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
711 if ((LocaleCompare(
"help",option+1) == 0) ||
712 (LocaleCompare(
"-help",option+1) == 0))
715 return(CompareUsage());
717 if (LocaleCompare(
"highlight-color",option+1) == 0)
722 if (i == (ssize_t) argc)
723 ThrowCompareException(OptionError,
"MissingArgument",option);
726 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
730 if (LocaleCompare(
"identify",option+1) == 0)
732 if (LocaleCompare(
"interlace",option+1) == 0)
740 if (i == (ssize_t) argc)
741 ThrowCompareException(OptionError,
"MissingArgument",option);
742 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
745 ThrowCompareException(OptionError,
"UnrecognizedInterlaceType",
749 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
753 if (LocaleCompare(
"level",option+1) == 0)
756 if (i == (ssize_t) argc)
757 ThrowCompareException(OptionError,
"MissingArgument",option);
758 if (IsGeometry(argv[i]) == MagickFalse)
759 ThrowCompareInvalidArgumentException(option,argv[i]);
762 if (LocaleCompare(
"limit",option+1) == 0)
776 if (i == (ssize_t) argc)
777 ThrowCompareException(OptionError,
"MissingArgument",option);
778 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
781 ThrowCompareException(OptionError,
"UnrecognizedResourceType",
784 if (i == (ssize_t) argc)
785 ThrowCompareException(OptionError,
"MissingArgument",option);
786 value=StringToDouble(argv[i],&p);
788 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
789 ThrowCompareInvalidArgumentException(option,argv[i]);
792 if (LocaleCompare(
"list",option+1) == 0)
800 if (i == (ssize_t) argc)
801 ThrowCompareException(OptionError,
"MissingArgument",option);
802 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
804 ThrowCompareException(OptionError,
"UnrecognizedListType",argv[i]);
805 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
808 return(status == 0 ? MagickFalse : MagickTrue);
810 if (LocaleCompare(
"log",option+1) == 0)
815 if ((i == (ssize_t) argc) || (strchr(argv[i],
'%') == (
char *) NULL))
816 ThrowCompareException(OptionError,
"MissingArgument",option);
819 if (LocaleCompare(
"lowlight-color",option+1) == 0)
824 if (i == (ssize_t) argc)
825 ThrowCompareException(OptionError,
"MissingArgument",option);
828 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
832 if (LocaleCompare(
"matte",option+1) == 0)
834 if (LocaleCompare(
"metric",option+1) == 0)
842 if (i == (ssize_t) argc)
843 ThrowCompareException(OptionError,
"MissingArgument",option);
844 type=ParseCommandOption(MagickMetricOptions,MagickTrue,argv[i]);
846 ThrowCompareException(OptionError,
"UnrecognizedMetricType",
848 metric=(MetricType) type;
851 if (LocaleCompare(
"monitor",option+1) == 0)
853 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
857 if (LocaleCompare(
"negate",option+1) == 0)
859 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
863 if (LocaleCompare(
"passphrase",option+1) == 0)
868 if (i == (ssize_t) argc)
869 ThrowCompareException(OptionError,
"MissingArgument",option);
872 if (LocaleCompare(
"precision",option+1) == 0)
877 if (i == (ssize_t) argc)
878 ThrowCompareException(OptionError,
"MissingArgument",option);
879 if (IsGeometry(argv[i]) == MagickFalse)
880 ThrowCompareInvalidArgumentException(option,argv[i]);
883 if (LocaleCompare(
"profile",option+1) == 0)
886 if (i == (ssize_t) argc)
887 ThrowCompareException(OptionError,
"MissingArgument",option);
890 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
894 if (LocaleCompare(
"quality",option+1) == 0)
899 if (i == (ssize_t) argc)
900 ThrowCompareException(OptionError,
"MissingArgument",option);
901 if (IsGeometry(argv[i]) == MagickFalse)
902 ThrowCompareInvalidArgumentException(option,argv[i]);
905 if (LocaleCompare(
"quantize",option+1) == 0)
913 if (i == (ssize_t) argc)
914 ThrowCompareException(OptionError,
"MissingArgument",option);
915 colorspace=ParseCommandOption(MagickColorspaceOptions,
916 MagickFalse,argv[i]);
918 ThrowCompareException(OptionError,
"UnrecognizedColorspace",
922 if (LocaleCompare(
"quiet",option+1) == 0)
924 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
928 if (LocaleCompare(
"read-mask",option+1) == 0)
933 if (i == (ssize_t) argc)
934 ThrowCompareException(OptionError,
"MissingArgument",option);
937 if (LocaleCompare(
"regard-warnings",option+1) == 0)
939 if (LocaleCompare(
"repage",option+1) == 0)
944 if (i == (ssize_t) argc)
945 ThrowCompareException(OptionError,
"MissingArgument",option);
946 if (IsGeometry(argv[i]) == MagickFalse)
947 ThrowCompareInvalidArgumentException(option,argv[i]);
950 if (LocaleCompare(
"resize",option+1) == 0)
955 if (i == (ssize_t) argc)
956 ThrowCompareException(OptionError,
"MissingArgument",option);
957 if (IsGeometry(argv[i]) == MagickFalse)
958 ThrowCompareInvalidArgumentException(option,argv[i]);
961 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
963 respect_parentheses=(*option ==
'-') ? MagickTrue : MagickFalse;
966 if (LocaleCompare(
"rotate",option+1) == 0)
969 if (i == (ssize_t) argc)
970 ThrowCompareException(OptionError,
"MissingArgument",option);
971 if (IsGeometry(argv[i]) == MagickFalse)
972 ThrowCompareInvalidArgumentException(option,argv[i]);
975 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
979 if (LocaleCompare(
"sampling-factor",option+1) == 0)
984 if (i == (ssize_t) argc)
985 ThrowCompareException(OptionError,
"MissingArgument",option);
986 if (IsGeometry(argv[i]) == MagickFalse)
987 ThrowCompareInvalidArgumentException(option,argv[i]);
990 if (LocaleCompare(
"seed",option+1) == 0)
995 if (i == (ssize_t) argc)
996 ThrowCompareException(OptionError,
"MissingArgument",option);
997 if (IsGeometry(argv[i]) == MagickFalse)
998 ThrowCompareInvalidArgumentException(option,argv[i]);
1001 if (LocaleCompare(
"separate",option+1) == 0)
1003 if (LocaleCompare(
"set",option+1) == 0)
1006 if (i == (ssize_t) argc)
1007 ThrowCompareException(OptionError,
"MissingArgument",option);
1011 if (i == (ssize_t) argc)
1012 ThrowCompareException(OptionError,
"MissingArgument",option);
1015 if (LocaleCompare(
"sigmoidal-contrast",option+1) == 0)
1018 if (i == (ssize_t) argc)
1019 ThrowCompareException(OptionError,
"MissingArgument",option);
1020 if (IsGeometry(argv[i]) == MagickFalse)
1021 ThrowCompareInvalidArgumentException(option,argv[i]);
1024 if (LocaleCompare(
"similarity-threshold",option+1) == 0)
1029 if (i == (ssize_t) argc)
1030 ThrowCompareException(OptionError,
"MissingArgument",option);
1031 if (IsGeometry(argv[i]) == MagickFalse)
1032 ThrowCompareInvalidArgumentException(option,argv[i]);
1034 similarity_threshold=DefaultSimilarityThreshold;
1036 similarity_threshold=StringToDouble(argv[i],(
char **) NULL);
1039 if (LocaleCompare(
"size",option+1) == 0)
1044 if (i == (ssize_t) argc)
1045 ThrowCompareException(OptionError,
"MissingArgument",option);
1046 if (IsGeometry(argv[i]) == MagickFalse)
1047 ThrowCompareInvalidArgumentException(option,argv[i]);
1050 if (LocaleCompare(
"subimage-search",option+1) == 0)
1054 subimage_search=MagickFalse;
1057 subimage_search=MagickTrue;
1060 if (LocaleCompare(
"synchronize",option+1) == 0)
1062 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1066 if (LocaleCompare(
"taint",option+1) == 0)
1068 if (LocaleCompare(
"transparent-color",option+1) == 0)
1073 if (i == (ssize_t) argc)
1074 ThrowCompareException(OptionError,
"MissingArgument",option);
1077 if (LocaleCompare(
"trim",option+1) == 0)
1079 if (LocaleCompare(
"type",option+1) == 0)
1087 if (i == (ssize_t) argc)
1088 ThrowCompareException(OptionError,
"MissingArgument",option);
1089 type=ParseCommandOption(MagickTypeOptions,MagickFalse,argv[i]);
1091 ThrowCompareException(OptionError,
"UnrecognizedImageType",
1095 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1099 if (LocaleCompare(
"verbose",option+1) == 0)
1101 if ((LocaleCompare(
"version",option+1) == 0) ||
1102 (LocaleCompare(
"-version",option+1) == 0))
1104 ListMagickVersion(stdout);
1107 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
1115 if (i == (ssize_t) argc)
1116 ThrowCompareException(OptionError,
"MissingArgument",option);
1117 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
1120 ThrowCompareException(OptionError,
1121 "UnrecognizedVirtualPixelMethod",argv[i]);
1124 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1128 if (LocaleCompare(
"write",option+1) == 0)
1131 if (i == (ssize_t) argc)
1132 ThrowCompareException(OptionError,
"MissingArgument",option);
1135 if (LocaleCompare(
"write-mask",option+1) == 0)
1140 if (i == (ssize_t) argc)
1141 ThrowCompareException(OptionError,
"MissingArgument",option);
1144 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1149 ThrowCompareException(OptionError,
"UnrecognizedOption",option)
1151 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
1152 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
1153 if (fire != MagickFalse)
1154 FireImageStack(MagickTrue,MagickTrue,MagickTrue);
1157 ThrowCompareException(OptionError,
"UnbalancedParenthesis",argv[i]);
1158 if (i-- != (ssize_t) (argc-1))
1159 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1160 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1161 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1162 FinalizeImageSettings(image_info,image,MagickTrue);
1163 if ((image == (Image *) NULL) || (GetImageListLength(image) < 2))
1164 ThrowCompareException(OptionError,
"MissingAnImageFilename",argv[i]);
1165 image=GetImageFromList(image,0);
1166 reconstruct_image=GetImageFromList(image,1);
1169 if (subimage_search != MagickFalse)
1171 similarity_image=SimilarityImage(image,reconstruct_image,metric,
1172 similarity_threshold,&offset,&similarity_metric,exception);
1173 if (similarity_metric > dissimilarity_threshold)
1174 ThrowCompareException(ImageError,
"ImagesTooDissimilar",image->filename);
1176 if ((reconstruct_image->columns == image->columns) &&
1177 (reconstruct_image->rows == image->rows))
1178 difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
1181 if (similarity_image == (Image *) NULL)
1182 difference_image=CompareImages(image,reconstruct_image,metric,&distortion,
1192 composite_image=CloneImage(image,0,0,MagickTrue,exception);
1193 if (composite_image == (Image *) NULL)
1194 difference_image=CompareImages(image,reconstruct_image,metric,
1195 &distortion,exception);
1204 (void) CompositeImage(composite_image,reconstruct_image,
1205 CopyCompositeOp,MagickTrue,offset.x,offset.y,exception);
1206 difference_image=CompareImages(image,composite_image,metric,
1207 &distortion,exception);
1208 if (difference_image != (Image *) NULL)
1210 difference_image->page.x=offset.x;
1211 difference_image->page.y=offset.y;
1213 composite_image=DestroyImage(composite_image);
1214 page.width=reconstruct_image->columns;
1215 page.height=reconstruct_image->rows;
1218 distort_image=CropImage(image,&page,exception);
1219 if (distort_image != (Image *) NULL)
1224 sans_image=CompareImages(distort_image,reconstruct_image,metric,
1225 &distortion,exception);
1226 distort_image=DestroyImage(distort_image);
1227 if (sans_image != (Image *) NULL)
1228 sans_image=DestroyImage(sans_image);
1231 if (difference_image != (Image *) NULL)
1233 AppendImageToList(&difference_image,similarity_image);
1234 similarity_image=(Image *) NULL;
1237 if (difference_image == (Image *) NULL)
1241 if (image_info->verbose != MagickFalse)
1242 (void) SetImageColorMetric(image,reconstruct_image,exception);
1243 if (*difference_image->magick ==
'\0')
1244 (void) CopyMagickString(difference_image->magick,image->magick,
1246 if (image_info->verbose == MagickFalse)
1250 case FuzzErrorMetric:
1251 case MeanAbsoluteErrorMetric:
1252 case MeanSquaredErrorMetric:
1253 case PeakAbsoluteErrorMetric:
1254 case RootMeanSquaredErrorMetric:
1256 (void) FormatLocaleFile(stderr,
"%.*g (%.*g)",GetMagickPrecision(),
1257 (
double) QuantumRange*distortion,GetMagickPrecision(),
1261 case PeakSignalToNoiseRatioErrorMetric:
1263 (void) FormatLocaleFile(stderr,
"%.*g (%.*g)",GetMagickPrecision(),
1264 distortion,GetMagickPrecision(),0.01*distortion);
1267 case AbsoluteErrorMetric:
1268 case NormalizedCrossCorrelationErrorMetric:
1269 case PerceptualHashErrorMetric:
1270 case StructuralSimilarityErrorMetric:
1271 case StructuralDissimilarityErrorMetric:
1273 (void) FormatLocaleFile(stderr,
"%.*g",GetMagickPrecision(),
1277 case MeanErrorPerPixelErrorMetric:
1279 (void) FormatLocaleFile(stderr,
"%.*g (%.*g, %.*g)",
1280 GetMagickPrecision(),distortion,
1281 GetMagickPrecision(),image->error.normalized_mean_error,
1282 GetMagickPrecision(),image->error.normalized_maximum_error);
1285 case UndefinedErrorMetric:
1288 if (subimage_search != MagickFalse)
1289 (void) FormatLocaleFile(stderr,
" @ %.20g,%.20g",
1290 (
double) difference_image->page.x,
1291 (
double) difference_image->page.y);
1296 *channel_distortion;
1298 channel_distortion=GetImageDistortions(image,reconstruct_image,
1300 (void) FormatLocaleFile(stderr,
"Image: %s\n",image->filename);
1301 if ((reconstruct_image->columns != image->columns) ||
1302 (reconstruct_image->rows != image->rows))
1303 (void) FormatLocaleFile(stderr,
"Offset: %.20g,%.20g\n",(
double)
1304 difference_image->page.x,(
double) difference_image->page.y);
1305 (void) FormatLocaleFile(stderr,
" Channel distortion: %s\n",
1306 CommandOptionToMnemonic(MagickMetricOptions,(ssize_t) metric));
1309 case FuzzErrorMetric:
1310 case MeanAbsoluteErrorMetric:
1311 case MeanSquaredErrorMetric:
1312 case PeakAbsoluteErrorMetric:
1313 case RootMeanSquaredErrorMetric:
1315 switch (image->colorspace)
1320 (void) FormatLocaleFile(stderr,
" red: %.*g (%.*g)\n",
1321 GetMagickPrecision(),(
double) QuantumRange*
1322 channel_distortion[RedPixelChannel],GetMagickPrecision(),
1323 channel_distortion[RedPixelChannel]);
1324 (void) FormatLocaleFile(stderr,
" green: %.*g (%.*g)\n",
1325 GetMagickPrecision(),(
double) QuantumRange*
1326 channel_distortion[GreenPixelChannel],GetMagickPrecision(),
1327 channel_distortion[GreenPixelChannel]);
1328 (void) FormatLocaleFile(stderr,
" blue: %.*g (%.*g)\n",
1329 GetMagickPrecision(),(
double) QuantumRange*
1330 channel_distortion[BluePixelChannel],GetMagickPrecision(),
1331 channel_distortion[BluePixelChannel]);
1332 if (image->alpha_trait != UndefinedPixelTrait)
1333 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1334 GetMagickPrecision(),(
double) QuantumRange*
1335 channel_distortion[AlphaPixelChannel],
1336 GetMagickPrecision(),
1337 channel_distortion[AlphaPixelChannel]);
1340 case CMYKColorspace:
1342 (void) FormatLocaleFile(stderr,
" cyan: %.*g (%.*g)\n",
1343 GetMagickPrecision(),(
double) QuantumRange*
1344 channel_distortion[CyanPixelChannel],GetMagickPrecision(),
1345 channel_distortion[CyanPixelChannel]);
1346 (void) FormatLocaleFile(stderr,
" magenta: %.*g (%.*g)\n",
1347 GetMagickPrecision(),(
double) QuantumRange*
1348 channel_distortion[MagentaPixelChannel],
1349 GetMagickPrecision(),
1350 channel_distortion[MagentaPixelChannel]);
1351 (void) FormatLocaleFile(stderr,
" yellow: %.*g (%.*g)\n",
1352 GetMagickPrecision(),(
double) QuantumRange*
1353 channel_distortion[YellowPixelChannel],GetMagickPrecision(),
1354 channel_distortion[YellowPixelChannel]);
1355 (void) FormatLocaleFile(stderr,
" black: %.*g (%.*g)\n",
1356 GetMagickPrecision(),(
double) QuantumRange*
1357 channel_distortion[BlackPixelChannel],GetMagickPrecision(),
1358 channel_distortion[BlackPixelChannel]);
1359 if (image->alpha_trait != UndefinedPixelTrait)
1360 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1361 GetMagickPrecision(),(
double) QuantumRange*
1362 channel_distortion[AlphaPixelChannel],
1363 GetMagickPrecision(),
1364 channel_distortion[AlphaPixelChannel]);
1367 case LinearGRAYColorspace:
1368 case GRAYColorspace:
1370 (void) FormatLocaleFile(stderr,
" gray: %.*g (%.*g)\n",
1371 GetMagickPrecision(),(
double) QuantumRange*
1372 channel_distortion[GrayPixelChannel],GetMagickPrecision(),
1373 channel_distortion[GrayPixelChannel]);
1374 if (image->alpha_trait != UndefinedPixelTrait)
1375 (void) FormatLocaleFile(stderr,
" alpha: %.*g (%.*g)\n",
1376 GetMagickPrecision(),(
double) QuantumRange*
1377 channel_distortion[AlphaPixelChannel],
1378 GetMagickPrecision(),
1379 channel_distortion[AlphaPixelChannel]);
1383 (void) FormatLocaleFile(stderr,
" all: %.*g (%.*g)\n",
1384 GetMagickPrecision(),(
double) QuantumRange*
1385 channel_distortion[MaxPixelChannels],GetMagickPrecision(),
1386 channel_distortion[MaxPixelChannels]);
1389 case AbsoluteErrorMetric:
1390 case NormalizedCrossCorrelationErrorMetric:
1391 case PeakSignalToNoiseRatioErrorMetric:
1392 case PerceptualHashErrorMetric:
1393 case StructuralSimilarityErrorMetric:
1394 case StructuralDissimilarityErrorMetric:
1396 switch (image->colorspace)
1401 (void) FormatLocaleFile(stderr,
" red: %.*g\n",
1402 GetMagickPrecision(),channel_distortion[RedPixelChannel]);
1403 (void) FormatLocaleFile(stderr,
" green: %.*g\n",
1404 GetMagickPrecision(),channel_distortion[GreenPixelChannel]);
1405 (void) FormatLocaleFile(stderr,
" blue: %.*g\n",
1406 GetMagickPrecision(),channel_distortion[BluePixelChannel]);
1407 if (image->alpha_trait != UndefinedPixelTrait)
1408 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1409 GetMagickPrecision(),
1410 channel_distortion[AlphaPixelChannel]);
1413 case CMYKColorspace:
1415 (void) FormatLocaleFile(stderr,
" cyan: %.*g\n",
1416 GetMagickPrecision(),channel_distortion[CyanPixelChannel]);
1417 (void) FormatLocaleFile(stderr,
" magenta: %.*g\n",
1418 GetMagickPrecision(),
1419 channel_distortion[MagentaPixelChannel]);
1420 (void) FormatLocaleFile(stderr,
" yellow: %.*g\n",
1421 GetMagickPrecision(),
1422 channel_distortion[YellowPixelChannel]);
1423 (void) FormatLocaleFile(stderr,
" black: %.*g\n",
1424 GetMagickPrecision(),
1425 channel_distortion[BlackPixelChannel]);
1426 if (image->alpha_trait != UndefinedPixelTrait)
1427 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1428 GetMagickPrecision(),
1429 channel_distortion[AlphaPixelChannel]);
1432 case LinearGRAYColorspace:
1433 case GRAYColorspace:
1435 (void) FormatLocaleFile(stderr,
" gray: %.*g\n",
1436 GetMagickPrecision(),channel_distortion[GrayPixelChannel]);
1437 if (image->alpha_trait != UndefinedPixelTrait)
1438 (void) FormatLocaleFile(stderr,
" alpha: %.*g\n",
1439 GetMagickPrecision(),
1440 channel_distortion[AlphaPixelChannel]);
1444 (void) FormatLocaleFile(stderr,
" all: %.*g\n",
1445 GetMagickPrecision(),channel_distortion[MaxPixelChannels]);
1448 case MeanErrorPerPixelErrorMetric:
1450 (void) FormatLocaleFile(stderr,
" %.*g (%.*g, %.*g)\n",
1451 GetMagickPrecision(),channel_distortion[MaxPixelChannels],
1452 GetMagickPrecision(),image->error.normalized_mean_error,
1453 GetMagickPrecision(),image->error.normalized_maximum_error);
1456 case UndefinedErrorMetric:
1459 channel_distortion=(
double *) RelinquishMagickMemory(
1460 channel_distortion);
1461 if (subimage_search != MagickFalse)
1462 (void) FormatLocaleFile(stderr,
" Offset: %.20g,%.20g\n",(
double)
1463 difference_image->page.x,(
double) difference_image->page.y);
1465 (void) ResetImagePage(difference_image,
"0x0+0+0");
1466 if (difference_image->next != (Image *) NULL)
1467 (void) ResetImagePage(difference_image->next,
"0x0+0+0");
1468 status&=(MagickStatusType) WriteImages(image_info,difference_image,
1469 argv[argc-1],exception);
1470 if ((metadata != (
char **) NULL) && (format != (
char *) NULL))
1475 text=InterpretImageProperties(image_info,difference_image,format,
1477 if (text == (
char *) NULL)
1478 ThrowCompareException(ResourceLimitError,
"MemoryAllocationFailed",
1479 GetExceptionMessage(errno));
1480 (void) ConcatenateString(&(*metadata),text);
1481 text=DestroyString(text);
1483 difference_image=DestroyImageList(difference_image);
1486 if ((metric == NormalizedCrossCorrelationErrorMetric) ||
1487 (metric == StructuralSimilarityErrorMetric) ||
1488 (metric == UndefinedErrorMetric))
1490 if (fabs(distortion-1.0) > CompareEpsilon)
1491 (void) SetImageOption(image_info,
"compare:dissimilar",
"true");
1494 if (fabs(distortion) > CompareEpsilon)
1495 (void) SetImageOption(image_info,
"compare:dissimilar",
"true");
1496 return(status != 0 ? MagickTrue : MagickFalse);