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 | % % |
| 20 | % Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization % |
| 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 | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 111 | % channel_features=GetImageChannelFeatures(image,1,excepton); |
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 | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 119 | % const unsigned long 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 | |
| 131 | static inline long MagickAbsoluteValue(const long x) |
| 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 | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 139 | const unsigned long 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, |
| 156 | mean, |
| 157 | *sum, |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 158 | *sum_average, |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 159 | sum_squares, |
| 160 | variance; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 161 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 162 | LongPixelPacket |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 163 | gray, |
| 164 | *grays; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 165 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 166 | long |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 167 | y, |
| 168 | z; |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 169 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 170 | MagickBooleanType |
| 171 | status; |
| 172 | |
| 173 | register long |
| 174 | i; |
| 175 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 176 | size_t |
| 177 | length; |
| 178 | |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 179 | unsigned long |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 180 | number_grays; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 181 | |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 182 | assert(image != (Image *) NULL); |
| 183 | assert(image->signature == MagickSignature); |
| 184 | if (image->debug != MagickFalse) |
| 185 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 186 | if ((image->columns < (distance+1)) || (image->rows < (distance+1))) |
| 187 | return((ChannelFeatures *) NULL); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 188 | length=AllChannels+1UL; |
| 189 | channel_features=(ChannelFeatures *) AcquireQuantumMemory(length, |
| 190 | sizeof(*channel_features)); |
| 191 | if (channel_features == (ChannelFeatures *) NULL) |
| 192 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 193 | (void) ResetMagickMemory(channel_features,0,length* |
| 194 | sizeof(*channel_features)); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 195 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 196 | Form grays. |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 197 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 198 | grays=(LongPixelPacket *) AcquireQuantumMemory(MaxMap+1UL,sizeof(*grays)); |
| 199 | if (grays == (LongPixelPacket *) NULL) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 200 | { |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 201 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 202 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 203 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 204 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 205 | return(channel_features); |
| 206 | } |
| 207 | for (i=0; i <= (long) MaxMap; i++) |
| 208 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 209 | grays[i].red=(~0UL); |
| 210 | grays[i].green=(~0UL); |
| 211 | grays[i].blue=(~0UL); |
| 212 | grays[i].opacity=(~0UL); |
| 213 | grays[i].index=(~0UL); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 214 | } |
| 215 | status=MagickTrue; |
| 216 | image_view=AcquireCacheView(image); |
| 217 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 218 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 219 | #endif |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 220 | for (y=0; y < (long) image->rows; y++) |
| 221 | { |
| 222 | register const IndexPacket |
| 223 | *restrict indexes; |
| 224 | |
| 225 | register const PixelPacket |
| 226 | *restrict p; |
| 227 | |
| 228 | register long |
| 229 | x; |
| 230 | |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 231 | if (status == MagickFalse) |
| 232 | continue; |
| 233 | p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 234 | if (p == (const PixelPacket *) NULL) |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 235 | { |
| 236 | status=MagickFalse; |
| 237 | continue; |
| 238 | } |
| 239 | indexes=GetCacheViewVirtualIndexQueue(image_view); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 240 | for (x=0; x < (long) image->columns; x++) |
| 241 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 242 | grays[ScaleQuantumToMap(p->red)].red=ScaleQuantumToMap(p->red); |
| 243 | grays[ScaleQuantumToMap(p->green)].green=ScaleQuantumToMap(p->green); |
| 244 | grays[ScaleQuantumToMap(p->blue)].blue=ScaleQuantumToMap(p->blue); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 245 | if (image->matte != MagickFalse) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 246 | grays[ScaleQuantumToMap(p->opacity)].opacity= |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 247 | ScaleQuantumToMap(p->opacity); |
| 248 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 249 | grays[ScaleQuantumToMap(indexes[x])].index= |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 250 | ScaleQuantumToMap(indexes[x]); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 251 | p++; |
| 252 | } |
| 253 | } |
cristy | 30c510a | 2010-01-24 03:43:00 +0000 | [diff] [blame] | 254 | image_view=DestroyCacheView(image_view); |
| 255 | if (status == MagickFalse) |
| 256 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 257 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
cristy | 30c510a | 2010-01-24 03:43:00 +0000 | [diff] [blame] | 258 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 259 | channel_features); |
| 260 | return(channel_features); |
| 261 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 262 | (void) ResetMagickMemory(&gray,0,sizeof(gray)); |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 263 | for (i=0; i <= (long) MaxMap; i++) |
| 264 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 265 | if (grays[i].red != ~0UL) |
| 266 | grays[gray.red++].red=grays[i].red; |
| 267 | if (grays[i].green != ~0UL) |
| 268 | grays[gray.green++].green=grays[i].green; |
| 269 | if (grays[i].blue != ~0UL) |
| 270 | grays[gray.blue++].blue=grays[i].blue; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 271 | if (image->matte != MagickFalse) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 272 | if (grays[i].opacity != ~0UL) |
| 273 | grays[gray.opacity++].opacity=grays[i].opacity; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 274 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 275 | if (grays[i].index != ~0UL) |
| 276 | grays[gray.index++].index=grays[i].index; |
cristy | 2070fa5 | 2010-01-24 03:17:57 +0000 | [diff] [blame] | 277 | } |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 278 | /* |
| 279 | Allocate spatial dependence matrix. |
| 280 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 281 | number_grays=gray.red; |
| 282 | if (gray.green > number_grays) |
| 283 | number_grays=gray.green; |
| 284 | if (gray.blue > number_grays) |
| 285 | number_grays=gray.blue; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 286 | if (image->matte != MagickFalse) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 287 | if (gray.opacity > number_grays) |
| 288 | number_grays=gray.opacity; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 289 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 290 | if (gray.index > number_grays) |
| 291 | number_grays=gray.index; |
| 292 | cooccurrence=(ChannelStatistics **) AcquireQuantumMemory(number_grays, |
| 293 | sizeof(*cooccurrence)); |
| 294 | if (cooccurrence == (ChannelStatistics **) NULL) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 295 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 296 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 297 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 298 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 299 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 300 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 301 | return(channel_features); |
| 302 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 303 | for (i=0; i < (long) number_grays; i++) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 304 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 305 | cooccurrence[i]=(ChannelStatistics *) AcquireQuantumMemory(number_grays, |
| 306 | sizeof(**cooccurrence)); |
| 307 | if (cooccurrence[i] == (ChannelStatistics *) NULL) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 308 | break; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 309 | (void) ResetMagickMemory(cooccurrence[i],0,number_grays* |
| 310 | sizeof(*cooccurrence)); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 311 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 312 | if (i < (long) number_grays) |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 313 | { |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 314 | for (i--; i >= 0; i--) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 315 | cooccurrence[i]=(ChannelStatistics *) |
| 316 | RelinquishMagickMemory(cooccurrence[i]); |
| 317 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
| 318 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 319 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 320 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 321 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 322 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 323 | return(channel_features); |
| 324 | } |
| 325 | /* |
| 326 | Initialize spatial dependence matrix. |
| 327 | */ |
| 328 | status=MagickTrue; |
| 329 | image_view=AcquireCacheView(image); |
| 330 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 331 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 332 | #endif |
| 333 | for (y=0; y < (long) image->rows; y++) |
| 334 | { |
| 335 | long |
| 336 | u, |
| 337 | v; |
| 338 | |
| 339 | register const IndexPacket |
| 340 | *restrict indexes; |
| 341 | |
| 342 | register const PixelPacket |
| 343 | *restrict p; |
| 344 | |
| 345 | register long |
| 346 | x; |
| 347 | |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 348 | ssize_t |
| 349 | offset; |
| 350 | |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 351 | if (status == MagickFalse) |
| 352 | continue; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 353 | p=GetCacheViewVirtualPixels(image_view,-(long) distance,y,image->columns+ |
| 354 | 2*distance,distance+1,exception); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 355 | if (p == (const PixelPacket *) NULL) |
| 356 | { |
| 357 | status=MagickFalse; |
| 358 | continue; |
| 359 | } |
| 360 | indexes=GetCacheViewVirtualIndexQueue(image_view); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 361 | p+=distance; |
| 362 | indexes+=distance; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 363 | for (x=0; x < (long) image->columns; x++) |
| 364 | { |
| 365 | for (i=0; i < 4; i++) |
| 366 | { |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 367 | switch (i) |
| 368 | { |
| 369 | case 0: |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 370 | default: |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 371 | { |
| 372 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 373 | Horizontal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 374 | */ |
| 375 | offset=(ssize_t) distance; |
| 376 | break; |
| 377 | } |
| 378 | case 1: |
| 379 | { |
| 380 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 381 | Vertical adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 382 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 383 | offset=(ssize_t) (image->columns+2*distance); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | case 2: |
| 387 | { |
| 388 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 389 | Right diagonal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 390 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 391 | offset=(ssize_t) (image->columns+2*distance)-distance; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 392 | break; |
| 393 | } |
| 394 | case 3: |
| 395 | { |
| 396 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 397 | Left diagonal adjacency. |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 398 | */ |
| 399 | offset=(ssize_t) (image->columns+2*distance)+distance; |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | u=0; |
| 404 | v=0; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 405 | while (grays[u].red != ScaleQuantumToMap(p->red)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 406 | u++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 407 | while (grays[v].red != ScaleQuantumToMap((p+offset)->red)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 408 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 409 | cooccurrence[u][v].direction[i].red++; |
| 410 | cooccurrence[v][u].direction[i].red++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 411 | u=0; |
| 412 | v=0; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 413 | while (grays[u].green != ScaleQuantumToMap(p->green)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 414 | u++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 415 | while (grays[v].green != ScaleQuantumToMap((p+offset)->green)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 416 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 417 | cooccurrence[u][v].direction[i].green++; |
| 418 | cooccurrence[v][u].direction[i].green++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 419 | u=0; |
| 420 | v=0; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 421 | while (grays[u].blue != ScaleQuantumToMap(p->blue)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 422 | u++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 423 | while (grays[v].blue != ScaleQuantumToMap((p+offset)->blue)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 424 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 425 | cooccurrence[u][v].direction[i].blue++; |
| 426 | cooccurrence[v][u].direction[i].blue++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 427 | if (image->matte != MagickFalse) |
| 428 | { |
| 429 | u=0; |
| 430 | v=0; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 431 | while (grays[u].opacity != ScaleQuantumToMap(p->opacity)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 432 | u++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 433 | while (grays[v].opacity != ScaleQuantumToMap((p+offset)->opacity)) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 434 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 435 | cooccurrence[u][v].direction[i].opacity++; |
| 436 | cooccurrence[v][u].direction[i].opacity++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 437 | } |
| 438 | if (image->colorspace == CMYKColorspace) |
| 439 | { |
| 440 | u=0; |
| 441 | v=0; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 442 | while (grays[u].index != ScaleQuantumToMap(indexes[x])) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 443 | u++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 444 | while (grays[v].index != ScaleQuantumToMap(indexes[x+offset])) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 445 | v++; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 446 | cooccurrence[u][v].direction[i].index++; |
| 447 | cooccurrence[v][u].direction[i].index++; |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 448 | } |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 449 | } |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 450 | p++; |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 451 | } |
| 452 | } |
| 453 | image_view=DestroyCacheView(image_view); |
| 454 | if (status == MagickFalse) |
| 455 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 456 | for (i=0; i < (long) number_grays; i++) |
| 457 | cooccurrence[i]=(ChannelStatistics *) |
| 458 | RelinquishMagickMemory(cooccurrence[i]); |
| 459 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
| 460 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 461 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 462 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 463 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 464 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 465 | return(channel_features); |
| 466 | } |
| 467 | /* |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 468 | Normalize spatial dependence matrix. |
| 469 | */ |
| 470 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 471 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 472 | #endif |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 473 | for (i=0; i < 4; i++) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 474 | { |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 475 | double |
| 476 | normalize; |
| 477 | |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 478 | switch (i) |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 479 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 480 | case 0: |
| 481 | default: |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 482 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 483 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 484 | Horizontal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 485 | */ |
| 486 | normalize=2.0*image->rows*(image->columns-distance); |
| 487 | break; |
| 488 | } |
| 489 | case 1: |
| 490 | { |
| 491 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 492 | Vertical adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 493 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 494 | normalize=2.0*(image->rows-distance)*image->columns; |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 495 | break; |
| 496 | } |
| 497 | case 2: |
| 498 | { |
| 499 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 500 | Right diagonal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 501 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 502 | normalize=2.0*(image->rows-distance)*(image->columns-distance); |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 503 | break; |
| 504 | } |
| 505 | case 3: |
| 506 | { |
| 507 | /* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 508 | Left diagonal adjacency. |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 509 | */ |
| 510 | normalize=2.0*(image->rows-distance)*(image->columns-distance); |
| 511 | break; |
| 512 | } |
| 513 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 514 | for (y=0; y < (long) number_grays; y++) |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 515 | { |
| 516 | register long |
| 517 | x; |
| 518 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 519 | for (x=0; x < (long) number_grays; x++) |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 520 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 521 | cooccurrence[x][y].direction[i].red/=normalize; |
| 522 | cooccurrence[x][y].direction[i].green/=normalize; |
| 523 | cooccurrence[x][y].direction[i].blue/=normalize; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 524 | if (image->matte != MagickFalse) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 525 | cooccurrence[x][y].direction[i].opacity/=normalize; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 526 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 527 | cooccurrence[x][y].direction[i].index/=normalize; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | } |
| 531 | /* |
| 532 | Compute texture features. |
| 533 | */ |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 534 | sum=(ChannelStatistics *) AcquireQuantumMemory(number_grays,sizeof(*sum)); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 535 | sum_average=(ChannelStatistics *) AcquireQuantumMemory(2*number_grays, |
| 536 | sizeof(*sum_average)); |
| 537 | if ((sum == (ChannelStatistics *) NULL) || |
| 538 | (sum_average == (ChannelStatistics *) NULL)) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 539 | { |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 540 | if (sum_average != (ChannelStatistics *) NULL) |
| 541 | sum_average=(ChannelStatistics *) RelinquishMagickMemory(sum_average); |
| 542 | if (sum != (ChannelStatistics *) NULL) |
| 543 | sum=(ChannelStatistics *) RelinquishMagickMemory(sum); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 544 | for (i=0; i < (long) number_grays; i++) |
| 545 | cooccurrence[i]=(ChannelStatistics *) |
| 546 | RelinquishMagickMemory(cooccurrence[i]); |
| 547 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
| 548 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
| 549 | channel_features=(ChannelFeatures *) RelinquishMagickMemory( |
| 550 | channel_features); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 551 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 552 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 553 | return(channel_features); |
| 554 | } |
| 555 | (void) ResetMagickMemory(sum,0,number_grays*sizeof(*sum)); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 556 | (void) ResetMagickMemory(sum_average,0,2*number_grays*sizeof(*sum_average)); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 557 | (void) ResetMagickMemory(&correlation,0,sizeof(correlation)); |
| 558 | (void) ResetMagickMemory(&mean,0,sizeof(mean)); |
| 559 | (void) ResetMagickMemory(&sum_squares,0,sizeof(sum_squares)); |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 560 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 561 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 562 | #endif |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 563 | for (i=0; i < 4; i++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 564 | { |
| 565 | register long |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 566 | y; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 567 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 568 | for (y=0; y < (long) number_grays; y++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 569 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 570 | register long |
| 571 | x; |
| 572 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 573 | for (x=0; x < (long) number_grays; x++) |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 574 | { |
| 575 | /* |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 576 | Angular second moment: measure of homogeneity of the image. |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 577 | */ |
| 578 | channel_features[RedChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 579 | cooccurrence[x][y].direction[i].red* |
| 580 | cooccurrence[x][y].direction[i].red; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 581 | channel_features[GreenChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 582 | cooccurrence[x][y].direction[i].green* |
| 583 | cooccurrence[x][y].direction[i].green; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 584 | channel_features[BlueChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 585 | cooccurrence[x][y].direction[i].blue* |
| 586 | cooccurrence[x][y].direction[i].blue; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 587 | if (image->matte != MagickFalse) |
| 588 | channel_features[OpacityChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 589 | cooccurrence[x][y].direction[i].opacity* |
| 590 | cooccurrence[x][y].direction[i].opacity; |
cristy | 549a37e | 2010-01-26 15:24:15 +0000 | [diff] [blame] | 591 | if (image->colorspace == CMYKColorspace) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 592 | channel_features[BlackChannel].angular_second_moment[i]+= |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 593 | cooccurrence[x][y].direction[i].index* |
| 594 | cooccurrence[x][y].direction[i].index; |
| 595 | /* |
| 596 | Correlation: measure of linear-dependencies in the image. |
| 597 | */ |
| 598 | sum[y].direction[i].red+=cooccurrence[x][y].direction[i].red; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 599 | sum[y].direction[i].green+=cooccurrence[x][y].direction[i].green; |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 600 | sum[y].direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
| 601 | if (image->matte != MagickFalse) |
| 602 | sum[y].direction[i].opacity+=cooccurrence[x][y].direction[i].opacity; |
| 603 | if (image->colorspace == CMYKColorspace) |
| 604 | sum[y].direction[i].index+=cooccurrence[x][y].direction[i].index; |
| 605 | correlation.direction[i].red+=x*y*cooccurrence[x][y].direction[i].red; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 606 | correlation.direction[i].green+=x*y* |
| 607 | cooccurrence[x][y].direction[i].green; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 608 | correlation.direction[i].blue+=x*y* |
| 609 | cooccurrence[x][y].direction[i].blue; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 610 | if (image->matte != MagickFalse) |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 611 | correlation.direction[i].opacity+=x*y* |
| 612 | cooccurrence[x][y].direction[i].opacity; |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 613 | if (image->colorspace == CMYKColorspace) |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 614 | correlation.direction[i].index+=x*y* |
| 615 | cooccurrence[x][y].direction[i].index; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 616 | /* |
| 617 | Inverse Difference Moment. |
| 618 | */ |
cristy | 9fc6dbf | 2010-01-28 02:49:50 +0000 | [diff] [blame] | 619 | channel_features[RedChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 620 | cooccurrence[x][y].direction[i].red/((y-x)*(y-x)+1); |
cristy | 9fc6dbf | 2010-01-28 02:49:50 +0000 | [diff] [blame] | 621 | channel_features[GreenChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 622 | cooccurrence[x][y].direction[i].green/((y-x)*(y-x)+1); |
cristy | 9fc6dbf | 2010-01-28 02:49:50 +0000 | [diff] [blame] | 623 | channel_features[BlueChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 624 | cooccurrence[x][y].direction[i].blue/((y-x)*(y-x)+1); |
| 625 | if (image->matte != MagickFalse) |
cristy | 9fc6dbf | 2010-01-28 02:49:50 +0000 | [diff] [blame] | 626 | channel_features[OpacityChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 627 | cooccurrence[x][y].direction[i].opacity/((y-x)*(y-x)+1); |
| 628 | if (image->colorspace == CMYKColorspace) |
cristy | 9fc6dbf | 2010-01-28 02:49:50 +0000 | [diff] [blame] | 629 | channel_features[IndexChannel].inverse_difference_moment[i]+= |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 630 | cooccurrence[x][y].direction[i].index/((y-x)*(y-x)+1); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 631 | /* |
| 632 | Sum average. |
| 633 | */ |
| 634 | sum_average[y+x+2].direction[i].red+= |
| 635 | cooccurrence[x][y].direction[i].red; |
| 636 | sum_average[y+x+2].direction[i].green+= |
| 637 | cooccurrence[x][y].direction[i].green; |
| 638 | sum_average[y+x+2].direction[i].blue+= |
| 639 | cooccurrence[x][y].direction[i].blue; |
| 640 | if (image->matte != MagickFalse) |
| 641 | sum_average[y+x+2].direction[i].opacity+= |
| 642 | cooccurrence[x][y].direction[i].opacity; |
| 643 | if (image->colorspace == CMYKColorspace) |
| 644 | sum_average[y+x+2].direction[i].index+= |
| 645 | cooccurrence[x][y].direction[i].index; |
| 646 | /* |
| 647 | Entropy. |
| 648 | */ |
| 649 | channel_features[RedChannel].entropy[i]-= |
| 650 | cooccurrence[x][y].direction[i].red* |
| 651 | log10(cooccurrence[x][y].direction[i].red+MagickEpsilon); |
| 652 | channel_features[GreenChannel].entropy[i]-= |
| 653 | cooccurrence[x][y].direction[i].green* |
| 654 | log10(cooccurrence[x][y].direction[i].green+MagickEpsilon); |
| 655 | channel_features[BlueChannel].entropy[i]-= |
| 656 | cooccurrence[x][y].direction[i].blue* |
| 657 | log10(cooccurrence[x][y].direction[i].blue+MagickEpsilon); |
| 658 | if (image->matte != MagickFalse) |
| 659 | channel_features[OpacityChannel].entropy[i]-= |
| 660 | cooccurrence[x][y].direction[i].opacity* |
| 661 | log10(cooccurrence[x][y].direction[i].opacity+MagickEpsilon); |
| 662 | if (image->colorspace == CMYKColorspace) |
| 663 | channel_features[IndexChannel].entropy[i]-= |
| 664 | cooccurrence[x][y].direction[i].index* |
| 665 | log10(cooccurrence[x][y].direction[i].index+MagickEpsilon); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 666 | } |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 667 | mean.direction[i].red+=y*sum[y].direction[i].red; |
| 668 | sum_squares.direction[i].red+=y*y*sum[y].direction[i].red; |
| 669 | mean.direction[i].green+=y*sum[y].direction[i].green; |
| 670 | sum_squares.direction[i].green+=y*y*sum[y].direction[i].green; |
| 671 | mean.direction[i].blue+=y*sum[y].direction[i].blue; |
| 672 | sum_squares.direction[i].blue+=y*y*sum[y].direction[i].blue; |
| 673 | if (image->matte != MagickFalse) |
| 674 | { |
| 675 | mean.direction[i].opacity+=y*sum[y].direction[i].opacity; |
| 676 | sum_squares.direction[i].opacity+=y*y*sum[y].direction[i].opacity; |
| 677 | } |
| 678 | if (image->colorspace == CMYKColorspace) |
| 679 | { |
| 680 | mean.direction[i].index+=y*sum[y].direction[i].index; |
| 681 | sum_squares.direction[i].index+=y*y*sum[y].direction[i].index; |
| 682 | } |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 683 | } |
cristy | cdf8e1b | 2010-01-28 01:52:33 +0000 | [diff] [blame] | 684 | /* |
| 685 | Correlation: measure of linear-dependencies in the image. |
| 686 | */ |
| 687 | channel_features[RedChannel].correlation[i]= |
| 688 | (correlation.direction[i].red-mean.direction[i].red* |
| 689 | mean.direction[i].red)/(sqrt(sum_squares.direction[i].red- |
| 690 | (mean.direction[i].red*mean.direction[i].red))*sqrt( |
| 691 | sum_squares.direction[i].red-(mean.direction[i].red* |
| 692 | mean.direction[i].red))); |
| 693 | channel_features[GreenChannel].correlation[i]= |
| 694 | (correlation.direction[i].green-mean.direction[i].green* |
| 695 | mean.direction[i].green)/(sqrt(sum_squares.direction[i].green- |
| 696 | (mean.direction[i].green*mean.direction[i].green))*sqrt( |
| 697 | sum_squares.direction[i].green-(mean.direction[i].green* |
| 698 | mean.direction[i].green))); |
| 699 | channel_features[BlueChannel].correlation[i]= |
| 700 | (correlation.direction[i].blue-mean.direction[i].blue* |
| 701 | mean.direction[i].blue)/(sqrt(sum_squares.direction[i].blue- |
| 702 | (mean.direction[i].blue*mean.direction[i].blue))*sqrt( |
| 703 | sum_squares.direction[i].blue-(mean.direction[i].blue* |
| 704 | mean.direction[i].blue))); |
| 705 | if (image->matte != MagickFalse) |
| 706 | channel_features[OpacityChannel].correlation[i]= |
| 707 | (correlation.direction[i].opacity-mean.direction[i].opacity* |
| 708 | mean.direction[i].opacity)/(sqrt(sum_squares.direction[i].opacity- |
| 709 | (mean.direction[i].opacity*mean.direction[i].opacity))*sqrt( |
| 710 | sum_squares.direction[i].opacity-(mean.direction[i].opacity* |
| 711 | mean.direction[i].opacity))); |
| 712 | if (image->colorspace == CMYKColorspace) |
| 713 | channel_features[IndexChannel].correlation[i]= |
| 714 | (correlation.direction[i].index-mean.direction[i].index* |
| 715 | mean.direction[i].index)/(sqrt(sum_squares.direction[i].index- |
| 716 | (mean.direction[i].index*mean.direction[i].index))*sqrt( |
| 717 | sum_squares.direction[i].index-(mean.direction[i].index* |
| 718 | mean.direction[i].index))); |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 719 | } |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 720 | /* |
| 721 | Compute more texture features. |
| 722 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 723 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 724 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 725 | #endif |
| 726 | for (i=0; i < 4; i++) |
| 727 | { |
| 728 | register long |
| 729 | x; |
| 730 | |
| 731 | for (x=2; x < (long) (2*number_grays); x++) |
| 732 | { |
| 733 | /* |
| 734 | Sum average. |
| 735 | */ |
| 736 | channel_features[RedChannel].sum_average[i]+= |
| 737 | x*sum_average[x].direction[i].red; |
| 738 | channel_features[GreenChannel].sum_average[i]+= |
| 739 | x*sum_average[x].direction[i].green; |
| 740 | channel_features[BlueChannel].sum_average[i]+= |
| 741 | x*sum_average[x].direction[i].blue; |
| 742 | if (image->matte != MagickFalse) |
| 743 | channel_features[OpacityChannel].sum_average[i]+= |
| 744 | x*sum_average[x].direction[i].opacity; |
| 745 | if (image->colorspace == CMYKColorspace) |
| 746 | channel_features[IndexChannel].sum_average[i]+= |
| 747 | x*sum_average[x].direction[i].index; |
| 748 | /* |
| 749 | Sum entropy. |
| 750 | */ |
| 751 | channel_features[RedChannel].sum_entropy[i]-= |
| 752 | sum_average[x].direction[i].red* |
| 753 | log10(sum_average[x].direction[i].red+MagickEpsilon); |
| 754 | channel_features[GreenChannel].sum_entropy[i]-= |
| 755 | sum_average[x].direction[i].green* |
| 756 | log10(sum_average[x].direction[i].green+MagickEpsilon); |
| 757 | channel_features[BlueChannel].sum_entropy[i]-= |
| 758 | sum_average[x].direction[i].blue* |
| 759 | log10(sum_average[x].direction[i].blue+MagickEpsilon); |
| 760 | if (image->matte != MagickFalse) |
| 761 | channel_features[OpacityChannel].sum_entropy[i]-= |
| 762 | sum_average[x].direction[i].opacity* |
| 763 | log10(sum_average[x].direction[i].opacity+MagickEpsilon); |
| 764 | if (image->colorspace == CMYKColorspace) |
| 765 | channel_features[IndexChannel].sum_entropy[i]-= |
| 766 | sum_average[x].direction[i].index* |
| 767 | log10(sum_average[x].direction[i].index+MagickEpsilon); |
| 768 | /* |
| 769 | Sum variance. |
| 770 | */ |
| 771 | channel_features[RedChannel].sum_variance[i]+= |
| 772 | (x-channel_features[RedChannel].sum_entropy[i])* |
| 773 | (x-channel_features[RedChannel].sum_entropy[i])* |
| 774 | sum_average[x].direction[i].red; |
| 775 | channel_features[GreenChannel].sum_variance[i]+= |
| 776 | (x-channel_features[GreenChannel].sum_entropy[i])* |
| 777 | (x-channel_features[GreenChannel].sum_entropy[i])* |
| 778 | sum_average[x].direction[i].green; |
| 779 | channel_features[BlueChannel].sum_variance[i]+= |
| 780 | (x-channel_features[BlueChannel].sum_entropy[i])* |
| 781 | (x-channel_features[BlueChannel].sum_entropy[i])* |
| 782 | sum_average[x].direction[i].blue; |
| 783 | if (image->matte != MagickFalse) |
| 784 | channel_features[OpacityChannel].sum_variance[i]+= |
| 785 | (x-channel_features[OpacityChannel].sum_entropy[i])* |
| 786 | (x-channel_features[OpacityChannel].sum_entropy[i])* |
| 787 | sum_average[x].direction[i].opacity; |
| 788 | if (image->colorspace == CMYKColorspace) |
| 789 | channel_features[IndexChannel].sum_variance[i]+= |
| 790 | (x-channel_features[IndexChannel].sum_entropy[i])* |
| 791 | (x-channel_features[IndexChannel].sum_entropy[i])* |
| 792 | sum_average[x].direction[i].index; |
| 793 | } |
| 794 | } |
| 795 | /* |
| 796 | Compute more texture features. |
| 797 | */ |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 798 | (void) ResetMagickMemory(&variance,0,sizeof(variance)); |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 799 | (void) ResetMagickMemory(sum_average,0,2*number_grays*sizeof(*sum_average)); |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 800 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 801 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 802 | #endif |
| 803 | for (i=0; i < 4; i++) |
| 804 | { |
| 805 | register long |
| 806 | y; |
| 807 | |
| 808 | for (y=0; y < (long) number_grays; y++) |
| 809 | { |
| 810 | register long |
| 811 | x; |
| 812 | |
| 813 | for (x=0; x < (long) number_grays; x++) |
| 814 | { |
| 815 | /* |
| 816 | Sum of Squares: Variance |
| 817 | */ |
| 818 | variance.direction[i].red+=(y-mean.direction[i].red+1)* |
| 819 | (y-mean.direction[i].red+1)*cooccurrence[x][y].direction[i].red; |
| 820 | variance.direction[i].green+=(y-mean.direction[i].green+1)* |
| 821 | (y-mean.direction[i].green+1)*cooccurrence[x][y].direction[i].green; |
| 822 | variance.direction[i].blue+=(y-mean.direction[i].blue+1)* |
| 823 | (y-mean.direction[i].blue+1)*cooccurrence[x][y].direction[i].blue; |
| 824 | if (image->matte != MagickFalse) |
| 825 | variance.direction[i].opacity+=(y-mean.direction[i].opacity+1)* |
| 826 | (y-mean.direction[i].opacity+1)* |
| 827 | cooccurrence[x][y].direction[i].opacity; |
| 828 | if (image->colorspace == CMYKColorspace) |
| 829 | variance.direction[i].index+=(y-mean.direction[i].index+1)* |
| 830 | (y-mean.direction[i].index+1)*cooccurrence[x][y].direction[i].index; |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 831 | /* |
| 832 | Sum average. |
| 833 | */ |
| 834 | sum_average[MagickAbsoluteValue(y-x)].direction[i].red+= |
| 835 | cooccurrence[x][y].direction[i].red; |
| 836 | sum_average[MagickAbsoluteValue(y-x)].direction[i].green+= |
| 837 | cooccurrence[x][y].direction[i].green; |
| 838 | sum_average[MagickAbsoluteValue(y-x)].direction[i].blue+= |
| 839 | cooccurrence[x][y].direction[i].blue; |
| 840 | if (image->matte != MagickFalse) |
| 841 | sum_average[MagickAbsoluteValue(y-x)].direction[i].opacity+= |
| 842 | cooccurrence[x][y].direction[i].opacity; |
| 843 | if (image->colorspace == CMYKColorspace) |
| 844 | sum_average[MagickAbsoluteValue(y-x)].direction[i].index+= |
| 845 | cooccurrence[x][y].direction[i].index; |
cristy | cf5e649 | 2010-01-28 02:45:28 +0000 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | channel_features[RedChannel].variance_sum_of_squares[i]= |
| 849 | variance.direction[i].red; |
| 850 | channel_features[GreenChannel].variance_sum_of_squares[i]= |
| 851 | variance.direction[i].green; |
| 852 | channel_features[BlueChannel].variance_sum_of_squares[i]= |
| 853 | variance.direction[i].blue; |
| 854 | if (image->matte != MagickFalse) |
| 855 | channel_features[RedChannel].variance_sum_of_squares[i]= |
| 856 | variance.direction[i].opacity; |
| 857 | if (image->colorspace == CMYKColorspace) |
| 858 | channel_features[RedChannel].variance_sum_of_squares[i]= |
| 859 | variance.direction[i].index; |
| 860 | } |
| 861 | /* |
| 862 | Compute more texture features. |
| 863 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 864 | (void) ResetMagickMemory(&variance,0,sizeof(variance)); |
| 865 | (void) ResetMagickMemory(&sum_squares,0,sizeof(sum_squares)); |
| 866 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 867 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 868 | #endif |
| 869 | for (i=0; i < 4; i++) |
| 870 | { |
| 871 | register long |
| 872 | x; |
| 873 | |
| 874 | for (x=0; x < (long) number_grays; x++) |
| 875 | { |
| 876 | variance.direction[i].red+=sum_average[x].direction[i].red; |
| 877 | variance.direction[i].green+=sum_average[x].direction[i].green; |
| 878 | variance.direction[i].blue+=sum_average[x].direction[i].blue; |
| 879 | if (image->matte != MagickFalse) |
| 880 | variance.direction[i].opacity+=sum_average[x].direction[i].opacity; |
| 881 | if (image->colorspace == CMYKColorspace) |
| 882 | variance.direction[i].index+=sum_average[x].direction[i].index; |
| 883 | sum_squares.direction[i].red+=sum_average[x].direction[i].red* |
| 884 | sum_average[x].direction[i].red; |
| 885 | sum_squares.direction[i].green+=sum_average[x].direction[i].green* |
| 886 | sum_average[x].direction[i].green; |
| 887 | sum_squares.direction[i].blue+=sum_average[x].direction[i].blue* |
| 888 | sum_average[x].direction[i].blue; |
| 889 | if (image->matte != MagickFalse) |
| 890 | sum_squares.direction[i].opacity+=sum_average[x].direction[i].opacity* |
| 891 | sum_average[x].direction[i].opacity; |
| 892 | if (image->colorspace == CMYKColorspace) |
| 893 | sum_squares.direction[i].index+=sum_average[x].direction[i].index* |
| 894 | sum_average[x].direction[i].index; |
| 895 | } |
| 896 | channel_features[RedChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame^] | 897 | (((double) number_grays*number_grays*sum_squares.direction[i].red)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 898 | (variance.direction[i].red*variance.direction[i].red))/ |
| 899 | ((double) number_grays*number_grays*number_grays*number_grays); |
| 900 | channel_features[GreenChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame^] | 901 | (((double) number_grays*number_grays*sum_squares.direction[i].green)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 902 | (variance.direction[i].green*variance.direction[i].green))/ |
| 903 | ((double) number_grays*number_grays*number_grays*number_grays); |
| 904 | channel_features[BlueChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame^] | 905 | (((double) number_grays*number_grays*sum_squares.direction[i].blue)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 906 | (variance.direction[i].blue*variance.direction[i].blue))/ |
| 907 | ((double) number_grays*number_grays*number_grays*number_grays); |
| 908 | if (image->matte != MagickFalse) |
| 909 | channel_features[OpacityChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame^] | 910 | (((double) number_grays*number_grays*sum_squares.direction[i].opacity)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 911 | (variance.direction[i].opacity*variance.direction[i].opacity))/ |
| 912 | ((double) number_grays*number_grays*number_grays*number_grays); |
| 913 | if (image->colorspace == CMYKColorspace) |
| 914 | channel_features[IndexChannel].difference_variance[i]= |
cristy | e0e19dc | 2010-01-29 02:13:08 +0000 | [diff] [blame^] | 915 | (((double) number_grays*number_grays*sum_squares.direction[i].index)- |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 916 | (variance.direction[i].index*variance.direction[i].index))/ |
| 917 | ((double) number_grays*number_grays*number_grays*number_grays); |
| 918 | } |
| 919 | /* |
| 920 | Compute more texture features. |
| 921 | */ |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 922 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
| 923 | #pragma omp parallel for schedule(dynamic,4) shared(status) |
| 924 | #endif |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 925 | for (i=0; i < 4; i++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 926 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 927 | for (z=0; z < (long) number_grays; z++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 928 | { |
| 929 | register long |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 930 | y; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 931 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 932 | ChannelStatistics |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 933 | pixel; |
| 934 | |
| 935 | (void) ResetMagickMemory(&pixel,0,sizeof(pixel)); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 936 | for (y=0; y < (long) number_grays; y++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 937 | { |
cristy | bd82207 | 2010-01-27 00:30:00 +0000 | [diff] [blame] | 938 | register long |
| 939 | x; |
| 940 | |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 941 | for (x=0; x < (long) number_grays; x++) |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 942 | { |
| 943 | /* |
| 944 | Contrast: amount of local variations present in an image. |
| 945 | */ |
| 946 | if (((y-x) == z) || ((x-y) == z)) |
| 947 | { |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 948 | pixel.direction[i].red+=cooccurrence[x][y].direction[i].red; |
| 949 | pixel.direction[i].green+=cooccurrence[x][y].direction[i].green; |
| 950 | pixel.direction[i].blue+=cooccurrence[x][y].direction[i].blue; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 951 | if (image->matte != MagickFalse) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 952 | pixel.direction[i].opacity+= |
| 953 | cooccurrence[x][y].direction[i].opacity; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 954 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 955 | pixel.direction[i].index+=cooccurrence[x][y].direction[i].index; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | } |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 959 | channel_features[RedChannel].contrast[i]+=z*z*pixel.direction[i].red; |
| 960 | channel_features[GreenChannel].contrast[i]+=z*z*pixel.direction[i].green; |
| 961 | channel_features[BlueChannel].contrast[i]+=z*z*pixel.direction[i].blue; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 962 | if (image->matte != MagickFalse) |
| 963 | channel_features[OpacityChannel].contrast[i]+=z*z* |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 964 | pixel.direction[i].opacity; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 965 | if (image->colorspace == CMYKColorspace) |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 966 | channel_features[BlackChannel].contrast[i]+=z*z* |
| 967 | pixel.direction[i].index; |
cristy | 3a82f25 | 2010-01-26 20:31:51 +0000 | [diff] [blame] | 968 | } |
| 969 | } |
cristy | 7e9726d | 2010-01-26 02:08:40 +0000 | [diff] [blame] | 970 | /* |
cristy | f2bf2c7 | 2010-01-25 19:54:15 +0000 | [diff] [blame] | 971 | Relinquish resources. |
| 972 | */ |
cristy | e189779 | 2010-01-29 02:05:50 +0000 | [diff] [blame] | 973 | sum_average=(ChannelStatistics *) RelinquishMagickMemory(sum_average); |
cristy | 7396d88 | 2010-01-27 02:37:56 +0000 | [diff] [blame] | 974 | sum=(ChannelStatistics *) RelinquishMagickMemory(sum); |
| 975 | for (i=0; i < (long) number_grays; i++) |
| 976 | cooccurrence[i]=(ChannelStatistics *) |
| 977 | RelinquishMagickMemory(cooccurrence[i]); |
| 978 | cooccurrence=(ChannelStatistics **) RelinquishMagickMemory(cooccurrence); |
| 979 | grays=(LongPixelPacket *) RelinquishMagickMemory(grays); |
cristy | 3e2860c | 2010-01-24 01:36:30 +0000 | [diff] [blame] | 980 | return(channel_features); |
| 981 | } |