cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 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 % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Comparison Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % December 2003 % |
| 18 | % % |
| 19 | % % |
cristy | 7e41fe8 | 2010-12-04 23:12:08 +0000 | [diff] [blame] | 20 | % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % dedicated to making software imaging solutions freely available. % |
| 22 | % % |
| 23 | % You may not use this file except in compliance with the License. You may % |
| 24 | % obtain a copy of the License at % |
| 25 | % % |
| 26 | % http://www.imagemagick.org/script/license.php % |
| 27 | % % |
| 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. % |
| 33 | % % |
| 34 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 35 | % |
| 36 | % |
| 37 | % |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | Include declarations. |
| 42 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/artifact.h" |
| 45 | #include "MagickCore/cache-view.h" |
| 46 | #include "MagickCore/client.h" |
| 47 | #include "MagickCore/color.h" |
| 48 | #include "MagickCore/color-private.h" |
| 49 | #include "MagickCore/colorspace.h" |
| 50 | #include "MagickCore/colorspace-private.h" |
| 51 | #include "MagickCore/compare.h" |
| 52 | #include "MagickCore/composite-private.h" |
| 53 | #include "MagickCore/constitute.h" |
| 54 | #include "MagickCore/exception-private.h" |
| 55 | #include "MagickCore/geometry.h" |
| 56 | #include "MagickCore/image-private.h" |
| 57 | #include "MagickCore/list.h" |
| 58 | #include "MagickCore/log.h" |
| 59 | #include "MagickCore/memory_.h" |
| 60 | #include "MagickCore/monitor.h" |
| 61 | #include "MagickCore/monitor-private.h" |
| 62 | #include "MagickCore/option.h" |
| 63 | #include "MagickCore/pixel-accessor.h" |
| 64 | #include "MagickCore/resource_.h" |
| 65 | #include "MagickCore/string_.h" |
| 66 | #include "MagickCore/statistic.h" |
| 67 | #include "MagickCore/transform.h" |
| 68 | #include "MagickCore/utility.h" |
| 69 | #include "MagickCore/version.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 70 | |
| 71 | /* |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % % |
| 74 | % % |
| 75 | % % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 76 | % C o m p a r e I m a g e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 77 | % % |
| 78 | % % |
| 79 | % % |
| 80 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 81 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 82 | % CompareImages() compares one or more pixel channels of an image to a |
| 83 | % reconstructed image and returns the difference image. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 84 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 85 | % The format of the CompareImages method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 87 | % Image *CompareImages(const Image *image,const Image *reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 88 | % const MetricType metric,double *distortion,ExceptionInfo *exception) |
| 89 | % |
| 90 | % A description of each parameter follows: |
| 91 | % |
| 92 | % o image: the image. |
| 93 | % |
| 94 | % o reconstruct_image: the reconstruct image. |
| 95 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | % o metric: the metric. |
| 97 | % |
| 98 | % o distortion: the computed distortion between the images. |
| 99 | % |
| 100 | % o exception: return any errors or warnings in this structure. |
| 101 | % |
| 102 | */ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 103 | MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image, |
| 104 | const MetricType metric,double *distortion,ExceptionInfo *exception) |
| 105 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 106 | CacheView |
| 107 | *highlight_view, |
| 108 | *image_view, |
| 109 | *reconstruct_view; |
| 110 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 111 | const char |
| 112 | *artifact; |
| 113 | |
| 114 | Image |
| 115 | *difference_image, |
| 116 | *highlight_image; |
| 117 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 118 | MagickBooleanType |
| 119 | status; |
| 120 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 121 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | highlight, |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 123 | lowlight; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 124 | |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 125 | ssize_t |
| 126 | y; |
| 127 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 128 | assert(image != (Image *) NULL); |
| 129 | assert(image->signature == MagickSignature); |
| 130 | if (image->debug != MagickFalse) |
| 131 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 132 | assert(reconstruct_image != (const Image *) NULL); |
| 133 | assert(reconstruct_image->signature == MagickSignature); |
| 134 | assert(distortion != (double *) NULL); |
| 135 | *distortion=0.0; |
| 136 | if (image->debug != MagickFalse) |
| 137 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 138 | if ((reconstruct_image->columns != image->columns) || |
| 139 | (reconstruct_image->rows != image->rows)) |
| 140 | ThrowImageException(ImageError,"ImageSizeDiffers"); |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 141 | status=GetImageDistortion(image,reconstruct_image,metric,distortion, |
| 142 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 143 | if (status == MagickFalse) |
| 144 | return((Image *) NULL); |
| 145 | difference_image=CloneImage(image,0,0,MagickTrue,exception); |
| 146 | if (difference_image == (Image *) NULL) |
| 147 | return((Image *) NULL); |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 148 | (void) SetImageAlphaChannel(difference_image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 149 | highlight_image=CloneImage(image,image->columns,image->rows,MagickTrue, |
| 150 | exception); |
| 151 | if (highlight_image == (Image *) NULL) |
| 152 | { |
| 153 | difference_image=DestroyImage(difference_image); |
| 154 | return((Image *) NULL); |
| 155 | } |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 156 | status=SetImageStorageClass(highlight_image,DirectClass,exception); |
| 157 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 158 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | difference_image=DestroyImage(difference_image); |
| 160 | highlight_image=DestroyImage(highlight_image); |
| 161 | return((Image *) NULL); |
| 162 | } |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 163 | (void) SetImageAlphaChannel(highlight_image,OpaqueAlphaChannel,exception); |
cristy | 269c941 | 2011-10-13 23:41:15 +0000 | [diff] [blame] | 164 | (void) QueryColorCompliance("#f1001ecc",AllCompliance,&highlight, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 165 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 166 | artifact=GetImageArtifact(image,"highlight-color"); |
| 167 | if (artifact != (const char *) NULL) |
cristy | 269c941 | 2011-10-13 23:41:15 +0000 | [diff] [blame] | 168 | (void) QueryColorCompliance(artifact,AllCompliance,&highlight, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 169 | exception); |
cristy | 269c941 | 2011-10-13 23:41:15 +0000 | [diff] [blame] | 170 | (void) QueryColorCompliance("#ffffffcc",AllCompliance,&lowlight, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 171 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 172 | artifact=GetImageArtifact(image,"lowlight-color"); |
| 173 | if (artifact != (const char *) NULL) |
cristy | 0b1a797 | 2011-10-22 22:17:02 +0000 | [diff] [blame] | 174 | (void) QueryColorCompliance(artifact,AllCompliance,&lowlight,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 175 | /* |
| 176 | Generate difference image. |
| 177 | */ |
| 178 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 179 | image_view=AcquireCacheView(image); |
| 180 | reconstruct_view=AcquireCacheView(reconstruct_image); |
| 181 | highlight_view=AcquireCacheView(highlight_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 182 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 183 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 184 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 185 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | { |
| 187 | MagickBooleanType |
| 188 | sync; |
| 189 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 190 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 191 | *restrict p, |
| 192 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 193 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 194 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 195 | *restrict r; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 196 | |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 197 | register ssize_t |
| 198 | x; |
| 199 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 200 | if (status == MagickFalse) |
| 201 | continue; |
| 202 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 203 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 204 | 1,exception); |
| 205 | r=QueueCacheViewAuthenticPixels(highlight_view,0,y,highlight_image->columns, |
| 206 | 1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 207 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL) || |
| 208 | (r == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 209 | { |
| 210 | status=MagickFalse; |
| 211 | continue; |
| 212 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 213 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 214 | { |
| 215 | MagickStatusType |
| 216 | difference; |
| 217 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 218 | register ssize_t |
| 219 | i; |
| 220 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 221 | difference=MagickFalse; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 222 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 223 | { |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 224 | MagickRealType |
| 225 | distance; |
| 226 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 227 | PixelChannel |
| 228 | channel; |
| 229 | |
| 230 | PixelTrait |
| 231 | reconstruct_traits, |
| 232 | traits; |
| 233 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 234 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 235 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 236 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 237 | if ((traits == UndefinedPixelTrait) || |
| 238 | (reconstruct_traits == UndefinedPixelTrait)) |
| 239 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 240 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 241 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 242 | distance=p[i]-(MagickRealType) |
| 243 | GetPixelChannel(reconstruct_image,channel,q); |
| 244 | if (fabs((double) distance) >= MagickEpsilon) |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 245 | difference=MagickTrue; |
| 246 | } |
| 247 | if (difference == MagickFalse) |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 248 | SetPixelInfoPixel(highlight_image,&lowlight,r); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 249 | else |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 250 | SetPixelInfoPixel(highlight_image,&highlight,r); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 251 | p+=GetPixelChannels(image); |
| 252 | q+=GetPixelChannels(reconstruct_image); |
| 253 | r+=GetPixelChannels(highlight_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 254 | } |
| 255 | sync=SyncCacheViewAuthenticPixels(highlight_view,exception); |
| 256 | if (sync == MagickFalse) |
| 257 | status=MagickFalse; |
| 258 | } |
| 259 | highlight_view=DestroyCacheView(highlight_view); |
| 260 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 261 | image_view=DestroyCacheView(image_view); |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 262 | (void) CompositeImage(difference_image,image->compose,highlight_image,0,0, |
| 263 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 264 | highlight_image=DestroyImage(highlight_image); |
| 265 | if (status == MagickFalse) |
| 266 | difference_image=DestroyImage(difference_image); |
| 267 | return(difference_image); |
| 268 | } |
| 269 | |
| 270 | /* |
| 271 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 272 | % % |
| 273 | % % |
| 274 | % % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 275 | % G e t I m a g e D i s t o r t i o n % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 276 | % % |
| 277 | % % |
| 278 | % % |
| 279 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 280 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 281 | % GetImageDistortion() compares one or more pixel channels of an image to a |
| 282 | % reconstructed image and returns the specified distortion metric. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 283 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 284 | % The format of the CompareImages method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 285 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 286 | % MagickBooleanType GetImageDistortion(const Image *image, |
| 287 | % const Image *reconstruct_image,const MetricType metric, |
| 288 | % double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | % |
| 290 | % A description of each parameter follows: |
| 291 | % |
| 292 | % o image: the image. |
| 293 | % |
| 294 | % o reconstruct_image: the reconstruct image. |
| 295 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | % o metric: the metric. |
| 297 | % |
| 298 | % o distortion: the computed distortion between the images. |
| 299 | % |
| 300 | % o exception: return any errors or warnings in this structure. |
| 301 | % |
| 302 | */ |
| 303 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 304 | static MagickBooleanType GetAbsoluteDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 305 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 306 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 307 | CacheView |
| 308 | *image_view, |
| 309 | *reconstruct_view; |
| 310 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 311 | MagickBooleanType |
| 312 | status; |
| 313 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 314 | ssize_t |
| 315 | y; |
| 316 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 317 | /* |
| 318 | Compute the absolute difference in pixels between two images. |
| 319 | */ |
| 320 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 321 | image_view=AcquireCacheView(image); |
| 322 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 323 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 324 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 325 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 326 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | { |
| 328 | double |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 329 | channel_distortion[MaxPixelChannels+1]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 330 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 331 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 332 | *restrict p, |
| 333 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 335 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 336 | i, |
| 337 | x; |
| 338 | |
| 339 | if (status == MagickFalse) |
| 340 | continue; |
| 341 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 342 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 343 | 1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 344 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 345 | { |
| 346 | status=MagickFalse; |
| 347 | continue; |
| 348 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 349 | (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 350 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 351 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 352 | MagickBooleanType |
| 353 | difference; |
| 354 | |
| 355 | register ssize_t |
| 356 | i; |
| 357 | |
| 358 | difference=MagickFalse; |
| 359 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 360 | { |
| 361 | PixelChannel |
| 362 | channel; |
| 363 | |
| 364 | PixelTrait |
| 365 | reconstruct_traits, |
| 366 | traits; |
| 367 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 368 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 369 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 370 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 371 | if ((traits == UndefinedPixelTrait) || |
| 372 | (reconstruct_traits == UndefinedPixelTrait)) |
| 373 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 374 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 375 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 376 | if (p[i] != GetPixelChannel(reconstruct_image,channel,q)) |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 377 | difference=MagickTrue; |
| 378 | } |
| 379 | if (difference != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 380 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 381 | channel_distortion[i]++; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 382 | channel_distortion[CompositePixelChannel]++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 383 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 384 | p+=GetPixelChannels(image); |
| 385 | q+=GetPixelChannels(reconstruct_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 387 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | #pragma omp critical (MagickCore_GetAbsoluteError) |
| 389 | #endif |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 390 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 391 | distortion[i]+=channel_distortion[i]; |
| 392 | } |
| 393 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 394 | image_view=DestroyCacheView(image_view); |
| 395 | return(status); |
| 396 | } |
| 397 | |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 398 | static size_t GetImageChannels(const Image *image) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 399 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 400 | register ssize_t |
| 401 | i; |
| 402 | |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 403 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | channels; |
| 405 | |
| 406 | channels=0; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 407 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 408 | { |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 409 | PixelChannel |
| 410 | channel; |
| 411 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 412 | PixelTrait |
| 413 | traits; |
| 414 | |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 415 | channel=GetPixelChannelMapChannel(image,i); |
| 416 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 25a5f2f | 2011-09-24 14:09:43 +0000 | [diff] [blame] | 417 | if ((traits & UpdatePixelTrait) != 0) |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 418 | channels++; |
| 419 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 420 | return(channels); |
| 421 | } |
| 422 | |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 423 | static MagickBooleanType GetFuzzDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 424 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 425 | { |
| 426 | CacheView |
| 427 | *image_view, |
| 428 | *reconstruct_view; |
| 429 | |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 430 | MagickBooleanType |
| 431 | status; |
| 432 | |
| 433 | register ssize_t |
| 434 | i; |
| 435 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 436 | ssize_t |
| 437 | y; |
| 438 | |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 439 | status=MagickTrue; |
| 440 | image_view=AcquireCacheView(image); |
| 441 | reconstruct_view=AcquireCacheView(reconstruct_image); |
| 442 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 443 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 444 | #endif |
| 445 | for (y=0; y < (ssize_t) image->rows; y++) |
| 446 | { |
| 447 | double |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 448 | channel_distortion[MaxPixelChannels+1]; |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 449 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 450 | register const Quantum |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 451 | *restrict p, |
| 452 | *restrict q; |
| 453 | |
| 454 | register ssize_t |
| 455 | i, |
| 456 | x; |
| 457 | |
| 458 | if (status == MagickFalse) |
| 459 | continue; |
| 460 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | e6529ff | 2011-02-04 20:05:32 +0000 | [diff] [blame] | 461 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 462 | 1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 463 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 464 | { |
| 465 | status=MagickFalse; |
| 466 | continue; |
| 467 | } |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 468 | (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion)); |
| 469 | for (x=0; x < (ssize_t) image->columns; x++) |
| 470 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 471 | register ssize_t |
| 472 | i; |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 473 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 474 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 475 | { |
| 476 | MagickRealType |
| 477 | distance; |
| 478 | |
| 479 | PixelChannel |
| 480 | channel; |
| 481 | |
| 482 | PixelTrait |
| 483 | reconstruct_traits, |
| 484 | traits; |
| 485 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 486 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 487 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 488 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 489 | if ((traits == UndefinedPixelTrait) || |
| 490 | (reconstruct_traits == UndefinedPixelTrait)) |
| 491 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 492 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 493 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 494 | distance=QuantumScale*(p[i]-(MagickRealType) GetPixelChannel( |
| 495 | reconstruct_image,channel,q)); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 496 | distance*=distance; |
| 497 | channel_distortion[i]+=distance; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 498 | channel_distortion[CompositePixelChannel]+=distance; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 499 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 500 | p+=GetPixelChannels(image); |
| 501 | q+=GetPixelChannels(reconstruct_image); |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 502 | } |
| 503 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 504 | #pragma omp critical (MagickCore_GetMeanSquaredError) |
| 505 | #endif |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 506 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 507 | distortion[i]+=channel_distortion[i]; |
| 508 | } |
| 509 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 510 | image_view=DestroyCacheView(image_view); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 511 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 512 | distortion[i]/=((double) image->columns*image->rows); |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 513 | distortion[CompositePixelChannel]/=(double) GetImageChannels(image); |
| 514 | distortion[CompositePixelChannel]=sqrt(distortion[CompositePixelChannel]); |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 515 | return(status); |
| 516 | } |
| 517 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 518 | static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 519 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 521 | CacheView |
| 522 | *image_view, |
| 523 | *reconstruct_view; |
| 524 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 525 | MagickBooleanType |
| 526 | status; |
| 527 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 528 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 529 | i; |
| 530 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 531 | ssize_t |
| 532 | y; |
| 533 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 534 | status=MagickTrue; |
| 535 | image_view=AcquireCacheView(image); |
| 536 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 537 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 538 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 539 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 540 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 541 | { |
| 542 | double |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 543 | channel_distortion[MaxPixelChannels+1]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 544 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 545 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 546 | *restrict p, |
| 547 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 548 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 549 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 550 | i, |
| 551 | x; |
| 552 | |
| 553 | if (status == MagickFalse) |
| 554 | continue; |
| 555 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 556 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 557 | 1,exception); |
| 558 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 559 | { |
| 560 | status=MagickFalse; |
| 561 | continue; |
| 562 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 563 | (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 564 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 565 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 566 | register ssize_t |
| 567 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 569 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 570 | { |
| 571 | MagickRealType |
| 572 | distance; |
| 573 | |
| 574 | PixelChannel |
| 575 | channel; |
| 576 | |
| 577 | PixelTrait |
| 578 | reconstruct_traits, |
| 579 | traits; |
| 580 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 581 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 582 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 583 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 584 | if ((traits == UndefinedPixelTrait) || |
| 585 | (reconstruct_traits == UndefinedPixelTrait)) |
| 586 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 587 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 588 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 589 | distance=QuantumScale*fabs(p[i]-(MagickRealType) GetPixelChannel( |
| 590 | reconstruct_image,channel,q)); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 591 | channel_distortion[i]+=distance; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 592 | channel_distortion[CompositePixelChannel]+=distance; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 593 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 594 | p+=GetPixelChannels(image); |
| 595 | q+=GetPixelChannels(reconstruct_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 596 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 597 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 598 | #pragma omp critical (MagickCore_GetMeanAbsoluteError) |
| 599 | #endif |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 600 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 601 | distortion[i]+=channel_distortion[i]; |
| 602 | } |
| 603 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 604 | image_view=DestroyCacheView(image_view); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 605 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 606 | distortion[i]/=((double) image->columns*image->rows); |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 607 | distortion[CompositePixelChannel]/=(double) GetImageChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 608 | return(status); |
| 609 | } |
| 610 | |
| 611 | static MagickBooleanType GetMeanErrorPerPixel(Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 612 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 613 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 614 | CacheView |
| 615 | *image_view, |
| 616 | *reconstruct_view; |
| 617 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 618 | MagickBooleanType |
| 619 | status; |
| 620 | |
| 621 | MagickRealType |
| 622 | alpha, |
| 623 | area, |
| 624 | beta, |
| 625 | maximum_error, |
| 626 | mean_error; |
| 627 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 628 | ssize_t |
| 629 | y; |
| 630 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 631 | status=MagickTrue; |
| 632 | alpha=1.0; |
| 633 | beta=1.0; |
| 634 | area=0.0; |
| 635 | maximum_error=0.0; |
| 636 | mean_error=0.0; |
| 637 | image_view=AcquireCacheView(image); |
| 638 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 639 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 640 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 641 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 642 | *restrict p, |
| 643 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 644 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 645 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 646 | x; |
| 647 | |
| 648 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 649 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 650 | 1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 651 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 652 | { |
| 653 | status=MagickFalse; |
| 654 | break; |
| 655 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 656 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 657 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 658 | register ssize_t |
| 659 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 660 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 661 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 662 | { |
| 663 | MagickRealType |
| 664 | distance; |
| 665 | |
| 666 | PixelChannel |
| 667 | channel; |
| 668 | |
| 669 | PixelTrait |
| 670 | reconstruct_traits, |
| 671 | traits; |
| 672 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 673 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 674 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 675 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 676 | if ((traits == UndefinedPixelTrait) || |
| 677 | (reconstruct_traits == UndefinedPixelTrait)) |
| 678 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 679 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 680 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 681 | distance=fabs((double) (alpha*p[i]-beta*GetPixelChannel( |
| 682 | reconstruct_image,channel,q))); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 683 | distortion[i]+=distance; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 684 | distortion[CompositePixelChannel]+=distance; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 685 | mean_error+=distance*distance; |
| 686 | if (distance > maximum_error) |
| 687 | maximum_error=distance; |
| 688 | area++; |
| 689 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 690 | p+=GetPixelChannels(image); |
| 691 | q+=GetPixelChannels(reconstruct_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 695 | image_view=DestroyCacheView(image_view); |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 696 | image->error.mean_error_per_pixel=distortion[CompositePixelChannel]/area; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 697 | image->error.normalized_mean_error=QuantumScale*QuantumScale*mean_error/area; |
| 698 | image->error.normalized_maximum_error=QuantumScale*maximum_error; |
| 699 | return(status); |
| 700 | } |
| 701 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 702 | static MagickBooleanType GetMeanSquaredDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 703 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 704 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 705 | CacheView |
| 706 | *image_view, |
| 707 | *reconstruct_view; |
| 708 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 709 | MagickBooleanType |
| 710 | status; |
| 711 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 712 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 713 | i; |
| 714 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 715 | ssize_t |
| 716 | y; |
| 717 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 718 | status=MagickTrue; |
| 719 | image_view=AcquireCacheView(image); |
| 720 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 721 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 722 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 723 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 724 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 725 | { |
| 726 | double |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 727 | channel_distortion[MaxPixelChannels+1]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 728 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 729 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 730 | *restrict p, |
| 731 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 732 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 733 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 734 | i, |
| 735 | x; |
| 736 | |
| 737 | if (status == MagickFalse) |
| 738 | continue; |
| 739 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 740 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 741 | 1,exception); |
| 742 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 743 | { |
| 744 | status=MagickFalse; |
| 745 | continue; |
| 746 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 748 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 749 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 750 | register ssize_t |
| 751 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 752 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 753 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 754 | { |
| 755 | MagickRealType |
| 756 | distance; |
| 757 | |
| 758 | PixelChannel |
| 759 | channel; |
| 760 | |
| 761 | PixelTrait |
| 762 | reconstruct_traits, |
| 763 | traits; |
| 764 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 765 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 766 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 767 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 768 | if ((traits == UndefinedPixelTrait) || |
| 769 | (reconstruct_traits == UndefinedPixelTrait)) |
| 770 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 771 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 772 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 773 | distance=QuantumScale*(p[i]-(MagickRealType) GetPixelChannel( |
| 774 | reconstruct_image,channel,q)); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 775 | distance*=distance; |
| 776 | channel_distortion[i]+=distance; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 777 | channel_distortion[CompositePixelChannel]+=distance; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 778 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 779 | p+=GetPixelChannels(image); |
| 780 | q+=GetPixelChannels(reconstruct_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 781 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 782 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 783 | #pragma omp critical (MagickCore_GetMeanSquaredError) |
| 784 | #endif |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 785 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 786 | distortion[i]+=channel_distortion[i]; |
| 787 | } |
| 788 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 789 | image_view=DestroyCacheView(image_view); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 790 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 791 | distortion[i]/=((double) image->columns*image->rows); |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 792 | distortion[CompositePixelChannel]/=GetImageChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 793 | return(status); |
| 794 | } |
| 795 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 796 | static MagickBooleanType GetNormalizedCrossCorrelationDistortion( |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 797 | const Image *image,const Image *reconstruct_image,double *distortion, |
| 798 | ExceptionInfo *exception) |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 799 | { |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 800 | #define SimilarityImageTag "Similarity/Image" |
| 801 | |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 802 | CacheView |
| 803 | *image_view, |
| 804 | *reconstruct_view; |
| 805 | |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 806 | ChannelStatistics |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 807 | *image_statistics, |
| 808 | *reconstruct_statistics; |
| 809 | |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 810 | MagickBooleanType |
| 811 | status; |
| 812 | |
cristy | 18a4136 | 2010-11-27 15:56:18 +0000 | [diff] [blame] | 813 | MagickOffsetType |
| 814 | progress; |
| 815 | |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 816 | MagickRealType |
| 817 | area; |
| 818 | |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 819 | register ssize_t |
| 820 | i; |
| 821 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 822 | ssize_t |
| 823 | y; |
| 824 | |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 825 | /* |
cristy | 18a4136 | 2010-11-27 15:56:18 +0000 | [diff] [blame] | 826 | Normalize to account for variation due to lighting and exposure condition. |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 827 | */ |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 828 | image_statistics=GetImageStatistics(image,exception); |
| 829 | reconstruct_statistics=GetImageStatistics(reconstruct_image,exception); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 830 | status=MagickTrue; |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 831 | progress=0; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 832 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 833 | distortion[i]=0.0; |
cristy | e28f7af | 2011-10-17 18:21:57 +0000 | [diff] [blame] | 834 | area=1.0/((MagickRealType) image->columns*image->rows-1); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 835 | image_view=AcquireCacheView(image); |
| 836 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 837 | for (y=0; y < (ssize_t) image->rows; y++) |
| 838 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 839 | register const Quantum |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 840 | *restrict p, |
| 841 | *restrict q; |
| 842 | |
| 843 | register ssize_t |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 844 | x; |
| 845 | |
| 846 | if (status == MagickFalse) |
| 847 | continue; |
| 848 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 849 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 850 | 1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 851 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 852 | { |
| 853 | status=MagickFalse; |
| 854 | continue; |
| 855 | } |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 856 | for (x=0; x < (ssize_t) image->columns; x++) |
| 857 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 858 | register ssize_t |
| 859 | i; |
| 860 | |
| 861 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 862 | { |
| 863 | PixelChannel |
| 864 | channel; |
| 865 | |
| 866 | PixelTrait |
| 867 | reconstruct_traits, |
| 868 | traits; |
| 869 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 870 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 871 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 872 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 873 | if ((traits == UndefinedPixelTrait) || |
| 874 | (reconstruct_traits == UndefinedPixelTrait)) |
| 875 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 876 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 877 | continue; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 878 | distortion[i]+=area*QuantumScale*(p[i]-image_statistics[i].mean)* |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 879 | (GetPixelChannel(reconstruct_image,channel,q)- |
| 880 | reconstruct_statistics[channel].mean); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 881 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 882 | p+=GetPixelChannels(image); |
| 883 | q+=GetPixelChannels(image); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 884 | } |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 885 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 886 | { |
| 887 | MagickBooleanType |
| 888 | proceed; |
| 889 | |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 890 | proceed=SetImageProgress(image,SimilarityImageTag,progress++, |
| 891 | image->rows); |
| 892 | if (proceed == MagickFalse) |
| 893 | status=MagickFalse; |
| 894 | } |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 895 | } |
| 896 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 897 | image_view=DestroyCacheView(image_view); |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 898 | /* |
| 899 | Divide by the standard deviation. |
| 900 | */ |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 901 | distortion[CompositePixelChannel]=0.0; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 902 | for (i=0; i < MaxPixelChannels; i++) |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 903 | { |
| 904 | MagickRealType |
cristy | 18a4136 | 2010-11-27 15:56:18 +0000 | [diff] [blame] | 905 | gamma; |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 906 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 907 | PixelChannel |
| 908 | channel; |
| 909 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 910 | channel=GetPixelChannelMapChannel(image,i); |
cristy | 18a4136 | 2010-11-27 15:56:18 +0000 | [diff] [blame] | 911 | gamma=image_statistics[i].standard_deviation* |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 912 | reconstruct_statistics[channel].standard_deviation; |
cristy | 18a4136 | 2010-11-27 15:56:18 +0000 | [diff] [blame] | 913 | gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma); |
| 914 | distortion[i]=QuantumRange*gamma*distortion[i]; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 915 | distortion[CompositePixelChannel]+=distortion[i]*distortion[i]; |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 916 | } |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 917 | distortion[CompositePixelChannel]=sqrt(distortion[CompositePixelChannel]/ |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 918 | GetImageChannels(image)); |
cristy | 34d6fdc | 2010-11-26 19:06:08 +0000 | [diff] [blame] | 919 | /* |
| 920 | Free resources. |
| 921 | */ |
cristy | 9f48ca6 | 2010-11-25 03:06:31 +0000 | [diff] [blame] | 922 | reconstruct_statistics=(ChannelStatistics *) RelinquishMagickMemory( |
| 923 | reconstruct_statistics); |
| 924 | image_statistics=(ChannelStatistics *) RelinquishMagickMemory( |
| 925 | image_statistics); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 926 | return(status); |
| 927 | } |
| 928 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 929 | static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 930 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 931 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 932 | CacheView |
| 933 | *image_view, |
| 934 | *reconstruct_view; |
| 935 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 936 | MagickBooleanType |
| 937 | status; |
| 938 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 939 | ssize_t |
| 940 | y; |
| 941 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 942 | status=MagickTrue; |
| 943 | image_view=AcquireCacheView(image); |
| 944 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 945 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 946 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 947 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 948 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 949 | { |
| 950 | double |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 951 | channel_distortion[MaxPixelChannels+1]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 952 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 953 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 954 | *restrict p, |
| 955 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 956 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 957 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 958 | i, |
| 959 | x; |
| 960 | |
| 961 | if (status == MagickFalse) |
| 962 | continue; |
| 963 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 964 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y, |
| 965 | reconstruct_image->columns,1,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 966 | if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 967 | { |
| 968 | status=MagickFalse; |
| 969 | continue; |
| 970 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 971 | (void) ResetMagickMemory(channel_distortion,0,sizeof(channel_distortion)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 972 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 973 | { |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 974 | register ssize_t |
| 975 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 976 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 977 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 978 | { |
| 979 | MagickRealType |
| 980 | distance; |
| 981 | |
| 982 | PixelChannel |
| 983 | channel; |
| 984 | |
| 985 | PixelTrait |
| 986 | reconstruct_traits, |
| 987 | traits; |
| 988 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 989 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 990 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 991 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 992 | if ((traits == UndefinedPixelTrait) || |
| 993 | (reconstruct_traits == UndefinedPixelTrait)) |
| 994 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 995 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 996 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 997 | distance=QuantumScale*fabs(p[i]-(MagickRealType) GetPixelChannel( |
| 998 | reconstruct_image,channel,q)); |
cristy | 25a5f2f | 2011-09-24 14:09:43 +0000 | [diff] [blame] | 999 | if (distance > channel_distortion[i]) |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1000 | channel_distortion[i]=distance; |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 1001 | if (distance > channel_distortion[CompositePixelChannel]) |
| 1002 | channel_distortion[CompositePixelChannel]=distance; |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1003 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1004 | p+=GetPixelChannels(image); |
| 1005 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1006 | } |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1007 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1008 | #pragma omp critical (MagickCore_GetPeakAbsoluteError) |
| 1009 | #endif |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1010 | for (i=0; i <= MaxPixelChannels; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1011 | if (channel_distortion[i] > distortion[i]) |
| 1012 | distortion[i]=channel_distortion[i]; |
| 1013 | } |
| 1014 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 1015 | image_view=DestroyCacheView(image_view); |
| 1016 | return(status); |
| 1017 | } |
| 1018 | |
| 1019 | static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1020 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1021 | { |
| 1022 | MagickBooleanType |
| 1023 | status; |
| 1024 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1025 | register ssize_t |
| 1026 | i; |
| 1027 | |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1028 | status=GetMeanSquaredDistortion(image,reconstruct_image,distortion,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1029 | for (i=0; i <= MaxPixelChannels; i++) |
| 1030 | distortion[i]=20.0*log10((double) 1.0/sqrt(distortion[i])); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1031 | return(status); |
| 1032 | } |
| 1033 | |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1034 | static MagickBooleanType GetRootMeanSquaredDistortion(const Image *image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1035 | const Image *reconstruct_image,double *distortion,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | { |
| 1037 | MagickBooleanType |
| 1038 | status; |
| 1039 | |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1040 | register ssize_t |
| 1041 | i; |
| 1042 | |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1043 | status=GetMeanSquaredDistortion(image,reconstruct_image,distortion,exception); |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1044 | for (i=0; i <= MaxPixelChannels; i++) |
| 1045 | distortion[i]=sqrt(distortion[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1046 | return(status); |
| 1047 | } |
| 1048 | |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1049 | MagickExport MagickBooleanType GetImageDistortion(Image *image, |
| 1050 | const Image *reconstruct_image,const MetricType metric,double *distortion, |
| 1051 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1052 | { |
| 1053 | double |
| 1054 | *channel_distortion; |
| 1055 | |
| 1056 | MagickBooleanType |
| 1057 | status; |
| 1058 | |
| 1059 | size_t |
| 1060 | length; |
| 1061 | |
| 1062 | assert(image != (Image *) NULL); |
| 1063 | assert(image->signature == MagickSignature); |
| 1064 | if (image->debug != MagickFalse) |
| 1065 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1066 | assert(reconstruct_image != (const Image *) NULL); |
| 1067 | assert(reconstruct_image->signature == MagickSignature); |
| 1068 | assert(distortion != (double *) NULL); |
| 1069 | *distortion=0.0; |
| 1070 | if (image->debug != MagickFalse) |
| 1071 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1072 | if ((reconstruct_image->columns != image->columns) || |
| 1073 | (reconstruct_image->rows != image->rows)) |
| 1074 | ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename); |
| 1075 | /* |
| 1076 | Get image distortion. |
| 1077 | */ |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1078 | length=MaxPixelChannels+1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1079 | channel_distortion=(double *) AcquireQuantumMemory(length, |
| 1080 | sizeof(*channel_distortion)); |
| 1081 | if (channel_distortion == (double *) NULL) |
| 1082 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1083 | (void) ResetMagickMemory(channel_distortion,0,length* |
| 1084 | sizeof(*channel_distortion)); |
| 1085 | switch (metric) |
| 1086 | { |
| 1087 | case AbsoluteErrorMetric: |
| 1088 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1089 | status=GetAbsoluteDistortion(image,reconstruct_image,channel_distortion, |
| 1090 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | } |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 1093 | case FuzzErrorMetric: |
| 1094 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1095 | status=GetFuzzDistortion(image,reconstruct_image,channel_distortion, |
| 1096 | exception); |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 1097 | break; |
| 1098 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1099 | case MeanAbsoluteErrorMetric: |
| 1100 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1101 | status=GetMeanAbsoluteDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1102 | channel_distortion,exception); |
| 1103 | break; |
| 1104 | } |
| 1105 | case MeanErrorPerPixelMetric: |
| 1106 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1107 | status=GetMeanErrorPerPixel(image,reconstruct_image,channel_distortion, |
| 1108 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1109 | break; |
| 1110 | } |
| 1111 | case MeanSquaredErrorMetric: |
| 1112 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1113 | status=GetMeanSquaredDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1114 | channel_distortion,exception); |
| 1115 | break; |
| 1116 | } |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1117 | case NormalizedCrossCorrelationErrorMetric: |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1118 | default: |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1119 | { |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1120 | status=GetNormalizedCrossCorrelationDistortion(image,reconstruct_image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1121 | channel_distortion,exception); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1122 | break; |
| 1123 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | case PeakAbsoluteErrorMetric: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1125 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1126 | status=GetPeakAbsoluteDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1127 | channel_distortion,exception); |
| 1128 | break; |
| 1129 | } |
| 1130 | case PeakSignalToNoiseRatioMetric: |
| 1131 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1132 | status=GetPeakSignalToNoiseRatio(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1133 | channel_distortion,exception); |
| 1134 | break; |
| 1135 | } |
| 1136 | case RootMeanSquaredErrorMetric: |
| 1137 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1138 | status=GetRootMeanSquaredDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1139 | channel_distortion,exception); |
| 1140 | break; |
| 1141 | } |
| 1142 | } |
cristy | 5f95f4f | 2011-10-23 01:01:01 +0000 | [diff] [blame] | 1143 | *distortion=channel_distortion[CompositePixelChannel]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1144 | channel_distortion=(double *) RelinquishMagickMemory(channel_distortion); |
| 1145 | return(status); |
| 1146 | } |
| 1147 | |
| 1148 | /* |
| 1149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1150 | % % |
| 1151 | % % |
| 1152 | % % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1153 | % G e t I m a g e D i s t o r t i o n s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1154 | % % |
| 1155 | % % |
| 1156 | % % |
| 1157 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1158 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1159 | % GetImageDistrortion() compares the pixel channels of an image to a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1160 | % reconstructed image and returns the specified distortion metric for each |
| 1161 | % channel. |
| 1162 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1163 | % The format of the CompareImages method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1164 | % |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1165 | % double *GetImageDistortions(const Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1166 | % const Image *reconstruct_image,const MetricType metric, |
| 1167 | % ExceptionInfo *exception) |
| 1168 | % |
| 1169 | % A description of each parameter follows: |
| 1170 | % |
| 1171 | % o image: the image. |
| 1172 | % |
| 1173 | % o reconstruct_image: the reconstruct image. |
| 1174 | % |
| 1175 | % o metric: the metric. |
| 1176 | % |
| 1177 | % o exception: return any errors or warnings in this structure. |
| 1178 | % |
| 1179 | */ |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1180 | MagickExport double *GetImageDistortions(Image *image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1181 | const Image *reconstruct_image,const MetricType metric, |
| 1182 | ExceptionInfo *exception) |
| 1183 | { |
| 1184 | double |
| 1185 | *channel_distortion; |
| 1186 | |
| 1187 | MagickBooleanType |
| 1188 | status; |
| 1189 | |
| 1190 | size_t |
| 1191 | length; |
| 1192 | |
| 1193 | assert(image != (Image *) NULL); |
| 1194 | assert(image->signature == MagickSignature); |
| 1195 | if (image->debug != MagickFalse) |
| 1196 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1197 | assert(reconstruct_image != (const Image *) NULL); |
| 1198 | assert(reconstruct_image->signature == MagickSignature); |
| 1199 | if (image->debug != MagickFalse) |
| 1200 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1201 | if ((reconstruct_image->columns != image->columns) || |
| 1202 | (reconstruct_image->rows != image->rows)) |
| 1203 | { |
cristy | c82a27b | 2011-10-21 01:07:16 +0000 | [diff] [blame] | 1204 | (void) ThrowMagickException(exception,GetMagickModule(),ImageError, |
| 1205 | "ImageSizeDiffers","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1206 | return((double *) NULL); |
| 1207 | } |
| 1208 | /* |
| 1209 | Get image distortion. |
| 1210 | */ |
cristy | 3fc482f | 2011-09-23 00:43:35 +0000 | [diff] [blame] | 1211 | length=MaxPixelChannels+1UL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1212 | channel_distortion=(double *) AcquireQuantumMemory(length, |
| 1213 | sizeof(*channel_distortion)); |
| 1214 | if (channel_distortion == (double *) NULL) |
| 1215 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1216 | (void) ResetMagickMemory(channel_distortion,0,length* |
| 1217 | sizeof(*channel_distortion)); |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 1218 | status=MagickTrue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1219 | switch (metric) |
| 1220 | { |
| 1221 | case AbsoluteErrorMetric: |
| 1222 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1223 | status=GetAbsoluteDistortion(image,reconstruct_image,channel_distortion, |
| 1224 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1225 | break; |
| 1226 | } |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 1227 | case FuzzErrorMetric: |
| 1228 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1229 | status=GetFuzzDistortion(image,reconstruct_image,channel_distortion, |
| 1230 | exception); |
cristy | 343eee9 | 2010-12-11 02:17:57 +0000 | [diff] [blame] | 1231 | break; |
| 1232 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1233 | case MeanAbsoluteErrorMetric: |
| 1234 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1235 | status=GetMeanAbsoluteDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1236 | channel_distortion,exception); |
| 1237 | break; |
| 1238 | } |
| 1239 | case MeanErrorPerPixelMetric: |
| 1240 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1241 | status=GetMeanErrorPerPixel(image,reconstruct_image,channel_distortion, |
| 1242 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1243 | break; |
| 1244 | } |
| 1245 | case MeanSquaredErrorMetric: |
| 1246 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1247 | status=GetMeanSquaredDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1248 | channel_distortion,exception); |
| 1249 | break; |
| 1250 | } |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1251 | case NormalizedCrossCorrelationErrorMetric: |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1252 | default: |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1253 | { |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1254 | status=GetNormalizedCrossCorrelationDistortion(image,reconstruct_image, |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1255 | channel_distortion,exception); |
cristy | 4c929a7 | 2010-11-24 18:54:42 +0000 | [diff] [blame] | 1256 | break; |
| 1257 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1258 | case PeakAbsoluteErrorMetric: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1259 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1260 | status=GetPeakAbsoluteDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | channel_distortion,exception); |
| 1262 | break; |
| 1263 | } |
| 1264 | case PeakSignalToNoiseRatioMetric: |
| 1265 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1266 | status=GetPeakSignalToNoiseRatio(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1267 | channel_distortion,exception); |
| 1268 | break; |
| 1269 | } |
| 1270 | case RootMeanSquaredErrorMetric: |
| 1271 | { |
cristy | 8a9106f | 2011-07-05 14:39:26 +0000 | [diff] [blame] | 1272 | status=GetRootMeanSquaredDistortion(image,reconstruct_image, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1273 | channel_distortion,exception); |
| 1274 | break; |
| 1275 | } |
| 1276 | } |
cristy | da16f16 | 2011-02-19 23:52:17 +0000 | [diff] [blame] | 1277 | if (status == MagickFalse) |
| 1278 | { |
| 1279 | channel_distortion=(double *) RelinquishMagickMemory(channel_distortion); |
| 1280 | return((double *) NULL); |
| 1281 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1282 | return(channel_distortion); |
| 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1287 | % % |
| 1288 | % % |
| 1289 | % % |
| 1290 | % I s I m a g e s E q u a l % |
| 1291 | % % |
| 1292 | % % |
| 1293 | % % |
| 1294 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1295 | % |
| 1296 | % IsImagesEqual() measures the difference between colors at each pixel |
| 1297 | % location of two images. A value other than 0 means the colors match |
| 1298 | % exactly. Otherwise an error measure is computed by summing over all |
| 1299 | % pixels in an image the distance squared in RGB space between each image |
| 1300 | % pixel and its corresponding pixel in the reconstruct image. The error |
| 1301 | % measure is assigned to these image members: |
| 1302 | % |
| 1303 | % o mean_error_per_pixel: The mean error for any single pixel in |
| 1304 | % the image. |
| 1305 | % |
| 1306 | % o normalized_mean_error: The normalized mean quantization error for |
| 1307 | % any single pixel in the image. This distance measure is normalized to |
| 1308 | % a range between 0 and 1. It is independent of the range of red, green, |
| 1309 | % and blue values in the image. |
| 1310 | % |
| 1311 | % o normalized_maximum_error: The normalized maximum quantization |
| 1312 | % error for any single pixel in the image. This distance measure is |
| 1313 | % normalized to a range between 0 and 1. It is independent of the range |
| 1314 | % of red, green, and blue values in your image. |
| 1315 | % |
| 1316 | % A small normalized mean square error, accessed as |
| 1317 | % image->normalized_mean_error, suggests the images are very similar in |
| 1318 | % spatial layout and color. |
| 1319 | % |
| 1320 | % The format of the IsImagesEqual method is: |
| 1321 | % |
| 1322 | % MagickBooleanType IsImagesEqual(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1323 | % const Image *reconstruct_image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1324 | % |
| 1325 | % A description of each parameter follows. |
| 1326 | % |
| 1327 | % o image: the image. |
| 1328 | % |
| 1329 | % o reconstruct_image: the reconstruct image. |
| 1330 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1331 | % o exception: return any errors or warnings in this structure. |
| 1332 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1333 | */ |
| 1334 | MagickExport MagickBooleanType IsImagesEqual(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1335 | const Image *reconstruct_image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1336 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 1337 | CacheView |
| 1338 | *image_view, |
| 1339 | *reconstruct_view; |
| 1340 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1341 | MagickBooleanType |
| 1342 | status; |
| 1343 | |
| 1344 | MagickRealType |
| 1345 | area, |
| 1346 | maximum_error, |
| 1347 | mean_error, |
| 1348 | mean_error_per_pixel; |
| 1349 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1350 | ssize_t |
| 1351 | y; |
| 1352 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1353 | assert(image != (Image *) NULL); |
| 1354 | assert(image->signature == MagickSignature); |
| 1355 | assert(reconstruct_image != (const Image *) NULL); |
| 1356 | assert(reconstruct_image->signature == MagickSignature); |
| 1357 | if ((reconstruct_image->columns != image->columns) || |
| 1358 | (reconstruct_image->rows != image->rows)) |
| 1359 | ThrowBinaryException(ImageError,"ImageSizeDiffers",image->filename); |
| 1360 | area=0.0; |
| 1361 | maximum_error=0.0; |
| 1362 | mean_error_per_pixel=0.0; |
| 1363 | mean_error=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1364 | image_view=AcquireCacheView(image); |
| 1365 | reconstruct_view=AcquireCacheView(reconstruct_image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1366 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1367 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1368 | register const Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1369 | *restrict p, |
| 1370 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1371 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1372 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1373 | x; |
| 1374 | |
| 1375 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
| 1376 | q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns, |
| 1377 | 1,exception); |
cristy | acd2ed2 | 2011-08-30 01:44:23 +0000 | [diff] [blame] | 1378 | if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1379 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1380 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1381 | { |
cristy | d5c15f9 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 1382 | register ssize_t |
| 1383 | i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1384 | |
cristy | d5c15f9 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 1385 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1386 | { |
| 1387 | MagickRealType |
| 1388 | distance; |
| 1389 | |
| 1390 | PixelChannel |
| 1391 | channel; |
| 1392 | |
| 1393 | PixelTrait |
| 1394 | reconstruct_traits, |
| 1395 | traits; |
| 1396 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 1397 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 1398 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | d5c15f9 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 1399 | reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel); |
| 1400 | if ((traits == UndefinedPixelTrait) || |
| 1401 | (reconstruct_traits == UndefinedPixelTrait)) |
| 1402 | continue; |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1403 | if ((reconstruct_traits & UpdatePixelTrait) == 0) |
| 1404 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 1405 | distance=fabs(p[i]-(MagickRealType) GetPixelChannel(reconstruct_image, |
| 1406 | channel,q)); |
cristy | d5c15f9 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 1407 | mean_error_per_pixel+=distance; |
| 1408 | mean_error+=distance*distance; |
| 1409 | if (distance > maximum_error) |
| 1410 | maximum_error=distance; |
| 1411 | area++; |
| 1412 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1413 | p+=GetPixelChannels(image); |
| 1414 | q+=GetPixelChannels(reconstruct_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1415 | } |
| 1416 | } |
| 1417 | reconstruct_view=DestroyCacheView(reconstruct_view); |
| 1418 | image_view=DestroyCacheView(image_view); |
| 1419 | image->error.mean_error_per_pixel=(double) (mean_error_per_pixel/area); |
| 1420 | image->error.normalized_mean_error=(double) (QuantumScale*QuantumScale* |
| 1421 | mean_error/area); |
| 1422 | image->error.normalized_maximum_error=(double) (QuantumScale*maximum_error); |
| 1423 | status=image->error.mean_error_per_pixel == 0.0 ? MagickTrue : MagickFalse; |
| 1424 | return(status); |
| 1425 | } |
| 1426 | |
| 1427 | /* |
| 1428 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1429 | % % |
| 1430 | % % |
| 1431 | % % |
| 1432 | % S i m i l a r i t y I m a g e % |
| 1433 | % % |
| 1434 | % % |
| 1435 | % % |
| 1436 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1437 | % |
| 1438 | % SimilarityImage() compares the reference image of the image and returns the |
| 1439 | % best match offset. In addition, it returns a similarity image such that an |
| 1440 | % exact match location is completely white and if none of the pixels match, |
| 1441 | % black, otherwise some gray level in-between. |
| 1442 | % |
| 1443 | % The format of the SimilarityImageImage method is: |
| 1444 | % |
| 1445 | % Image *SimilarityImage(const Image *image,const Image *reference, |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1446 | % const MetricType metric,RectangleInfo *offset,double *similarity, |
| 1447 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1448 | % |
| 1449 | % A description of each parameter follows: |
| 1450 | % |
| 1451 | % o image: the image. |
| 1452 | % |
| 1453 | % o reference: find an area of the image that closely resembles this image. |
| 1454 | % |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1455 | % o metric: the metric. |
| 1456 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1457 | % o the best match offset of the reference image within the image. |
| 1458 | % |
| 1459 | % o similarity: the computed similarity between the images. |
| 1460 | % |
| 1461 | % o exception: return any errors or warnings in this structure. |
| 1462 | % |
| 1463 | */ |
| 1464 | |
| 1465 | static double GetSimilarityMetric(const Image *image,const Image *reference, |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1466 | const MetricType metric,const ssize_t x_offset,const ssize_t y_offset, |
| 1467 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1468 | { |
| 1469 | double |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1470 | distortion; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1471 | |
cristy | 713ff21 | 2010-11-26 21:56:11 +0000 | [diff] [blame] | 1472 | Image |
| 1473 | *similarity_image; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1474 | |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1475 | MagickBooleanType |
| 1476 | status; |
| 1477 | |
cristy | 713ff21 | 2010-11-26 21:56:11 +0000 | [diff] [blame] | 1478 | RectangleInfo |
| 1479 | geometry; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | |
cristy | 713ff21 | 2010-11-26 21:56:11 +0000 | [diff] [blame] | 1481 | SetGeometry(reference,&geometry); |
| 1482 | geometry.x=x_offset; |
| 1483 | geometry.y=y_offset; |
| 1484 | similarity_image=CropImage(image,&geometry,exception); |
| 1485 | if (similarity_image == (Image *) NULL) |
| 1486 | return(0.0); |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1487 | distortion=0.0; |
| 1488 | status=GetImageDistortion(similarity_image,reference,metric,&distortion, |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1489 | exception); |
cristy | 713ff21 | 2010-11-26 21:56:11 +0000 | [diff] [blame] | 1490 | similarity_image=DestroyImage(similarity_image); |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1491 | if (status == MagickFalse) |
| 1492 | return(0.0); |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1493 | return(distortion); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | MagickExport Image *SimilarityImage(Image *image,const Image *reference, |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1497 | const MetricType metric,RectangleInfo *offset,double *similarity_metric, |
| 1498 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1499 | { |
| 1500 | #define SimilarityImageTag "Similarity/Image" |
| 1501 | |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 1502 | CacheView |
| 1503 | *similarity_view; |
| 1504 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1505 | Image |
| 1506 | *similarity_image; |
| 1507 | |
| 1508 | MagickBooleanType |
| 1509 | status; |
| 1510 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1511 | MagickOffsetType |
| 1512 | progress; |
| 1513 | |
| 1514 | ssize_t |
| 1515 | y; |
| 1516 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1517 | assert(image != (const Image *) NULL); |
| 1518 | assert(image->signature == MagickSignature); |
| 1519 | if (image->debug != MagickFalse) |
| 1520 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1521 | assert(exception != (ExceptionInfo *) NULL); |
| 1522 | assert(exception->signature == MagickSignature); |
| 1523 | assert(offset != (RectangleInfo *) NULL); |
| 1524 | SetGeometry(reference,offset); |
| 1525 | *similarity_metric=1.0; |
cristy | f9255b9 | 2010-08-14 22:59:00 +0000 | [diff] [blame] | 1526 | if ((reference->columns > image->columns) || (reference->rows > image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1527 | ThrowImageException(ImageError,"ImageSizeDiffers"); |
| 1528 | similarity_image=CloneImage(image,image->columns-reference->columns+1, |
| 1529 | image->rows-reference->rows+1,MagickTrue,exception); |
| 1530 | if (similarity_image == (Image *) NULL) |
| 1531 | return((Image *) NULL); |
cristy | d5c15f9 | 2011-09-23 00:58:33 +0000 | [diff] [blame] | 1532 | status=SetImageStorageClass(similarity_image,DirectClass,exception); |
| 1533 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1534 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1535 | similarity_image=DestroyImage(similarity_image); |
| 1536 | return((Image *) NULL); |
| 1537 | } |
| 1538 | /* |
| 1539 | Measure similarity of reference image against image. |
| 1540 | */ |
| 1541 | status=MagickTrue; |
| 1542 | progress=0; |
| 1543 | similarity_view=AcquireCacheView(similarity_image); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1544 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 1545 | #pragma omp parallel for schedule(dynamic,4) shared(progress,status) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1546 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1547 | for (y=0; y < (ssize_t) (image->rows-reference->rows+1); y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1548 | { |
| 1549 | double |
| 1550 | similarity; |
| 1551 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1552 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1553 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1554 | |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1555 | register ssize_t |
| 1556 | x; |
| 1557 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1558 | if (status == MagickFalse) |
| 1559 | continue; |
cristy | 3cc758f | 2010-11-27 01:33:49 +0000 | [diff] [blame] | 1560 | q=GetCacheViewAuthenticPixels(similarity_view,0,y,similarity_image->columns, |
| 1561 | 1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1562 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | { |
| 1564 | status=MagickFalse; |
| 1565 | continue; |
| 1566 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1567 | for (x=0; x < (ssize_t) (image->columns-reference->columns+1); x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1568 | { |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1569 | register ssize_t |
| 1570 | i; |
| 1571 | |
cristy | 0913681 | 2011-10-18 15:24:30 +0000 | [diff] [blame] | 1572 | similarity=GetSimilarityMetric(image,reference,metric,x,y,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1573 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1574 | #pragma omp critical (MagickCore_SimilarityImage) |
| 1575 | #endif |
| 1576 | if (similarity < *similarity_metric) |
| 1577 | { |
| 1578 | *similarity_metric=similarity; |
| 1579 | offset->x=x; |
| 1580 | offset->y=y; |
| 1581 | } |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1582 | for (i=0; i < (ssize_t) GetPixelChannels(image); i++) |
| 1583 | { |
| 1584 | PixelChannel |
| 1585 | channel; |
| 1586 | |
| 1587 | PixelTrait |
| 1588 | similarity_traits, |
| 1589 | traits; |
| 1590 | |
cristy | e2a912b | 2011-12-05 20:02:07 +0000 | [diff] [blame] | 1591 | channel=GetPixelChannelMapChannel(image,i); |
cristy | abace41 | 2011-12-11 15:56:53 +0000 | [diff] [blame] | 1592 | traits=GetPixelChannelMapTraits(image,channel); |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1593 | similarity_traits=GetPixelChannelMapTraits(similarity_image,channel); |
| 1594 | if ((traits == UndefinedPixelTrait) || |
| 1595 | (similarity_traits == UndefinedPixelTrait)) |
| 1596 | continue; |
| 1597 | if ((similarity_traits & UpdatePixelTrait) == 0) |
| 1598 | continue; |
cristy | 0beccfa | 2011-09-25 20:47:53 +0000 | [diff] [blame] | 1599 | SetPixelChannel(similarity_image,channel,ClampToQuantum(QuantumRange- |
| 1600 | QuantumRange*similarity),q); |
cristy | 49dd6a0 | 2011-09-24 23:08:01 +0000 | [diff] [blame] | 1601 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1602 | q+=GetPixelChannels(similarity_image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1603 | } |
| 1604 | if (SyncCacheViewAuthenticPixels(similarity_view,exception) == MagickFalse) |
| 1605 | status=MagickFalse; |
| 1606 | if (image->progress_monitor != (MagickProgressMonitor) NULL) |
| 1607 | { |
| 1608 | MagickBooleanType |
| 1609 | proceed; |
| 1610 | |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1611 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | #pragma omp critical (MagickCore_SimilarityImage) |
| 1613 | #endif |
| 1614 | proceed=SetImageProgress(image,SimilarityImageTag,progress++, |
| 1615 | image->rows); |
| 1616 | if (proceed == MagickFalse) |
| 1617 | status=MagickFalse; |
| 1618 | } |
| 1619 | } |
| 1620 | similarity_view=DestroyCacheView(similarity_view); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1621 | return(similarity_image); |
| 1622 | } |