From: cristy Date: Thu, 30 Jan 2014 12:54:20 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~2753 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=337bf652ea5452a7147647e4d4450d7e71ee4c11;p=imagemagick --- diff --git a/MagickCore/compare.c b/MagickCore/compare.c index b2fbfda2e..b5095748c 100644 --- a/MagickCore/compare.c +++ b/MagickCore/compare.c @@ -1103,6 +1103,33 @@ static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image, return(status); } +static Image *PerceptualHashImage(const Image *image, + const ColorspaceType colorspace,ExceptionInfo *exception) +{ + Image + *clone_image, + *phash_image; + + MagickBooleanType + status; + + /* + Transform colorspace then blur perceptual hash image. + */ + clone_image=CloneImage(image,0,0,MagickTrue,exception); + if (clone_image == (Image *) NULL) + return((Image *) NULL); + status=TransformImageColorspace(clone_image,colorspace,exception); + if (status == MagickFalse) + { + clone_image=DestroyImage(clone_image); + return((Image *) NULL); + } + phash_image=BlurImage(clone_image,0.0,1.0,exception); + clone_image=DestroyImage(clone_image); + return(phash_image); +} + static MagickBooleanType GetPerceptualHashDistortion(const Image *image, const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) { @@ -1111,8 +1138,8 @@ static MagickBooleanType GetPerceptualHashDistortion(const Image *image, *reconstruct_moments; Image - *blur_image, - *blur_reconstruct; + *phash_image, + *phash_reconstruct; register ssize_t i; @@ -1120,35 +1147,32 @@ static MagickBooleanType GetPerceptualHashDistortion(const Image *image, /* Compute perceptual hash in the native image colorspace. */ - blur_image=BlurImage(image,0.0,1.0,exception); - if (blur_image == (Image *) NULL) + phash_image=PerceptualHashImage(image,image->colorspace,exception); + if (phash_image == (Image *) NULL) return(MagickFalse); - image_moments=GetImageMoments(blur_image,exception); + image_moments=GetImageMoments(phash_image,exception); + phash_image=DestroyImage(phash_image); if (image_moments == (ChannelMoments *) NULL) - { - blur_image=DestroyImage(blur_image); - return(MagickFalse); - } - blur_reconstruct=BlurImage(reconstruct_image,0.0,1.0,exception); - if (blur_reconstruct == (Image *) NULL) + return(MagickFalse); + phash_reconstruct=PerceptualHashImage(reconstruct_image, + reconstruct_image->colorspace,exception); + if (phash_reconstruct == (Image *) NULL) { image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments); - blur_image=DestroyImage(blur_image); return(MagickFalse); } - reconstruct_moments=GetImageMoments(blur_reconstruct,exception); + reconstruct_moments=GetImageMoments(phash_reconstruct,exception); + phash_reconstruct=DestroyImage(phash_reconstruct); if (reconstruct_moments == (ChannelMoments *) NULL) { image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments); - blur_image=DestroyImage(blur_image); - blur_reconstruct=DestroyImage(blur_reconstruct); return(MagickFalse); } for (i=0; i < 7; i++) { - ssize_t + ssize_t channel; - + /* Compute sum of moment differences squared. */ @@ -1169,32 +1193,28 @@ static MagickBooleanType GetPerceptualHashDistortion(const Image *image, image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments); reconstruct_moments=(ChannelMoments *) RelinquishMagickMemory( reconstruct_moments); - if ((IsImageGray(blur_image,exception) != MagickFalse) || - (IsImageGray(blur_reconstruct,exception) != MagickFalse)) - { - blur_reconstruct=DestroyImage(blur_reconstruct); - blur_image=DestroyImage(blur_image); - return(MagickTrue); - } + if ((IsImageGray(image,exception) != MagickFalse) || + (IsImageGray(reconstruct_image,exception) != MagickFalse)) + return(MagickTrue); /* Compute perceptual hash in the HCLP colorspace. */ - if ((TransformImageColorspace(blur_image,HCLpColorspace,exception) == MagickFalse) || - (TransformImageColorspace(blur_reconstruct,HCLpColorspace,exception) == MagickFalse)) - { - blur_reconstruct=DestroyImage(blur_reconstruct); - blur_image=DestroyImage(blur_image); - return(MagickFalse); - } - image_moments=GetImageMoments(blur_image,exception); - blur_image=DestroyImage(blur_image); + phash_image=PerceptualHashImage(image,HCLpColorspace,exception); + if (phash_image == (Image *) NULL) + return(MagickFalse); + image_moments=GetImageMoments(phash_image,exception); + phash_image=DestroyImage(phash_image); if (image_moments == (ChannelMoments *) NULL) + return(MagickFalse); + phash_reconstruct=PerceptualHashImage(reconstruct_image,HCLpColorspace, + exception); + if (phash_reconstruct == (Image *) NULL) { - blur_reconstruct=DestroyImage(blur_reconstruct); + image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments); return(MagickFalse); } - reconstruct_moments=GetImageMoments(blur_reconstruct,exception); - blur_reconstruct=DestroyImage(blur_reconstruct); + reconstruct_moments=GetImageMoments(phash_reconstruct,exception); + phash_reconstruct=DestroyImage(phash_reconstruct); if (reconstruct_moments == (ChannelMoments *) NULL) { image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments); @@ -1202,9 +1222,9 @@ static MagickBooleanType GetPerceptualHashDistortion(const Image *image, } for (i=0; i < 7; i++) { - ssize_t + ssize_t channel; - + /* Compute sum of moment differences squared. */ @@ -1228,6 +1248,7 @@ static MagickBooleanType GetPerceptualHashDistortion(const Image *image, return(MagickTrue); } + static MagickBooleanType GetRootMeanSquaredDistortion(const Image *image, const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) {