• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Dirk Lemstra 2014-2015
4 //
5 // Definition of channel moments.
6 //
7 
8 #if !defined (Magick_ChannelMoments_header)
9 #define Magick_ChannelMoments_header
10 
11 #include "Magick++/Include.h"
12 #include <vector>
13 
14 namespace Magick
15 {
16   class Image;
17 
18   class MagickPPExport ChannelMoments
19   {
20   public:
21 
22     // Default constructor
23     ChannelMoments(void);
24 
25     // Copy constructor
26     ChannelMoments(const ChannelMoments &channelMoments_);
27 
28     // Destroy channel moments
29     ~ChannelMoments(void);
30 
31     // X position of centroid
32     double centroidX(void) const;
33 
34     // Y position of centroid
35     double centroidY(void) const;
36 
37     // The channel
38     PixelChannel channel(void) const;
39 
40     // X position of ellipse axis
41     double ellipseAxisX(void) const;
42 
43     // Y position of ellipse axis
44     double ellipseAxisY(void) const;
45 
46     // Ellipse angle
47     double ellipseAngle(void) const;
48 
49     // Ellipse eccentricity
50     double ellipseEccentricity(void) const;
51 
52     // Ellipse intensity
53     double ellipseIntensity(void) const;
54 
55     // Hu invariants (valid range for index is 0-7)
56     double huInvariants(const size_t index_) const;
57 
58     // Does object contain valid channel moments?
59     bool isValid() const;
60 
61     //
62     // Implemementation methods
63     //
64 
65     ChannelMoments(const PixelChannel channel_,
66       const MagickCore::ChannelMoments *channelMoments_);
67 
68   private:
69     PixelChannel _channel;
70     std::vector<double> _huInvariants;
71     double _centroidX;
72     double _centroidY;
73     double _ellipseAxisX;
74     double _ellipseAxisY;
75     double _ellipseAngle;
76     double _ellipseEccentricity;
77     double _ellipseIntensity;
78   };
79 
80   class MagickPPExport ChannelPerceptualHash
81   {
82   public:
83 
84     // Default constructor
85     ChannelPerceptualHash(void);
86 
87     // Copy constructor
88     ChannelPerceptualHash(const ChannelPerceptualHash &channelPerceptualHash_);
89 
90     // Constructor using the specified hash string
91     ChannelPerceptualHash(const PixelChannel channel_,
92       const std::string &hash_);
93 
94     // Destroy channel perceptual hash
95     ~ChannelPerceptualHash(void);
96 
97     // Return hash string
98     operator std::string() const;
99 
100     // The channel
101     PixelChannel channel(void) const;
102 
103     // Does object contain valid channel perceptual hash?
104     bool isValid() const;
105 
106     // Returns the sum squared difference between this hash and the other hash
107     double sumSquaredDifferences(
108       const ChannelPerceptualHash &channelPerceptualHash_);
109 
110     // SRGB hu preceptual hash (valid range for index is 0-6)
111     double srgbHuPhash(const size_t index_) const;
112 
113     // HCLp hu preceptual hash (valid range for index is 0-6)
114     double hclpHuPhash(const size_t index_) const;
115 
116     //
117     // Implemementation methods
118     //
119 
120     ChannelPerceptualHash(const PixelChannel channel_,
121       const MagickCore::ChannelPerceptualHash *channelPerceptualHash_);
122 
123   private:
124     PixelChannel _channel;
125     std::vector<double> _srgbHuPhash;
126     std::vector<double> _hclpHuPhash;
127   };
128 
129   // Obtain image statistics. Statistics are normalized to the range
130   // of 0.0 to 1.0 and are output to the specified ImageStatistics
131   // structure.
132   class MagickPPExport ChannelStatistics
133   {
134   public:
135 
136     // Default constructor
137     ChannelStatistics(void);
138 
139     // Copy constructor
140     ChannelStatistics(const ChannelStatistics &channelStatistics_);
141 
142     // Destroy channel statistics
143     ~ChannelStatistics(void);
144 
145     // Area
146     double area() const;
147 
148     // The channel
149     PixelChannel channel(void) const;
150 
151     // Depth
152     size_t depth() const;
153 
154     // Entropy
155     double entropy() const;
156 
157     // Does object contain valid channel statistics?
158     bool isValid() const;
159 
160     // Kurtosis
161     double kurtosis() const;
162 
163     // Minimum value observed
164     double maxima() const;
165 
166     // Average (mean) value observed
167     double mean() const;
168 
169     // Maximum value observed
170     double minima() const;
171 
172     // Skewness
173     double skewness() const;
174 
175     // Standard deviation, sqrt(variance)
176     double standardDeviation() const;
177 
178     // Sum
179     double sum() const;
180 
181     // Sum cubed
182     double sumCubed() const;
183 
184     // Sum fourth power
185     double sumFourthPower() const;
186 
187     // Sum squared
188     double sumSquared() const;
189 
190     // Variance
191     double variance() const;
192 
193     //
194     // Implemementation methods
195     //
196 
197     ChannelStatistics(const PixelChannel channel_,
198       const MagickCore::ChannelStatistics *channelStatistics_);
199 
200   private:
201     PixelChannel _channel;
202     double _area;
203     size_t _depth;
204     double _entropy;
205     double _kurtosis;
206     double _maxima;
207     double _mean;
208     double _minima;
209     double _skewness;
210     double _standardDeviation;
211     double _sum;
212     double _sumCubed;
213     double _sumFourthPower;
214     double _sumSquared;
215     double _variance;
216   };
217 
218   class MagickPPExport ImageMoments
219   {
220   public:
221 
222     // Default constructor
223     ImageMoments(void);
224 
225     // Copy constructor
226     ImageMoments(const ImageMoments &imageMoments_);
227 
228     // Destroy image moments
229     ~ImageMoments(void);
230 
231     // Returns the moments for the specified channel
232     ChannelMoments channel(const PixelChannel channel_) const;
233 
234     //
235     // Implemementation methods
236     //
237     ImageMoments(const Image &image_);
238 
239   private:
240     std::vector<ChannelMoments> _channels;
241   };
242 
243   class MagickPPExport ImagePerceptualHash
244   {
245   public:
246 
247     // Default constructor
248     ImagePerceptualHash(void);
249 
250     // Copy constructor
251     ImagePerceptualHash(const ImagePerceptualHash &imagePerceptualHash_);
252 
253     // Constructor using the specified hash string
254     ImagePerceptualHash(const std::string &hash_);
255 
256     // Destroy image perceptual hash
257     ~ImagePerceptualHash(void);
258 
259     // Return hash string
260     operator std::string() const;
261 
262     // Returns the perceptual hash for the specified channel
263     ChannelPerceptualHash channel(const PixelChannel channel_) const;
264 
265     // Does object contain valid perceptual hash?
266     bool isValid() const;
267 
268     // Returns the sum squared difference between this hash and the other hash
269     double sumSquaredDifferences(
270       const ImagePerceptualHash &channelPerceptualHash_);
271 
272     //
273     // Implemementation methods
274     //
275     ImagePerceptualHash(const Image &image_);
276 
277   private:
278     std::vector<ChannelPerceptualHash> _channels;
279   };
280 
281   class MagickPPExport ImageStatistics
282   {
283   public:
284 
285     // Default constructor
286     ImageStatistics(void);
287 
288     // Copy constructor
289     ImageStatistics(const ImageStatistics &imageStatistics_);
290 
291     // Destroy image statistics
292     ~ImageStatistics(void);
293 
294     // Returns the statistics for the specified channel
295     ChannelStatistics channel(const PixelChannel channel_) const;
296 
297     //
298     // Implemementation methods
299     //
300     ImageStatistics(const Image &image_);
301 
302   private:
303     std::vector<ChannelStatistics> _channels;
304   };
305 }
306 
307 #endif // Magick_ChannelMoments_header
308