cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % % |
| 6 | % FFFFF EEEEE AAA TTTTT U U RRRR EEEEE % |
| 7 | % F E A A T U U R R E % |
| 8 | % FFF EEE AAAAA T U U RRRR EEE % |
| 9 | % F E A A T U U R R E % |
| 10 | % F EEEEE A A T UUU R R EEEEE % |
| 11 | % % |
| 12 | % % |
| 13 | % MagickCore Image Feature Methods % |
| 14 | % % |
| 15 | % Software Design % |
| 16 | % John Cristy % |
| 17 | % July 1992 % |
| 18 | % % |
| 19 | % % |
cristy | 1454be7 | 2011-12-19 01:52:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3e2860c | 2010-01-24 01:36:30 +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/property.h" |
| 45 | #include "MagickCore/animate.h" |
| 46 | #include "MagickCore/blob.h" |
| 47 | #include "MagickCore/blob-private.h" |
| 48 | #include "MagickCore/cache.h" |
| 49 | #include "MagickCore/cache-private.h" |
| 50 | #include "MagickCore/cache-view.h" |
| 51 | #include "MagickCore/client.h" |
| 52 | #include "MagickCore/color.h" |
| 53 | #include "MagickCore/color-private.h" |
| 54 | #include "MagickCore/colorspace.h" |
| 55 | #include "MagickCore/colorspace-private.h" |
| 56 | #include "MagickCore/composite.h" |
| 57 | #include "MagickCore/composite-private.h" |
| 58 | #include "MagickCore/compress.h" |
| 59 | #include "MagickCore/constitute.h" |
| 60 | #include "MagickCore/display.h" |
| 61 | #include "MagickCore/draw.h" |
| 62 | #include "MagickCore/enhance.h" |
| 63 | #include "MagickCore/exception.h" |
| 64 | #include "MagickCore/exception-private.h" |
| 65 | #include "MagickCore/feature.h" |
| 66 | #include "MagickCore/gem.h" |
| 67 | #include "MagickCore/geometry.h" |
| 68 | #include "MagickCore/list.h" |
| 69 | #include "MagickCore/image-private.h" |
| 70 | #include "MagickCore/magic.h" |
| 71 | #include "MagickCore/magick.h" |
| 72 | #include "MagickCore/memory_.h" |
| 73 | #include "MagickCore/module.h" |
| 74 | #include "MagickCore/monitor.h" |
| 75 | #include "MagickCore/monitor-private.h" |
| 76 | #include "MagickCore/option.h" |
| 77 | #include "MagickCore/paint.h" |
| 78 | #include "MagickCore/pixel-accessor.h" |
| 79 | #include "MagickCore/profile.h" |
| 80 | #include "MagickCore/quantize.h" |
| 81 | #include "MagickCore/quantum-private.h" |
| 82 | #include "MagickCore/random_.h" |
| 83 | #include "MagickCore/segment.h" |
| 84 | #include "MagickCore/semaphore.h" |
| 85 | #include "MagickCore/signature-private.h" |
| 86 | #include "MagickCore/string_.h" |
| 87 | #include "MagickCore/thread-private.h" |
| 88 | #include "MagickCore/timer.h" |
| 89 | #include "MagickCore/utility.h" |
| 90 | #include "MagickCore/version.h" |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 91 | |
| 92 | /* |
| 93 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 94 | % % |
| 95 | % % |
| 96 | % % |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 97 | % G e t I m a g e F e a t u r e s % |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 98 | % % |
| 99 | % % |
| 100 | % % |
| 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 | % |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 103 | % GetImageFeatures() returns features for each channel in the image in |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 104 | % each of four directions (horizontal, vertical, left and right diagonals) |
| 105 | % for the specified distance. The features include the angular second |
| 106 | % moment, contrast, correlation, sum of squares: variance, inverse difference |
| 107 | % moment, sum average, sum varience, sum entropy, entropy, difference variance,% difference entropy, information measures of correlation 1, information |
| 108 | % measures of correlation 2, and maximum correlation coefficient. You can |
| 109 | % access the red channel contrast, for example, like this: |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 110 | % |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 111 | % channel_features=GetImageFeatures(image,1,exception); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 112 | % contrast=channel_features[RedPixelChannel].contrast[0]; |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 113 | % |
| 114 | % Use MagickRelinquishMemory() to free the features buffer. |
| 115 | % |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 116 | % The format of the GetImageFeatures method is: |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 117 | % |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 118 | % ChannelFeatures *GetImageFeatures(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 119 | % const size_t distance,ExceptionInfo *exception) |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 120 | % |
| 121 | % A description of each parameter follows: |
| 122 | % |
| 123 | % o image: the image. |
| 124 | % |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 125 | % o distance: the distance. |
| 126 | % |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 127 | % o exception: return any errors or warnings in this structure. |
| 128 | % |
| 129 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 130 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 131 | static inline ssize_t MagickAbsoluteValue(const ssize_t x) |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 132 | { |
| 133 | if (x < 0) |
| 134 | return(-x); |
| 135 | return(x); |
| 136 | } |
| 137 | |
cristy | 490408a | 2011-07-07 14:42:05 +0000 | [diff] [blame] | 138 | MagickExport ChannelFeatures *GetImageFeatures(const Image *image, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 139 | const size_t distance,ExceptionInfo *exception) |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 140 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 141 | typedef struct _ChannelStatistics |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 142 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 143 | PixelInfo |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 144 | direction[4]; /* horizontal, vertical, left and right diagonals */ |
| 145 | } ChannelStatistics; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 146 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 147 | CacheView |
| 148 | *image_view; |
| 149 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 150 | ChannelFeatures |
| 151 | *channel_features; |
| 152 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 153 | ChannelStatistics |
| 154 | **cooccurrence, |
| 155 | correlation, |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 156 | *density_x, |
| 157 | *density_xy, |
| 158 | *density_y, |
| 159 | entropy_x, |
| 160 | entropy_xy, |
| 161 | entropy_xy1, |
| 162 | entropy_xy2, |
| 163 | entropy_y, |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 164 | mean, |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 165 | **Q, |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 166 | *sum, |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 167 | sum_squares, |
| 168 | variance; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 169 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 170 | PixelPacket |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 171 | gray, |
| 172 | *grays; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 173 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 174 | MagickBooleanType |
| 175 | status; |
| 176 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 177 | register ssize_t |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 178 | i; |
| 179 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 180 | size_t |
| 181 | length; |
| 182 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 183 | ssize_t |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 184 | y; |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 185 | |
cristy | ecd0ab5 | 2010-05-30 14:59:20 +0000 | [diff] [blame] | 186 | unsigned int |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 187 | number_grays; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 188 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 189 | assert(image != (Image *) NULL); |
| 190 | assert(image->signature == MagickSignature); |
| 191 | if (image->debug != MagickFalse) |
| 192 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 193 | if ((image->columns < (distance+1)) || (image->rows < (distance+1))) |
| 194 | return((ChannelFeatures *) NULL); |
cristy | 9a9230e | 2011-04-26 14:56:14 +0000 | [diff] [blame] | 195 | length=CompositeChannels+1UL; |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 196 | channel_features=(ChannelFeatures *) AcquireQuantumMemory(length, |
| 197 | sizeof(*channel_features)); |
| 198 | if (channel_features == (ChannelFeatures *) NULL) |
| 199 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 200 | (void) ResetMagickMemory(channel_features,0,length* |
| 201 | sizeof(*channel_features)); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 202 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 203 | Form grays. |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 204 | */ |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 205 | grays=(PixelPacket *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*grays)); |
| 206 | if (grays == (PixelPacket *) NULL) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 207 | { |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 208 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 209 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 210 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 211 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 212 | return(channel_features); |
| 213 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 214 | for (i=0; i <= (ssize_t) MaxMap; i++) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 215 | { |
cristy | ecd0ab5 | 2010-05-30 14:59:20 +0000 | [diff] [blame] | 216 | grays[i].red=(~0U); |
| 217 | grays[i].green=(~0U); |
| 218 | grays[i].blue=(~0U); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 219 | grays[i].alpha=(~0U); |
| 220 | grays[i].black=(~0U); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 221 | } |
| 222 | status=MagickTrue; |
| 223 | image_view=AcquireCacheView(image); |
| 224 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 225 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 226 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 227 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 228 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 229 | register const Quantum |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 230 | *restrict p; |
| 231 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 232 | register ssize_t |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 233 | x; |
| 234 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 235 | if (status == MagickFalse) |
| 236 | continue; |
| 237 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 238 | if (p == (const Quantum *) NULL) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 239 | { |
| 240 | status=MagickFalse; |
| 241 | continue; |
| 242 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 243 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 244 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 245 | grays[ScaleQuantumToMap(GetPixelRed(image,p))].red= |
| 246 | ScaleQuantumToMap(GetPixelRed(image,p)); |
| 247 | grays[ScaleQuantumToMap(GetPixelGreen(image,p))].green= |
| 248 | ScaleQuantumToMap(GetPixelGreen(image,p)); |
| 249 | grays[ScaleQuantumToMap(GetPixelBlue(image,p))].blue= |
| 250 | ScaleQuantumToMap(GetPixelBlue(image,p)); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 251 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 252 | grays[ScaleQuantumToMap(GetPixelBlack(image,p))].black= |
| 253 | ScaleQuantumToMap(GetPixelBlack(image,p)); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 254 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 255 | grays[ScaleQuantumToMap(GetPixelAlpha(image,p))].alpha= |
| 256 | ScaleQuantumToMap(GetPixelAlpha(image,p)); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 257 | p+=GetPixelChannels(image); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 258 | } |
| 259 | } |
cristy | 30c510a | 2010-01-24 03:43:00 +0000 | [diff] [blame] | 260 | image_view=DestroyCacheView(image_view); |
| 261 | if (status == MagickFalse) |
| 262 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 263 | grays=(PixelPacket *) RelinquishMagickMemory(grays); |
cristy | 30c510a | 2010-01-24 03:43:00 +0000 | [diff] [blame] | 264 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 265 | channel_features); |
| 266 | return(channel_features); |
| 267 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 268 | (void) ResetMagickMemory(&gray,0,sizeof(gray)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 269 | for (i=0; i <= (ssize_t) MaxMap; i++) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 270 | { |
cristy | ecd0ab5 | 2010-05-30 14:59:20 +0000 | [diff] [blame] | 271 | if (grays[i].red != ~0U) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 272 | grays[gray.red++].red=grays[i].red; |
cristy | ecd0ab5 | 2010-05-30 14:59:20 +0000 | [diff] [blame] | 273 | if (grays[i].green != ~0U) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 274 | grays[gray.green++].green=grays[i].green; |
cristy | ecd0ab5 | 2010-05-30 14:59:20 +0000 | [diff] [blame] | 275 | if (grays[i].blue != ~0U) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 276 | grays[gray.blue++].blue=grays[i].blue; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 277 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 278 | if (grays[i].black != ~0U) |
| 279 | grays[gray.black++].black=grays[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 280 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 281 | if (grays[i].alpha != ~0U) |
| 282 | grays[gray.alpha++].alpha=grays[i].alpha; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 283 | } |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 284 | /* |
| 285 | Allocate spatial dependence matrix. |
| 286 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 287 | number_grays=gray.red; |
| 288 | if (gray.green > number_grays) |
| 289 | number_grays=gray.green; |
| 290 | if (gray.blue > number_grays) |
| 291 | number_grays=gray.blue; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 292 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 293 | if (gray.black > number_grays) |
| 294 | number_grays=gray.black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 295 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 296 | if (gray.alpha > number_grays) |
| 297 | number_grays=gray.alpha; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 298 | cooccurrence=(ChannelStatistics **) AcquireQuantumMemory(number_grays, |
| 299 | sizeof(*cooccurrence)); |
cristy | 77173e5 | 2010-02-02 02:51:35 +0000 | [diff] [blame] | 300 | density_x=(ChannelStatistics *) AcquireQuantumMemory(2*(number_grays+1), |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 301 | sizeof(*density_x)); |
| 302 | density_xy=(ChannelStatistics *) AcquireQuantumMemory(2*(number_grays+1), |
| 303 | sizeof(*density_xy)); |
cristy | 77173e5 | 2010-02-02 02:51:35 +0000 | [diff] [blame] | 304 | density_y=(ChannelStatistics *) AcquireQuantumMemory(2*(number_grays+1), |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 305 | sizeof(*density_y)); |
| 306 | Q=(ChannelStatistics **) AcquireQuantumMemory(number_grays,sizeof(*Q)); |
| 307 | sum=(ChannelStatistics *) AcquireQuantumMemory(number_grays,sizeof(*sum)); |
| 308 | if ((cooccurrence == (ChannelStatistics **) NULL) || |
| 309 | (density_x == (ChannelStatistics *) NULL) || |
| 310 | (density_xy == (ChannelStatistics *) NULL) || |
| 311 | (density_y == (ChannelStatistics *) NULL) || |
| 312 | (Q == (ChannelStatistics **) NULL) || |
| 313 | (sum == (ChannelStatistics *) NULL)) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 314 | { |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 315 | if (Q != (ChannelStatistics **) NULL) |
| 316 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 317 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 318 | Q[i]=(ChannelStatistics *) RelinquishMagickMemory(Q[i]); |
| 319 | Q=(ChannelStatistics **) RelinquishMagickMemory(Q); |
| 320 | } |
| 321 | if (sum != (ChannelStatistics *) NULL) |
| 322 | sum=(ChannelStatistics *) RelinquishMagickMemory(sum); |
| 323 | if (density_y != (ChannelStatistics *) NULL) |
| 324 | density_y=(ChannelStatistics *) RelinquishMagickMemory(density_y); |
| 325 | if (density_xy != (ChannelStatistics *) NULL) |
| 326 | density_xy=(ChannelStatistics *) RelinquishMagickMemory(density_xy); |
| 327 | if (density_x != (ChannelStatistics *) NULL) |
| 328 | density_x=(ChannelStatistics *) RelinquishMagickMemory(density_x); |
| 329 | if (cooccurrence != (ChannelStatistics **) NULL) |
| 330 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 331 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 332 | cooccurrence[i]=(ChannelStatistics *) |
| 333 | RelinquishMagickMemory(cooccurrence[i]); |
| 334 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory( |
| 335 | cooccurrence); |
| 336 | } |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 337 | grays=(PixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 338 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 339 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 340 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 341 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 342 | return(channel_features); |
| 343 | } |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 344 | (void) ResetMagickMemory(&correlation,0,sizeof(correlation)); |
cristy | 77173e5 | 2010-02-02 02:51:35 +0000 | [diff] [blame] | 345 | (void) ResetMagickMemory(density_x,0,2*(number_grays+1)*sizeof(*density_x)); |
| 346 | (void) ResetMagickMemory(density_xy,0,2*(number_grays+1)*sizeof(*density_xy)); |
| 347 | (void) ResetMagickMemory(density_y,0,2*(number_grays+1)*sizeof(*density_y)); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 348 | (void) ResetMagickMemory(&mean,0,sizeof(mean)); |
| 349 | (void) ResetMagickMemory(sum,0,number_grays*sizeof(*sum)); |
| 350 | (void) ResetMagickMemory(&sum_squares,0,sizeof(sum_squares)); |
| 351 | (void) ResetMagickMemory(density_xy,0,2*number_grays*sizeof(*density_xy)); |
| 352 | (void) ResetMagickMemory(&entropy_x,0,sizeof(entropy_x)); |
| 353 | (void) ResetMagickMemory(&entropy_xy,0,sizeof(entropy_xy)); |
| 354 | (void) ResetMagickMemory(&entropy_xy1,0,sizeof(entropy_xy1)); |
| 355 | (void) ResetMagickMemory(&entropy_xy2,0,sizeof(entropy_xy2)); |
| 356 | (void) ResetMagickMemory(&entropy_y,0,sizeof(entropy_y)); |
| 357 | (void) ResetMagickMemory(&variance,0,sizeof(variance)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 358 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 359 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 360 | cooccurrence[i]=(ChannelStatistics *) AcquireQuantumMemory(number_grays, |
| 361 | sizeof(**cooccurrence)); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 362 | Q[i]=(ChannelStatistics *) AcquireQuantumMemory(number_grays,sizeof(**Q)); |
| 363 | if ((cooccurrence[i] == (ChannelStatistics *) NULL) || |
| 364 | (Q[i] == (ChannelStatistics *) NULL)) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 365 | break; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 366 | (void) ResetMagickMemory(cooccurrence[i],0,number_grays* |
cristy | 3749be4 | 2010-02-02 02:46:51 +0000 | [diff] [blame] | 367 | sizeof(**cooccurrence)); |
| 368 | (void) ResetMagickMemory(Q[i],0,number_grays*sizeof(**Q)); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 369 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 370 | if (i < (ssize_t) number_grays) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 371 | { |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 372 | for (i--; i >= 0; i--) |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 373 | { |
| 374 | if (Q[i] != (ChannelStatistics *) NULL) |
| 375 | Q[i]=(ChannelStatistics *) RelinquishMagickMemory(Q[i]); |
| 376 | if (cooccurrence[i] != (ChannelStatistics *) NULL) |
| 377 | cooccurrence[i]=(ChannelStatistics *) |
| 378 | RelinquishMagickMemory(cooccurrence[i]); |
| 379 | } |
| 380 | Q=(ChannelStatistics **) RelinquishMagickMemory(Q); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 381 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 382 | sum=(ChannelStatistics *) RelinquishMagickMemory(sum); |
| 383 | density_y=(ChannelStatistics *) RelinquishMagickMemory(density_y); |
| 384 | density_xy=(ChannelStatistics *) RelinquishMagickMemory(density_xy); |
| 385 | density_x=(ChannelStatistics *) RelinquishMagickMemory(density_x); |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 386 | grays=(PixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 387 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 388 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 389 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 390 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 391 | return(channel_features); |
| 392 | } |
| 393 | /* |
| 394 | Initialize spatial dependence matrix. |
| 395 | */ |
| 396 | status=MagickTrue; |
| 397 | image_view=AcquireCacheView(image); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 398 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 399 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 400 | register const Quantum |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 401 | *restrict p; |
| 402 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 403 | register ssize_t |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 404 | x; |
| 405 | |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 406 | ssize_t |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 407 | i, |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 408 | offset, |
| 409 | u, |
| 410 | v; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 411 | |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 412 | if (status == MagickFalse) |
| 413 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 414 | p=GetCacheViewVirtualPixels(image_view,-(ssize_t) distance,y,image->columns+ |
cristy | a1d2bd3 | 2011-10-19 22:12:25 +0000 | [diff] [blame] | 415 | 2*distance,distance+2,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 416 | if (p == (const Quantum *) NULL) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 417 | { |
| 418 | status=MagickFalse; |
| 419 | continue; |
| 420 | } |
cristy | 8a11cb1 | 2011-10-19 23:53:34 +0000 | [diff] [blame] | 421 | p+=distance*GetPixelChannels(image);; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 422 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 423 | { |
| 424 | for (i=0; i < 4; i++) |
| 425 | { |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 426 | switch (i) |
| 427 | { |
| 428 | case 0: |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 429 | default: |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 430 | { |
| 431 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 432 | Horizontal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 433 | */ |
| 434 | offset=(ssize_t) distance; |
| 435 | break; |
| 436 | } |
| 437 | case 1: |
| 438 | { |
| 439 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 440 | Vertical adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 441 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 442 | offset=(ssize_t) (image->columns+2*distance); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 443 | break; |
| 444 | } |
| 445 | case 2: |
| 446 | { |
| 447 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 448 | Right diagonal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 449 | */ |
cristy | d99b096 | 2010-05-29 23:14:26 +0000 | [diff] [blame] | 450 | offset=(ssize_t) ((image->columns+2*distance)-distance); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 451 | break; |
| 452 | } |
| 453 | case 3: |
| 454 | { |
| 455 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 456 | Left diagonal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 457 | */ |
cristy | d99b096 | 2010-05-29 23:14:26 +0000 | [diff] [blame] | 458 | offset=(ssize_t) ((image->columns+2*distance)+distance); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 459 | break; |
| 460 | } |
| 461 | } |
| 462 | u=0; |
| 463 | v=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 464 | while (grays[u].red != ScaleQuantumToMap(GetPixelRed(image,p))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 465 | u++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 466 | while (grays[v].red != ScaleQuantumToMap(GetPixelRed(image,p+offset*GetPixelChannels(image)))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 467 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 468 | cooccurrence[u][v].direction[i].red++; |
| 469 | cooccurrence[v][u].direction[i].red++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 470 | u=0; |
| 471 | v=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 472 | while (grays[u].green != ScaleQuantumToMap(GetPixelGreen(image,p))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 473 | u++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 474 | while (grays[v].green != ScaleQuantumToMap(GetPixelGreen(image,p+offset*GetPixelChannels(image)))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 475 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 476 | cooccurrence[u][v].direction[i].green++; |
| 477 | cooccurrence[v][u].direction[i].green++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 478 | u=0; |
| 479 | v=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 480 | while (grays[u].blue != ScaleQuantumToMap(GetPixelBlue(image,p))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 481 | u++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 482 | while (grays[v].blue != ScaleQuantumToMap(GetPixelBlue(image,p+offset*GetPixelChannels(image)))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 483 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 484 | cooccurrence[u][v].direction[i].blue++; |
| 485 | cooccurrence[v][u].direction[i].blue++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 486 | if (image->colorspace == CMYKColorspace) |
| 487 | { |
| 488 | u=0; |
| 489 | v=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 490 | while (grays[u].black != ScaleQuantumToMap(GetPixelBlack(image,p))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 491 | u++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 492 | while (grays[v].black != ScaleQuantumToMap(GetPixelBlack(image,p+offset*GetPixelChannels(image)))) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 493 | v++; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 494 | cooccurrence[u][v].direction[i].black++; |
| 495 | cooccurrence[v][u].direction[i].black++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 496 | } |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 497 | if (image->matte != MagickFalse) |
| 498 | { |
| 499 | u=0; |
| 500 | v=0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 501 | while (grays[u].alpha != ScaleQuantumToMap(GetPixelAlpha(image,p))) |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 502 | u++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 503 | while (grays[v].alpha != ScaleQuantumToMap(GetPixelAlpha(image,p+offset*GetPixelChannels(image)))) |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 504 | v++; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 505 | cooccurrence[u][v].direction[i].alpha++; |
| 506 | cooccurrence[v][u].direction[i].alpha++; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 507 | } |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 508 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 509 | p+=GetPixelChannels(image); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 512 | grays=(PixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 513 | image_view=DestroyCacheView(image_view); |
| 514 | if (status == MagickFalse) |
| 515 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 516 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 517 | cooccurrence[i]=(ChannelStatistics *) |
| 518 | RelinquishMagickMemory(cooccurrence[i]); |
| 519 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 520 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 521 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 522 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 523 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 524 | return(channel_features); |
| 525 | } |
| 526 | /* |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 527 | Normalize spatial dependence matrix. |
| 528 | */ |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 529 | for (i=0; i < 4; i++) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 530 | { |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 531 | double |
| 532 | normalize; |
| 533 | |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 534 | register ssize_t |
| 535 | y; |
| 536 | |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 537 | switch (i) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 538 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 539 | case 0: |
| 540 | default: |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 541 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 542 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 543 | Horizontal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 544 | */ |
| 545 | normalize=2.0*image->rows*(image->columns-distance); |
| 546 | break; |
| 547 | } |
| 548 | case 1: |
| 549 | { |
| 550 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 551 | Vertical adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 552 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 553 | normalize=2.0*(image->rows-distance)*image->columns; |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 554 | break; |
| 555 | } |
| 556 | case 2: |
| 557 | { |
| 558 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 559 | Right diagonal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 560 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 561 | normalize=2.0*(image->rows-distance)*(image->columns-distance); |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 562 | break; |
| 563 | } |
| 564 | case 3: |
| 565 | { |
| 566 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 567 | Left diagonal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 568 | */ |
| 569 | normalize=2.0*(image->rows-distance)*(image->columns-distance); |
| 570 | break; |
| 571 | } |
| 572 | } |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 573 | normalize=1.0/(fabs((double) normalize) <= MagickEpsilon ? 1.0 : normalize); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 574 | for (y=0; y < (ssize_t) number_grays; y++) |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 575 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 576 | register ssize_t |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 577 | x; |
| 578 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 579 | for (x=0; x < (ssize_t) number_grays; x++) |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 580 | { |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 581 | cooccurrence[x][y].direction[i].red*=normalize; |
| 582 | cooccurrence[x][y].direction[i].green*=normalize; |
| 583 | cooccurrence[x][y].direction[i].blue*=normalize; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 584 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 585 | cooccurrence[x][y].direction[i].black*=normalize; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 586 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 587 | cooccurrence[x][y].direction[i].alpha*=normalize; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | } |
| 591 | /* |
| 592 | Compute texture features. |
| 593 | */ |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 594 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 595 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 596 | #endif |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 597 | for (i=0; i < 4; i++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 598 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 599 | register ssize_t |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 600 | y; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 601 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 602 | for (y=0; y < (ssize_t) number_grays; y++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 603 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 604 | register ssize_t |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 605 | x; |
| 606 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 607 | for (x=0; x < (ssize_t) number_grays; x++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 608 | { |
| 609 | /* |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 610 | Angular second moment: measure of homogeneity of the image. |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 611 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 612 | channel_features[RedPixelChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 613 | cooccurrence[x][y].direction[i].red* |
| 614 | cooccurrence[x][y].direction[i].red; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 615 | channel_features[GreenPixelChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 616 | cooccurrence[x][y].direction[i].green* |
| 617 | cooccurrence[x][y].direction[i].green; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 618 | channel_features[BluePixelChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 619 | cooccurrence[x][y].direction[i].blue* |
| 620 | cooccurrence[x][y].direction[i].blue; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 621 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 622 | channel_features[BlackPixelChannel].angular_second_moment[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 623 | cooccurrence[x][y].direction[i].black* |
| 624 | cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 625 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 626 | channel_features[AlphaPixelChannel].angular_second_moment[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 627 | cooccurrence[x][y].direction[i].alpha* |
| 628 | cooccurrence[x][y].direction[i].alpha; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 629 | /* |
| 630 | Correlation: measure of linear-dependencies in the image. |
| 631 | */ |
| 632 | sum[y].direction[i].red+=cooccurrence[x][y].direction[i].red; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 633 | sum[y].direction[i].green+=cooccurrence[x][y].direction[i].green; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 634 | sum[y].direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 635 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 636 | sum[y].direction[i].black+=cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 637 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 638 | sum[y].direction[i].alpha+=cooccurrence[x][y].direction[i].alpha; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 639 | correlation.direction[i].red+=x*y*cooccurrence[x][y].direction[i].red; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 640 | correlation.direction[i].green+=x*y* |
| 641 | cooccurrence[x][y].direction[i].green; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 642 | correlation.direction[i].blue+=x*y* |
| 643 | cooccurrence[x][y].direction[i].blue; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 644 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 645 | correlation.direction[i].black+=x*y* |
| 646 | cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 647 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 648 | correlation.direction[i].alpha+=x*y* |
| 649 | cooccurrence[x][y].direction[i].alpha; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 650 | /* |
| 651 | Inverse Difference Moment. |
| 652 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 653 | channel_features[RedPixelChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 654 | cooccurrence[x][y].direction[i].red/((y-x)*(y-x)+1); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 655 | channel_features[GreenPixelChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 656 | cooccurrence[x][y].direction[i].green/((y-x)*(y-x)+1); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 657 | channel_features[BluePixelChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 658 | cooccurrence[x][y].direction[i].blue/((y-x)*(y-x)+1); |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 659 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 660 | channel_features[BlackPixelChannel].inverse_difference_moment[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 661 | cooccurrence[x][y].direction[i].black/((y-x)*(y-x)+1); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 662 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 663 | channel_features[AlphaPixelChannel].inverse_difference_moment[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 664 | cooccurrence[x][y].direction[i].alpha/((y-x)*(y-x)+1); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 665 | /* |
| 666 | Sum average. |
| 667 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 668 | density_xy[y+x+2].direction[i].red+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 669 | cooccurrence[x][y].direction[i].red; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 670 | density_xy[y+x+2].direction[i].green+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 671 | cooccurrence[x][y].direction[i].green; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 672 | density_xy[y+x+2].direction[i].blue+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 673 | cooccurrence[x][y].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 674 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 675 | density_xy[y+x+2].direction[i].black+= |
| 676 | cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 677 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 678 | density_xy[y+x+2].direction[i].alpha+= |
| 679 | cooccurrence[x][y].direction[i].alpha; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 680 | /* |
| 681 | Entropy. |
| 682 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 683 | channel_features[RedPixelChannel].entropy[i]-= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 684 | cooccurrence[x][y].direction[i].red* |
| 685 | log10(cooccurrence[x][y].direction[i].red+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 686 | channel_features[GreenPixelChannel].entropy[i]-= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 687 | cooccurrence[x][y].direction[i].green* |
| 688 | log10(cooccurrence[x][y].direction[i].green+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 689 | channel_features[BluePixelChannel].entropy[i]-= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 690 | cooccurrence[x][y].direction[i].blue* |
| 691 | log10(cooccurrence[x][y].direction[i].blue+MagickEpsilon); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 692 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 693 | channel_features[BlackPixelChannel].entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 694 | cooccurrence[x][y].direction[i].black* |
| 695 | log10(cooccurrence[x][y].direction[i].black+MagickEpsilon); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 696 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 697 | channel_features[AlphaPixelChannel].entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 698 | cooccurrence[x][y].direction[i].alpha* |
| 699 | log10(cooccurrence[x][y].direction[i].alpha+MagickEpsilon); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 700 | /* |
| 701 | Information Measures of Correlation. |
| 702 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 703 | density_x[x].direction[i].red+=cooccurrence[x][y].direction[i].red; |
| 704 | density_x[x].direction[i].green+=cooccurrence[x][y].direction[i].green; |
| 705 | density_x[x].direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 706 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 707 | density_x[x].direction[i].alpha+= |
| 708 | cooccurrence[x][y].direction[i].alpha; |
| 709 | if (image->colorspace == CMYKColorspace) |
| 710 | density_x[x].direction[i].black+= |
| 711 | cooccurrence[x][y].direction[i].black; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 712 | density_y[y].direction[i].red+=cooccurrence[x][y].direction[i].red; |
| 713 | density_y[y].direction[i].green+=cooccurrence[x][y].direction[i].green; |
| 714 | density_y[y].direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 715 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 716 | density_y[y].direction[i].black+= |
| 717 | cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 718 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 719 | density_y[y].direction[i].alpha+= |
| 720 | cooccurrence[x][y].direction[i].alpha; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 721 | } |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 722 | mean.direction[i].red+=y*sum[y].direction[i].red; |
| 723 | sum_squares.direction[i].red+=y*y*sum[y].direction[i].red; |
| 724 | mean.direction[i].green+=y*sum[y].direction[i].green; |
| 725 | sum_squares.direction[i].green+=y*y*sum[y].direction[i].green; |
| 726 | mean.direction[i].blue+=y*sum[y].direction[i].blue; |
| 727 | sum_squares.direction[i].blue+=y*y*sum[y].direction[i].blue; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 728 | if (image->colorspace == CMYKColorspace) |
| 729 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 730 | mean.direction[i].black+=y*sum[y].direction[i].black; |
| 731 | sum_squares.direction[i].black+=y*y*sum[y].direction[i].black; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 732 | } |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 733 | if (image->matte != MagickFalse) |
| 734 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 735 | mean.direction[i].alpha+=y*sum[y].direction[i].alpha; |
| 736 | sum_squares.direction[i].alpha+=y*y*sum[y].direction[i].alpha; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 737 | } |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 738 | } |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 739 | /* |
| 740 | Correlation: measure of linear-dependencies in the image. |
| 741 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 742 | channel_features[RedPixelChannel].correlation[i]= |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 743 | (correlation.direction[i].red-mean.direction[i].red* |
| 744 | mean.direction[i].red)/(sqrt(sum_squares.direction[i].red- |
| 745 | (mean.direction[i].red*mean.direction[i].red))*sqrt( |
| 746 | sum_squares.direction[i].red-(mean.direction[i].red* |
| 747 | mean.direction[i].red))); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 748 | channel_features[GreenPixelChannel].correlation[i]= |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 749 | (correlation.direction[i].green-mean.direction[i].green* |
| 750 | mean.direction[i].green)/(sqrt(sum_squares.direction[i].green- |
| 751 | (mean.direction[i].green*mean.direction[i].green))*sqrt( |
| 752 | sum_squares.direction[i].green-(mean.direction[i].green* |
| 753 | mean.direction[i].green))); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 754 | channel_features[BluePixelChannel].correlation[i]= |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 755 | (correlation.direction[i].blue-mean.direction[i].blue* |
| 756 | mean.direction[i].blue)/(sqrt(sum_squares.direction[i].blue- |
| 757 | (mean.direction[i].blue*mean.direction[i].blue))*sqrt( |
| 758 | sum_squares.direction[i].blue-(mean.direction[i].blue* |
| 759 | mean.direction[i].blue))); |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 760 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 761 | channel_features[BlackPixelChannel].correlation[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 762 | (correlation.direction[i].black-mean.direction[i].black* |
| 763 | mean.direction[i].black)/(sqrt(sum_squares.direction[i].black- |
| 764 | (mean.direction[i].black*mean.direction[i].black))*sqrt( |
| 765 | sum_squares.direction[i].black-(mean.direction[i].black* |
| 766 | mean.direction[i].black))); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 767 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 768 | channel_features[AlphaPixelChannel].correlation[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 769 | (correlation.direction[i].alpha-mean.direction[i].alpha* |
| 770 | mean.direction[i].alpha)/(sqrt(sum_squares.direction[i].alpha- |
| 771 | (mean.direction[i].alpha*mean.direction[i].alpha))*sqrt( |
| 772 | sum_squares.direction[i].alpha-(mean.direction[i].alpha* |
| 773 | mean.direction[i].alpha))); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 774 | } |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 775 | /* |
| 776 | Compute more texture features. |
| 777 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 778 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 779 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 780 | #endif |
| 781 | for (i=0; i < 4; i++) |
| 782 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 783 | register ssize_t |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 784 | x; |
| 785 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 786 | for (x=2; x < (ssize_t) (2*number_grays); x++) |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 787 | { |
| 788 | /* |
| 789 | Sum average. |
| 790 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 791 | channel_features[RedPixelChannel].sum_average[i]+= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 792 | x*density_xy[x].direction[i].red; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 793 | channel_features[GreenPixelChannel].sum_average[i]+= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 794 | x*density_xy[x].direction[i].green; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 795 | channel_features[BluePixelChannel].sum_average[i]+= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 796 | x*density_xy[x].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 797 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 798 | channel_features[BlackPixelChannel].sum_average[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 799 | x*density_xy[x].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 800 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 801 | channel_features[AlphaPixelChannel].sum_average[i]+= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 802 | x*density_xy[x].direction[i].alpha; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 803 | /* |
| 804 | Sum entropy. |
| 805 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 806 | channel_features[RedPixelChannel].sum_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 807 | density_xy[x].direction[i].red* |
| 808 | log10(density_xy[x].direction[i].red+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 809 | channel_features[GreenPixelChannel].sum_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 810 | density_xy[x].direction[i].green* |
| 811 | log10(density_xy[x].direction[i].green+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 812 | channel_features[BluePixelChannel].sum_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 813 | density_xy[x].direction[i].blue* |
| 814 | log10(density_xy[x].direction[i].blue+MagickEpsilon); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 815 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 816 | channel_features[BlackPixelChannel].sum_entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 817 | density_xy[x].direction[i].black* |
| 818 | log10(density_xy[x].direction[i].black+MagickEpsilon); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 819 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 820 | channel_features[AlphaPixelChannel].sum_entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 821 | density_xy[x].direction[i].alpha* |
| 822 | log10(density_xy[x].direction[i].alpha+MagickEpsilon); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 823 | /* |
| 824 | Sum variance. |
| 825 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 826 | channel_features[RedPixelChannel].sum_variance[i]+= |
| 827 | (x-channel_features[RedPixelChannel].sum_entropy[i])* |
| 828 | (x-channel_features[RedPixelChannel].sum_entropy[i])* |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 829 | density_xy[x].direction[i].red; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 830 | channel_features[GreenPixelChannel].sum_variance[i]+= |
| 831 | (x-channel_features[GreenPixelChannel].sum_entropy[i])* |
| 832 | (x-channel_features[GreenPixelChannel].sum_entropy[i])* |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 833 | density_xy[x].direction[i].green; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 834 | channel_features[BluePixelChannel].sum_variance[i]+= |
| 835 | (x-channel_features[BluePixelChannel].sum_entropy[i])* |
| 836 | (x-channel_features[BluePixelChannel].sum_entropy[i])* |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 837 | density_xy[x].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 838 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 839 | channel_features[BlackPixelChannel].sum_variance[i]+= |
| 840 | (x-channel_features[BlackPixelChannel].sum_entropy[i])* |
| 841 | (x-channel_features[BlackPixelChannel].sum_entropy[i])* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 842 | density_xy[x].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 843 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 844 | channel_features[AlphaPixelChannel].sum_variance[i]+= |
| 845 | (x-channel_features[AlphaPixelChannel].sum_entropy[i])* |
| 846 | (x-channel_features[AlphaPixelChannel].sum_entropy[i])* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 847 | density_xy[x].direction[i].alpha; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | /* |
| 851 | Compute more texture features. |
| 852 | */ |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 853 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 854 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 855 | #endif |
| 856 | for (i=0; i < 4; i++) |
| 857 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 858 | register ssize_t |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 859 | y; |
| 860 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 861 | for (y=0; y < (ssize_t) number_grays; y++) |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 862 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 863 | register ssize_t |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 864 | x; |
| 865 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 866 | for (x=0; x < (ssize_t) number_grays; x++) |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 867 | { |
| 868 | /* |
| 869 | Sum of Squares: Variance |
| 870 | */ |
| 871 | variance.direction[i].red+=(y-mean.direction[i].red+1)* |
| 872 | (y-mean.direction[i].red+1)*cooccurrence[x][y].direction[i].red; |
| 873 | variance.direction[i].green+=(y-mean.direction[i].green+1)* |
| 874 | (y-mean.direction[i].green+1)*cooccurrence[x][y].direction[i].green; |
| 875 | variance.direction[i].blue+=(y-mean.direction[i].blue+1)* |
| 876 | (y-mean.direction[i].blue+1)*cooccurrence[x][y].direction[i].blue; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 877 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 878 | variance.direction[i].black+=(y-mean.direction[i].black+1)* |
| 879 | (y-mean.direction[i].black+1)*cooccurrence[x][y].direction[i].black; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 880 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 881 | variance.direction[i].alpha+=(y-mean.direction[i].alpha+1)* |
| 882 | (y-mean.direction[i].alpha+1)* |
| 883 | cooccurrence[x][y].direction[i].alpha; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 884 | /* |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 885 | Sum average / Difference Variance. |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 886 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 887 | density_xy[MagickAbsoluteValue(y-x)].direction[i].red+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 888 | cooccurrence[x][y].direction[i].red; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 889 | density_xy[MagickAbsoluteValue(y-x)].direction[i].green+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 890 | cooccurrence[x][y].direction[i].green; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 891 | density_xy[MagickAbsoluteValue(y-x)].direction[i].blue+= |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 892 | cooccurrence[x][y].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 893 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 894 | density_xy[MagickAbsoluteValue(y-x)].direction[i].black+= |
| 895 | cooccurrence[x][y].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 896 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 897 | density_xy[MagickAbsoluteValue(y-x)].direction[i].alpha+= |
| 898 | cooccurrence[x][y].direction[i].alpha; |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 899 | /* |
| 900 | Information Measures of Correlation. |
| 901 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 902 | entropy_xy.direction[i].red-=cooccurrence[x][y].direction[i].red* |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 903 | log10(cooccurrence[x][y].direction[i].red+MagickEpsilon); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 904 | entropy_xy.direction[i].green-=cooccurrence[x][y].direction[i].green* |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 905 | log10(cooccurrence[x][y].direction[i].green+MagickEpsilon); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 906 | entropy_xy.direction[i].blue-=cooccurrence[x][y].direction[i].blue* |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 907 | log10(cooccurrence[x][y].direction[i].blue+MagickEpsilon); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 908 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 909 | entropy_xy.direction[i].black-=cooccurrence[x][y].direction[i].black* |
| 910 | log10(cooccurrence[x][y].direction[i].black+MagickEpsilon); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 911 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 912 | entropy_xy.direction[i].alpha-= |
| 913 | cooccurrence[x][y].direction[i].alpha*log10( |
| 914 | cooccurrence[x][y].direction[i].alpha+MagickEpsilon); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 915 | entropy_xy1.direction[i].red-=(cooccurrence[x][y].direction[i].red* |
| 916 | log10(density_x[x].direction[i].red*density_y[y].direction[i].red+ |
| 917 | MagickEpsilon)); |
| 918 | entropy_xy1.direction[i].green-=(cooccurrence[x][y].direction[i].green* |
| 919 | log10(density_x[x].direction[i].green*density_y[y].direction[i].green+ |
| 920 | MagickEpsilon)); |
| 921 | entropy_xy1.direction[i].blue-=(cooccurrence[x][y].direction[i].blue* |
| 922 | log10(density_x[x].direction[i].blue*density_y[y].direction[i].blue+ |
| 923 | MagickEpsilon)); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 924 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 925 | entropy_xy1.direction[i].black-=( |
| 926 | cooccurrence[x][y].direction[i].black*log10( |
| 927 | density_x[x].direction[i].black*density_y[y].direction[i].black+ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 928 | MagickEpsilon)); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 929 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 930 | entropy_xy1.direction[i].alpha-=( |
| 931 | cooccurrence[x][y].direction[i].alpha*log10( |
| 932 | density_x[x].direction[i].alpha*density_y[y].direction[i].alpha+ |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 933 | MagickEpsilon)); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 934 | entropy_xy2.direction[i].red-=(density_x[x].direction[i].red* |
| 935 | density_y[y].direction[i].red*log10(density_x[x].direction[i].red* |
| 936 | density_y[y].direction[i].red+MagickEpsilon)); |
| 937 | entropy_xy2.direction[i].green-=(density_x[x].direction[i].green* |
| 938 | density_y[y].direction[i].green*log10(density_x[x].direction[i].green* |
| 939 | density_y[y].direction[i].green+MagickEpsilon)); |
| 940 | entropy_xy2.direction[i].blue-=(density_x[x].direction[i].blue* |
| 941 | density_y[y].direction[i].blue*log10(density_x[x].direction[i].blue* |
| 942 | density_y[y].direction[i].blue+MagickEpsilon)); |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 943 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 944 | entropy_xy2.direction[i].black-=(density_x[x].direction[i].black* |
| 945 | density_y[y].direction[i].black*log10( |
| 946 | density_x[x].direction[i].black*density_y[y].direction[i].black+ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 947 | MagickEpsilon)); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 948 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 949 | entropy_xy2.direction[i].alpha-=(density_x[x].direction[i].alpha* |
| 950 | density_y[y].direction[i].alpha*log10( |
| 951 | density_x[x].direction[i].alpha*density_y[y].direction[i].alpha+ |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 952 | MagickEpsilon)); |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 953 | } |
| 954 | } |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 955 | channel_features[RedPixelChannel].variance_sum_of_squares[i]= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 956 | variance.direction[i].red; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 957 | channel_features[GreenPixelChannel].variance_sum_of_squares[i]= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 958 | variance.direction[i].green; |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 959 | channel_features[BluePixelChannel].variance_sum_of_squares[i]= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 960 | variance.direction[i].blue; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 961 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 962 | channel_features[BlackPixelChannel].variance_sum_of_squares[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 963 | variance.direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 964 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 965 | channel_features[AlphaPixelChannel].variance_sum_of_squares[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 966 | variance.direction[i].alpha; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 967 | } |
| 968 | /* |
| 969 | Compute more texture features. |
| 970 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 971 | (void) ResetMagickMemory(&variance,0,sizeof(variance)); |
| 972 | (void) ResetMagickMemory(&sum_squares,0,sizeof(sum_squares)); |
| 973 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 974 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 975 | #endif |
| 976 | for (i=0; i < 4; i++) |
| 977 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 978 | register ssize_t |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 979 | x; |
| 980 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 981 | for (x=0; x < (ssize_t) number_grays; x++) |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 982 | { |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 983 | /* |
| 984 | Difference variance. |
| 985 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 986 | variance.direction[i].red+=density_xy[x].direction[i].red; |
| 987 | variance.direction[i].green+=density_xy[x].direction[i].green; |
| 988 | variance.direction[i].blue+=density_xy[x].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 989 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 990 | variance.direction[i].black+=density_xy[x].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 991 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 992 | variance.direction[i].alpha+=density_xy[x].direction[i].alpha; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 993 | sum_squares.direction[i].red+=density_xy[x].direction[i].red* |
| 994 | density_xy[x].direction[i].red; |
| 995 | sum_squares.direction[i].green+=density_xy[x].direction[i].green* |
| 996 | density_xy[x].direction[i].green; |
| 997 | sum_squares.direction[i].blue+=density_xy[x].direction[i].blue* |
| 998 | density_xy[x].direction[i].blue; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 999 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1000 | sum_squares.direction[i].black+=density_xy[x].direction[i].black* |
| 1001 | density_xy[x].direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1002 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1003 | sum_squares.direction[i].alpha+=density_xy[x].direction[i].alpha* |
| 1004 | density_xy[x].direction[i].alpha; |
cristy | f6214de | 2010-01-29 02:47:41 +0000 | [diff] [blame] | 1005 | /* |
| 1006 | Difference entropy. |
| 1007 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1008 | channel_features[RedPixelChannel].difference_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1009 | density_xy[x].direction[i].red* |
| 1010 | log10(density_xy[x].direction[i].red+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1011 | channel_features[GreenPixelChannel].difference_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1012 | density_xy[x].direction[i].green* |
| 1013 | log10(density_xy[x].direction[i].green+MagickEpsilon); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1014 | channel_features[BluePixelChannel].difference_entropy[i]-= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1015 | density_xy[x].direction[i].blue* |
| 1016 | log10(density_xy[x].direction[i].blue+MagickEpsilon); |
cristy | f6214de | 2010-01-29 02:47:41 +0000 | [diff] [blame] | 1017 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1018 | channel_features[BlackPixelChannel].difference_entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1019 | density_xy[x].direction[i].black* |
| 1020 | log10(density_xy[x].direction[i].black+MagickEpsilon); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1021 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1022 | channel_features[AlphaPixelChannel].difference_entropy[i]-= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1023 | density_xy[x].direction[i].alpha* |
| 1024 | log10(density_xy[x].direction[i].alpha+MagickEpsilon); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1025 | /* |
| 1026 | Information Measures of Correlation. |
| 1027 | */ |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1028 | entropy_x.direction[i].red-=(density_x[x].direction[i].red* |
| 1029 | log10(density_x[x].direction[i].red+MagickEpsilon)); |
| 1030 | entropy_x.direction[i].green-=(density_x[x].direction[i].green* |
| 1031 | log10(density_x[x].direction[i].green+MagickEpsilon)); |
| 1032 | entropy_x.direction[i].blue-=(density_x[x].direction[i].blue* |
| 1033 | log10(density_x[x].direction[i].blue+MagickEpsilon)); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1034 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1035 | entropy_x.direction[i].black-=(density_x[x].direction[i].black* |
| 1036 | log10(density_x[x].direction[i].black+MagickEpsilon)); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1037 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1038 | entropy_x.direction[i].alpha-=(density_x[x].direction[i].alpha* |
| 1039 | log10(density_x[x].direction[i].alpha+MagickEpsilon)); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1040 | entropy_y.direction[i].red-=(density_y[x].direction[i].red* |
| 1041 | log10(density_y[x].direction[i].red+MagickEpsilon)); |
| 1042 | entropy_y.direction[i].green-=(density_y[x].direction[i].green* |
| 1043 | log10(density_y[x].direction[i].green+MagickEpsilon)); |
| 1044 | entropy_y.direction[i].blue-=(density_y[x].direction[i].blue* |
| 1045 | log10(density_y[x].direction[i].blue+MagickEpsilon)); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1046 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1047 | entropy_y.direction[i].black-=(density_y[x].direction[i].black* |
| 1048 | log10(density_y[x].direction[i].black+MagickEpsilon)); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1049 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1050 | entropy_y.direction[i].alpha-=(density_y[x].direction[i].alpha* |
| 1051 | log10(density_y[x].direction[i].alpha+MagickEpsilon)); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1052 | } |
cristy | f6214de | 2010-01-29 02:47:41 +0000 | [diff] [blame] | 1053 | /* |
| 1054 | Difference variance. |
| 1055 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1056 | channel_features[RedPixelChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame] | 1057 | (((double) number_grays*number_grays*sum_squares.direction[i].red)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1058 | (variance.direction[i].red*variance.direction[i].red))/ |
| 1059 | ((double) number_grays*number_grays*number_grays*number_grays); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1060 | channel_features[GreenPixelChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame] | 1061 | (((double) number_grays*number_grays*sum_squares.direction[i].green)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1062 | (variance.direction[i].green*variance.direction[i].green))/ |
| 1063 | ((double) number_grays*number_grays*number_grays*number_grays); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1064 | channel_features[BluePixelChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame] | 1065 | (((double) number_grays*number_grays*sum_squares.direction[i].blue)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1066 | (variance.direction[i].blue*variance.direction[i].blue))/ |
| 1067 | ((double) number_grays*number_grays*number_grays*number_grays); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1068 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1069 | channel_features[BlackPixelChannel].difference_variance[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1070 | (((double) number_grays*number_grays*sum_squares.direction[i].black)- |
| 1071 | (variance.direction[i].black*variance.direction[i].black))/ |
| 1072 | ((double) number_grays*number_grays*number_grays*number_grays); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1073 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1074 | channel_features[AlphaPixelChannel].difference_variance[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1075 | (((double) number_grays*number_grays*sum_squares.direction[i].alpha)- |
| 1076 | (variance.direction[i].alpha*variance.direction[i].alpha))/ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1077 | ((double) number_grays*number_grays*number_grays*number_grays); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1078 | /* |
| 1079 | Information Measures of Correlation. |
| 1080 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1081 | channel_features[RedPixelChannel].measure_of_correlation_1[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1082 | (entropy_xy.direction[i].red-entropy_xy1.direction[i].red)/ |
| 1083 | (entropy_x.direction[i].red > entropy_y.direction[i].red ? |
| 1084 | entropy_x.direction[i].red : entropy_y.direction[i].red); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1085 | channel_features[GreenPixelChannel].measure_of_correlation_1[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1086 | (entropy_xy.direction[i].green-entropy_xy1.direction[i].green)/ |
| 1087 | (entropy_x.direction[i].green > entropy_y.direction[i].green ? |
| 1088 | entropy_x.direction[i].green : entropy_y.direction[i].green); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1089 | channel_features[BluePixelChannel].measure_of_correlation_1[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1090 | (entropy_xy.direction[i].blue-entropy_xy1.direction[i].blue)/ |
| 1091 | (entropy_x.direction[i].blue > entropy_y.direction[i].blue ? |
| 1092 | entropy_x.direction[i].blue : entropy_y.direction[i].blue); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1093 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1094 | channel_features[BlackPixelChannel].measure_of_correlation_1[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1095 | (entropy_xy.direction[i].black-entropy_xy1.direction[i].black)/ |
| 1096 | (entropy_x.direction[i].black > entropy_y.direction[i].black ? |
| 1097 | entropy_x.direction[i].black : entropy_y.direction[i].black); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1098 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1099 | channel_features[AlphaPixelChannel].measure_of_correlation_1[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1100 | (entropy_xy.direction[i].alpha-entropy_xy1.direction[i].alpha)/ |
| 1101 | (entropy_x.direction[i].alpha > entropy_y.direction[i].alpha ? |
| 1102 | entropy_x.direction[i].alpha : entropy_y.direction[i].alpha); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1103 | channel_features[RedPixelChannel].measure_of_correlation_2[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1104 | (sqrt(fabs(1.0-exp(-2.0*(entropy_xy2.direction[i].red- |
| 1105 | entropy_xy.direction[i].red))))); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1106 | channel_features[GreenPixelChannel].measure_of_correlation_2[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1107 | (sqrt(fabs(1.0-exp(-2.0*(entropy_xy2.direction[i].green- |
| 1108 | entropy_xy.direction[i].green))))); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1109 | channel_features[BluePixelChannel].measure_of_correlation_2[i]= |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1110 | (sqrt(fabs(1.0-exp(-2.0*(entropy_xy2.direction[i].blue- |
| 1111 | entropy_xy.direction[i].blue))))); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1112 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1113 | channel_features[BlackPixelChannel].measure_of_correlation_2[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1114 | (sqrt(fabs(1.0-exp(-2.0*(entropy_xy2.direction[i].black- |
| 1115 | entropy_xy.direction[i].black))))); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1116 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1117 | channel_features[AlphaPixelChannel].measure_of_correlation_2[i]= |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1118 | (sqrt(fabs(1.0-exp(-2.0*(entropy_xy2.direction[i].alpha- |
| 1119 | entropy_xy.direction[i].alpha))))); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 1120 | } |
| 1121 | /* |
| 1122 | Compute more texture features. |
| 1123 | */ |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1124 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | e617850 | 2011-12-23 17:02:29 +0000 | [diff] [blame] | 1125 | #pragma omp parallel for schedule(static,4) shared(status) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1126 | #endif |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 1127 | for (i=0; i < 4; i++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1128 | { |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1129 | ssize_t |
| 1130 | z; |
| 1131 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1132 | for (z=0; z < (ssize_t) number_grays; z++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1133 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1134 | register ssize_t |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 1135 | y; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1136 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 1137 | ChannelStatistics |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 1138 | pixel; |
| 1139 | |
| 1140 | (void) ResetMagickMemory(&pixel,0,sizeof(pixel)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1141 | for (y=0; y < (ssize_t) number_grays; y++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1142 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1143 | register ssize_t |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 1144 | x; |
| 1145 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1146 | for (x=0; x < (ssize_t) number_grays; x++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1147 | { |
| 1148 | /* |
| 1149 | Contrast: amount of local variations present in an image. |
| 1150 | */ |
| 1151 | if (((y-x) == z) || ((x-y) == z)) |
| 1152 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 1153 | pixel.direction[i].red+=cooccurrence[x][y].direction[i].red; |
| 1154 | pixel.direction[i].green+=cooccurrence[x][y].direction[i].green; |
| 1155 | pixel.direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1156 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1157 | pixel.direction[i].black+=cooccurrence[x][y].direction[i].black; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1158 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1159 | pixel.direction[i].alpha+= |
| 1160 | cooccurrence[x][y].direction[i].alpha; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1161 | } |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1162 | /* |
| 1163 | Maximum Correlation Coefficient. |
| 1164 | */ |
| 1165 | Q[z][y].direction[i].red+=cooccurrence[z][x].direction[i].red* |
| 1166 | cooccurrence[y][x].direction[i].red/density_x[z].direction[i].red/ |
| 1167 | density_y[x].direction[i].red; |
| 1168 | Q[z][y].direction[i].green+=cooccurrence[z][x].direction[i].green* |
| 1169 | cooccurrence[y][x].direction[i].green/ |
| 1170 | density_x[z].direction[i].green/density_y[x].direction[i].red; |
| 1171 | Q[z][y].direction[i].blue+=cooccurrence[z][x].direction[i].blue* |
| 1172 | cooccurrence[y][x].direction[i].blue/density_x[z].direction[i].blue/ |
| 1173 | density_y[x].direction[i].blue; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1174 | if (image->colorspace == CMYKColorspace) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1175 | Q[z][y].direction[i].black+=cooccurrence[z][x].direction[i].black* |
| 1176 | cooccurrence[y][x].direction[i].black/ |
| 1177 | density_x[z].direction[i].black/density_y[x].direction[i].black; |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1178 | if (image->matte != MagickFalse) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1179 | Q[z][y].direction[i].alpha+= |
| 1180 | cooccurrence[z][x].direction[i].alpha* |
| 1181 | cooccurrence[y][x].direction[i].alpha/ |
| 1182 | density_x[z].direction[i].alpha/ |
| 1183 | density_y[x].direction[i].alpha; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1184 | } |
| 1185 | } |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1186 | channel_features[RedPixelChannel].contrast[i]+=z*z* |
| 1187 | pixel.direction[i].red; |
| 1188 | channel_features[GreenPixelChannel].contrast[i]+=z*z* |
| 1189 | pixel.direction[i].green; |
| 1190 | channel_features[BluePixelChannel].contrast[i]+=z*z* |
| 1191 | pixel.direction[i].blue; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1192 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1193 | channel_features[BlackPixelChannel].contrast[i]+=z*z* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1194 | pixel.direction[i].black; |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1195 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1196 | channel_features[AlphaPixelChannel].contrast[i]+=z*z* |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1197 | pixel.direction[i].alpha; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1198 | } |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1199 | /* |
| 1200 | Maximum Correlation Coefficient. |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1201 | Future: return second largest eigenvalue of Q. |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1202 | */ |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1203 | channel_features[RedPixelChannel].maximum_correlation_coefficient[i]= |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1204 | sqrt((double) -1.0); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1205 | channel_features[GreenPixelChannel].maximum_correlation_coefficient[i]= |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1206 | sqrt((double) -1.0); |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1207 | channel_features[BluePixelChannel].maximum_correlation_coefficient[i]= |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1208 | sqrt((double) -1.0); |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1209 | if (image->colorspace == CMYKColorspace) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1210 | channel_features[BlackPixelChannel].maximum_correlation_coefficient[i]= |
cristy | e0acabf | 2010-01-30 00:52:38 +0000 | [diff] [blame] | 1211 | sqrt((double) -1.0); |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1212 | if (image->matte != MagickFalse) |
cristy | d3090f9 | 2011-10-18 00:05:15 +0000 | [diff] [blame] | 1213 | channel_features[AlphaPixelChannel].maximum_correlation_coefficient[i]= |
cristy | 53a727d | 2011-06-16 14:53:56 +0000 | [diff] [blame] | 1214 | sqrt((double) -1.0); |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 1215 | } |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 1216 | /* |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 1217 | Relinquish resources. |
| 1218 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 1219 | sum=(ChannelStatistics *) RelinquishMagickMemory(sum); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1220 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | ffa10d0 | 2010-01-30 17:53:27 +0000 | [diff] [blame] | 1221 | Q[i]=(ChannelStatistics *) RelinquishMagickMemory(Q[i]); |
| 1222 | Q=(ChannelStatistics **) RelinquishMagickMemory(Q); |
| 1223 | density_y=(ChannelStatistics *) RelinquishMagickMemory(density_y); |
| 1224 | density_xy=(ChannelStatistics *) RelinquishMagickMemory(density_xy); |
| 1225 | density_x=(ChannelStatistics *) RelinquishMagickMemory(density_x); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1226 | for (i=0; i < (ssize_t) number_grays; i++) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 1227 | cooccurrence[i]=(ChannelStatistics *) |
| 1228 | RelinquishMagickMemory(cooccurrence[i]); |
| 1229 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 1230 | return(channel_features); |
| 1231 | } |