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 | % |
| 103 | % GetImageChannelFeatures() returns features for each channel in the |
| 104 | % image. The features include the angular second momentum, contrast, |
| 105 | % correlation, sum of squares: variance, inverse difference moment, sum |
| 106 | % average, sum varience, sum entropy, entropy, difference variance, difference |
| 107 | % entropy, information measures of correlation 1, information measures of |
| 108 | % correlation 2, and maximum correlation coefficient. You can access the red |
| 109 | % channel contrast, for example, like this: |
| 110 | % |
| 111 | % channel_features=GetImageChannelFeatures(image,excepton); |
| 112 | % contrast=channel_features[RedChannel].contrast; |
| 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, |
| 119 | % ExceptionInfo *exception) |
| 120 | % |
| 121 | % A description of each parameter follows: |
| 122 | % |
| 123 | % o image: the image. |
| 124 | % |
| 125 | % o exception: return any errors or warnings in this structure. |
| 126 | % |
| 127 | */ |
| 128 | MagickExport ChannelFeatures *GetImageChannelFeatures(const Image *image, |
| 129 | ExceptionInfo *exception) |
| 130 | { |
| 131 | ChannelFeatures |
| 132 | *channel_features; |
| 133 | |
| 134 | long |
| 135 | y; |
| 136 | |
| 137 | size_t |
| 138 | length; |
| 139 | |
| 140 | assert(image != (Image *) NULL); |
| 141 | assert(image->signature == MagickSignature); |
| 142 | if (image->debug != MagickFalse) |
| 143 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 144 | length=AllChannels+1UL; |
| 145 | channel_features=(ChannelFeatures *) AcquireQuantumMemory(length, |
| 146 | sizeof(*channel_features)); |
| 147 | if (channel_features == (ChannelFeatures *) NULL) |
| 148 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 149 | (void) ResetMagickMemory(channel_features,0,length* |
| 150 | sizeof(*channel_features)); |
| 151 | for (y=0; y < (long) image->rows; y++) |
| 152 | { |
| 153 | register const IndexPacket |
| 154 | *restrict indexes; |
| 155 | |
| 156 | register const PixelPacket |
| 157 | *restrict p; |
| 158 | |
| 159 | register long |
| 160 | x; |
| 161 | |
| 162 | p=GetVirtualPixels(image,0,y,image->columns,1,exception); |
| 163 | if (p == (const PixelPacket *) NULL) |
| 164 | break; |
| 165 | indexes=GetVirtualIndexQueue(image); |
| 166 | for (x=0; x < (long) image->columns; x++) |
| 167 | { |
| 168 | p++; |
| 169 | } |
| 170 | } |
| 171 | return(channel_features); |
| 172 | } |