Magick++  7.0.9
ChannelMoments.cpp
Go to the documentation of this file.
1 // This may look like C code, but it is really -*- C++ -*-
2 //
3 // Copyright Dirk Lemstra 2014-2015
4 //
5 // Implementation of channel moments.
6 //
7 
8 #define MAGICKCORE_IMPLEMENTATION 1
9 #define MAGICK_PLUSPLUS_IMPLEMENTATION 1
10 
11 #include "Magick++/Include.h"
13 #include "Magick++/Exception.h"
14 #include "Magick++/Image.h"
15 
16 using namespace std;
17 
19  : _huInvariants(8),
20  _channel(UndefinedChannel),
21  _centroidX(0.0),
22  _centroidY(0.0),
23  _ellipseAxisX(0.0),
24  _ellipseAxisY(0.0),
25  _ellipseAngle(0.0),
26  _ellipseEccentricity(0.0),
27  _ellipseIntensity(0.0)
28 {
29 }
30 
32  : _huInvariants(channelMoments_._huInvariants),
33  _channel(channelMoments_._channel),
34  _centroidX(channelMoments_._centroidX),
35  _centroidY(channelMoments_._centroidY),
36  _ellipseAxisX(channelMoments_._ellipseAxisX),
37  _ellipseAxisY(channelMoments_._ellipseAxisY),
38  _ellipseAngle(channelMoments_._ellipseAngle),
39  _ellipseEccentricity(channelMoments_._ellipseEccentricity),
40  _ellipseIntensity(channelMoments_._ellipseIntensity)
41 {
42 }
43 
45 {
46 }
47 
48 Magick::ChannelMoments::ChannelMoments(const ChannelType channel_,
49  const MagickCore::ChannelMoments *channelMoments_)
50  : _huInvariants(),
51  _channel(channel_),
52  _centroidX(channelMoments_->centroid.x),
53  _centroidY(channelMoments_->centroid.y),
54  _ellipseAxisX(channelMoments_->ellipse_axis.x),
55  _ellipseAxisY(channelMoments_->ellipse_axis.y),
56  _ellipseAngle(channelMoments_->ellipse_angle),
57  _ellipseEccentricity(channelMoments_->ellipse_eccentricity),
58  _ellipseIntensity(channelMoments_->ellipse_intensity)
59 {
60  size_t
61  i;
62 
63  for (i=0; i<8; i++)
64  _huInvariants.push_back(channelMoments_->I[i]);
65 }
66 
68 {
69  return(_centroidX);
70 }
71 
73 {
74  return(_centroidY);
75 }
76 
77 Magick::ChannelType Magick::ChannelMoments::channel(void) const
78 {
79  return(_channel);
80 }
81 
83 {
84  return(_ellipseAxisX);
85 }
86 
88 {
89  return(_ellipseAxisY);
90 }
91 
93 {
94  return(_ellipseAngle);
95 }
96 
98 {
99  return(_ellipseEccentricity);
100 }
101 
103 {
104  return(_ellipseIntensity);
105 }
106 
107 double Magick::ChannelMoments::huInvariants(const size_t index_) const
108 {
109  if (index_ > 7)
110  throw ErrorOption("Valid range for index is 0-7");
111 
112  return(_huInvariants.at(index_));
113 }
114 
116  : _channels()
117 {
118 }
119 
121  : _channels(imageMoments_._channels)
122 {
123 }
124 
126 {
127 }
128 
130  const ChannelType channel_) const
131 {
132  for (std::vector<ChannelMoments>::const_iterator it = _channels.begin();
133  it != _channels.end(); ++it)
134  {
135  if (it->channel() == channel_)
136  return(*it);
137  }
138  return(ChannelMoments());
139 }
140 
142  : _channels()
143 {
144  MagickCore::ChannelMoments*
145  channel_moments;
146 
148  channel_moments=GetImageChannelMoments(image_.constImage(),exceptionInfo);
149  if (channel_moments != (MagickCore::ChannelMoments *) NULL)
150  {
151  switch(image_.constImage()->colorspace)
152  {
153  case RGBColorspace:
154  default:
155  _channels.push_back(Magick::ChannelMoments(RedChannel,
156  &channel_moments[RedChannel]));
157  _channels.push_back(Magick::ChannelMoments(GreenChannel,
158  &channel_moments[GreenChannel]));
159  _channels.push_back(Magick::ChannelMoments(BlueChannel,
160  &channel_moments[BlueChannel]));
161  break;
162  case CMYKColorspace:
163  _channels.push_back(Magick::ChannelMoments(CyanChannel,
164  &channel_moments[CyanChannel]));
165  _channels.push_back(Magick::ChannelMoments(MagentaChannel,
166  &channel_moments[MagentaChannel]));
167  _channels.push_back(Magick::ChannelMoments(YellowChannel,
168  &channel_moments[YellowChannel]));
169  _channels.push_back(Magick::ChannelMoments(BlackChannel,
170  &channel_moments[BlackChannel]));
171  break;
172  case GRAYColorspace:
173  _channels.push_back(Magick::ChannelMoments(GrayChannel,
174  &channel_moments[GrayChannel]));
175  break;
176  }
177  if (image_.constImage()->matte != MagickFalse)
178  _channels.push_back(Magick::ChannelMoments(AlphaChannel,
179  &channel_moments[AlphaChannel]));
180  if (image_.constImage()->colorspace != GRAYColorspace)
181  _channels.push_back(Magick::ChannelMoments(CompositeChannels,
182  &channel_moments[CompositeChannels]));
183  channel_moments=(MagickCore::ChannelMoments *) RelinquishMagickMemory(
184  channel_moments);
185  }
186  ThrowPPException(image_.quiet());
187 }
double huInvariants(const size_t index_) const
double ellipseIntensity(void) const
void quiet(const bool quiet_)
Definition: Image.cpp:1379
double ellipseAngle(void) const
double ellipseEccentricity(void) const
double ellipseAxisY(void) const
const MagickCore::Image * constImage(void) const
Definition: Image.cpp:5043
#define ThrowPPException(quiet)
Definition: Include.h:1524
double centroidY(void) const
ChannelType channel(void) const
double centroidX(void) const
ChannelMoments channel(const ChannelType channel_=CompositeChannels) const
double ellipseAxisX(void) const
#define GetPPException
Definition: Include.h:1520