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