using namespace std;
Magick::ChannelMoments::ChannelMoments(void)
- : _huInvariants(),
+ : _huInvariants(8),
+ _channel(UndefinedChannel),
_centroidX(0.0),
_centroidY(0.0),
_ellipseAxisX(0.0),
Magick::ChannelMoments::ChannelMoments(const ChannelMoments &channelMoments_)
: _huInvariants(channelMoments_._huInvariants),
+ _channel(channelMoments_._channel),
_centroidX(channelMoments_._centroidX),
_centroidY(channelMoments_._centroidY),
_ellipseAxisX(channelMoments_._ellipseAxisX),
_ellipseEccentricity(channelMoments_._ellipseEccentricity),
_ellipseIntensity(channelMoments_._ellipseIntensity)
{
-//channelMoments_
}
Magick::ChannelMoments::~ChannelMoments(void)
{
}
-Magick::ChannelMoments::ChannelMoments(
+Magick::ChannelMoments::ChannelMoments(const ChannelType channel_,
const MagickCore::ChannelMoments *channelMoments_)
: _huInvariants(),
+ _channel(channel_),
_centroidX(channelMoments_->centroid.x),
_centroidY(channelMoments_->centroid.y),
_ellipseAxisX(channelMoments_->ellipse_axis.x),
return(_centroidY);
}
+Magick::ChannelType Magick::ChannelMoments::channel(void) const
+{
+ return(_channel);
+}
+
double Magick::ChannelMoments::ellipseAxisX(void) const
{
return(_ellipseAxisX);
throw ErrorOption("Valid range for index is 0-7");
return(_huInvariants.at(index_));
+}
+
+Magick::ImageMoments::ImageMoments(void)
+ : _channels()
+{
+}
+
+Magick::ImageMoments::ImageMoments(const ImageMoments &imageMoments_)
+ : _channels(imageMoments_._channels)
+{
+}
+
+Magick::ImageMoments::~ImageMoments(void)
+{
+}
+
+Magick::ChannelMoments Magick::ImageMoments::channel(
+ const ChannelType channel_) const
+{
+ for (std::vector<ChannelMoments>::const_iterator it = _channels.begin();
+ it != _channels.end(); ++it)
+ {
+ if (it->channel() == channel_)
+ return(*it);
+ }
+ return(ChannelMoments());
+}
+
+Magick::ImageMoments::ImageMoments(const MagickCore::Image *image)
+ : _channels()
+{
+ MagickCore::ChannelMoments*
+ channel_moments;
+
+ GetPPException;
+ channel_moments=GetImageMoments(image,&exceptionInfo);
+ if (channel_moments != (MagickCore::ChannelMoments *) NULL)
+ {
+ switch(image->colorspace)
+ {
+ case RGBColorspace:
+ default:
+ _channels.push_back(Magick::ChannelMoments(RedChannel,
+ &channel_moments[RedChannel]));
+ _channels.push_back(Magick::ChannelMoments(GreenChannel,
+ &channel_moments[GreenChannel]));
+ _channels.push_back(Magick::ChannelMoments(BlueChannel,
+ &channel_moments[BlueChannel]));
+ break;
+ case CMYKColorspace:
+ _channels.push_back(Magick::ChannelMoments(CyanChannel,
+ &channel_moments[CyanChannel]));
+ _channels.push_back(Magick::ChannelMoments(MagentaChannel,
+ &channel_moments[MagentaChannel]));
+ _channels.push_back(Magick::ChannelMoments(YellowChannel,
+ &channel_moments[YellowChannel]));
+ _channels.push_back(Magick::ChannelMoments(BlackChannel,
+ &channel_moments[BlackChannel]));
+ break;
+ case GRAYColorspace:
+ _channels.push_back(Magick::ChannelMoments(GrayChannel,
+ &channel_moments[GrayChannel]));
+ break;
+ }
+ if (image->alpha_trait == BlendPixelTrait)
+ _channels.push_back(Magick::ChannelMoments(AlphaChannel,
+ &channel_moments[AlphaChannel]));
+ if (image->colorspace != GRAYColorspace)
+ _channels.push_back(Magick::ChannelMoments(CompositeChannels,
+ &channel_moments[CompositeChannels]));
+ channel_moments=(MagickCore::ChannelMoments *) RelinquishMagickMemory(
+ channel_moments);
+ }
+ ThrowPPException;
}
\ No newline at end of file
//
// Implemementation methods
//
- ChannelMoments(const MagickCore::ChannelMoments *channelMoments_);
+
+ ChannelMoments(const ChannelType channel_,
+ const MagickCore::ChannelMoments *channelMoments_);
// X position of centroid
double centroidX(void) const;
// Y position of centroid
double centroidY(void) const;
+ // The channel
+ ChannelType channel(void) const;
+
// X position of ellipse axis
double ellipseAxisX(void) const;
private:
std::vector<double> _huInvariants;
+ ChannelType _channel;
double _centroidX;
double _centroidY;
double _ellipseAxisX;
double _ellipseIntensity;
};
+ class MagickPPExport ImageMoments
+ {
+ public:
+
+ // Default constructor
+ ImageMoments(void);
+
+ // Copy constructor
+ ImageMoments(const ImageMoments &imageMoments_);
+
+ // Destroy image moments
+ ~ImageMoments(void);
+
+ // Returns the moments for the specified channel
+ ChannelMoments channel(const ChannelType channel_=CompositeChannels) const;
+
+ //
+ // Implemementation methods
+ //
+ ImageMoments(const MagickCore::Image *image_);
+
+ private:
+ std::vector<ChannelMoments> _channels;
+ };
}
#endif // Magick_ChannelMoments_header
\ No newline at end of file