const Image *reconstruct_image,double *distortion,ExceptionInfo *exception)
{
ChannelPerceptualHash
- *image_phash,
+ *channel_phash,
*reconstruct_phash;
ssize_t
/*
Compute perceptual hash in the sRGB colorspace.
*/
- image_phash=GetImagePerceptualHash(image,exception);
- if (image_phash == (ChannelPerceptualHash *) NULL)
+ channel_phash=GetImagePerceptualHash(image,exception);
+ if (channel_phash == (ChannelPerceptualHash *) NULL)
return(MagickFalse);
reconstruct_phash=GetImagePerceptualHash(reconstruct_image,exception);
if (reconstruct_phash == (ChannelPerceptualHash *) NULL)
{
- image_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(image_phash);
+ channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
+ channel_phash);
return(MagickFalse);
}
#if defined(MAGICKCORE_OPENMP_SUPPORT)
alpha,
beta;
- alpha=image_phash[channel].srgb_hu_phash[i];
- beta=reconstruct_phash[channel].srgb_hu_phash[i];
- difference+=(beta-alpha)*(beta-alpha);
- }
- distortion[channel]+=difference;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_GetPerceptualHashDistortion)
-#endif
- distortion[CompositePixelChannel]+=difference;
- }
- /*
- Compute perceptual hash in the HCLP colorspace.
- */
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4)
-#endif
- for (channel=0; channel < MaxPixelChannels; channel++)
- {
- double
- difference;
-
- register ssize_t
- i;
-
- difference=0.0;
- for (i=0; i < MaximumNumberOfImageMoments; i++)
- {
- double
- alpha,
- beta;
+ register ssize_t
+ j;
- alpha=image_phash[channel].hclp_hu_phash[i];
- beta=reconstruct_phash[channel].hclp_hu_phash[i];
- difference+=(beta-alpha)*(beta-alpha);
+ for (j=0; j < (ssize_t) channel_phash[0].number_colorspaces; j++)
+ {
+ alpha=channel_phash[channel].phash[j][i];
+ beta=reconstruct_phash[channel].phash[j][i];
+ difference+=(beta-alpha)*(beta-alpha);
+ }
}
distortion[channel]+=difference;
#if defined(MAGICKCORE_OPENMP_SUPPORT)
*/
reconstruct_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
reconstruct_phash);
- image_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(image_phash);
+ channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(channel_phash);
return(MagickTrue);
}
(void) FormatLocaleFile(file,"\n");
for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
{
- const char
- *name;
-
register ssize_t
j;
PixelTrait traits=GetPixelChannelTraits(image,channel);
if (traits == UndefinedPixelTrait)
continue;
- switch (channel)
- {
- case RedPixelChannel:
- {
- name="Red";
- if (image->colorspace == CMYKColorspace)
- name="Cyan";
- if (image->colorspace == GRAYColorspace)
- name="Gray";
- break;
- }
- case GreenPixelChannel:
- {
- name="Green";
- if (image->colorspace == CMYKColorspace)
- name="Magenta";
- break;
- }
- case BluePixelChannel:
- {
- name="Blue";
- if (image->colorspace == CMYKColorspace)
- name="Yellow";
- break;
- }
- case BlackPixelChannel:
- {
- name="Black";
- if (image->storage_class == PseudoClass)
- name="Index";
- break;
- }
- case IndexPixelChannel:
- {
- name="Index";
- break;
- }
- case AlphaPixelChannel:
- {
- name="Alpha";
- break;
- }
- case ReadMaskPixelChannel:
- {
- name="ReadMask";
- break;
- }
- case WriteMaskPixelChannel:
- {
- name="WriteMask";
- break;
- }
- case MetaPixelChannel:
- {
- name="Meta";
- break;
- }
- default:
- name="Undefined";
- }
- n=FormatLocaleFile(file," %s:\n",name);
+ n=FormatLocaleFile(file," Channel %.20g:\n",(double) channel);
for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
{
register ssize_t
return(n);
}
-static ssize_t PrintChannelPerceptualHash(FILE *file,const ChannelType channel,
- const char *name,const MagickBooleanType separator,
+static ssize_t PrintChannelPerceptualHash(Image *image,FILE *file,
const ChannelPerceptualHash *channel_phash)
{
register ssize_t
ssize_t
n;
- n=FormatLocaleFile(file," \"%s\": {\n",name);
- for (i=0; i < 6; i++)
- n+=FormatLocaleFile(file,
- " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ],\n",i+1.0,
- GetMagickPrecision(),channel_phash[channel].srgb_hu_phash[i],
- GetMagickPrecision(),channel_phash[channel].hclp_hu_phash[i]);
- n+=FormatLocaleFile(file,
- " \"PH%.20g\": [ \"%.*g\", \"%.*g\" ]\n",i+1.0,
- GetMagickPrecision(),channel_phash[channel].srgb_hu_phash[i],
- GetMagickPrecision(),channel_phash[channel].hclp_hu_phash[i]);
- (void) FormatLocaleFile(file," }");
- if (separator != MagickFalse)
- (void) FormatLocaleFile(file,",");
- (void) FormatLocaleFile(file,"\n");
+ (void) FormatLocaleFile(file," \"colorspaces\": [ ");
+ for (i=0; i < (ssize_t) channel_phash[0].number_colorspaces; i++)
+ {
+ (void) FormatLocaleFile(file,"\"%s\"",CommandOptionToMnemonic(
+ MagickColorspaceOptions,(ssize_t) channel_phash[0].colorspace[i]));
+ if (i < (ssize_t) (channel_phash[0].number_colorspaces-1))
+ (void) FormatLocaleFile(file,", ");
+ }
+ (void) FormatLocaleFile(file,"],\n");
+ for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+ {
+ register ssize_t
+ j;
+
+ PixelChannel channel=GetPixelChannelChannel(image,i);
+ PixelTrait traits=GetPixelChannelTraits(image,channel);
+ if (traits == UndefinedPixelTrait)
+ continue;
+ n=FormatLocaleFile(file," \"Channel%.20g\": {\n",(double) channel);
+ for (j=0; j < MaximumNumberOfPerceptualHashes; j++)
+ {
+ register ssize_t
+ k;
+
+ n+=FormatLocaleFile(file," \"PH%.20g\": [",(double) j+1);
+ for (k=0; k < (ssize_t) channel_phash[0].number_colorspaces; k++)
+ {
+ n+=FormatLocaleFile(file,"\"%.*g\"",GetMagickPrecision(),
+ channel_phash[channel].phash[k][j]);
+ if (k < (ssize_t) (channel_phash[0].number_colorspaces-1))
+ n+=FormatLocaleFile(file,", ");
+ }
+ n+=FormatLocaleFile(file,"]");
+ if (j < (MaximumNumberOfPerceptualHashes-1))
+ n+=FormatLocaleFile(file,",\n");
+ }
+ if (i < (GetPixelChannels(image)-1))
+ n+=FormatLocaleFile(file,"\n },\n");
+ }
+ n+=FormatLocaleFile(file,"\n }\n");
return(n);
}
if (channel_phash != (ChannelPerceptualHash *) NULL)
{
(void) FormatLocaleFile(file," \"channelPerceptualHash\": {\n");
- if (image->alpha_trait != UndefinedPixelTrait)
- (void) PrintChannelPerceptualHash(file,AlphaChannel,"alphaAlpha",
- MagickTrue,channel_phash);
- (void) PrintChannelPerceptualHash(file,RedChannel,"redHue",MagickTrue,
- channel_phash);
- (void) PrintChannelPerceptualHash(file,GreenChannel,"greenChroma",
- MagickTrue,channel_phash);
- (void) PrintChannelPerceptualHash(file,BlueChannel,"blueLuma",MagickFalse,
- channel_phash);
+ (void) PrintChannelPerceptualHash(image,file,channel_phash);
(void) FormatLocaleFile(file," },\n");
channel_phash=(ChannelPerceptualHash *) RelinquishMagickMemory(
channel_phash);