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