From: dirk Date: Tue, 29 Apr 2014 04:58:45 +0000 (+0000) Subject: Added new class to support multiple ChannelMoments. X-Git-Tag: 7.0.1-0~2388 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1dc9872b1090aee0396c72f854d103bcd94cb07b;p=imagemagick Added new class to support multiple ChannelMoments. --- diff --git a/Magick++/lib/ChannelMoments.cpp b/Magick++/lib/ChannelMoments.cpp index 652a5ce16..9e637248a 100644 --- a/Magick++/lib/ChannelMoments.cpp +++ b/Magick++/lib/ChannelMoments.cpp @@ -15,7 +15,8 @@ using namespace std; Magick::ChannelMoments::ChannelMoments(void) - : _huInvariants(), + : _huInvariants(8), + _channel(UndefinedChannel), _centroidX(0.0), _centroidY(0.0), _ellipseAxisX(0.0), @@ -28,6 +29,7 @@ Magick::ChannelMoments::ChannelMoments(void) Magick::ChannelMoments::ChannelMoments(const ChannelMoments &channelMoments_) : _huInvariants(channelMoments_._huInvariants), + _channel(channelMoments_._channel), _centroidX(channelMoments_._centroidX), _centroidY(channelMoments_._centroidY), _ellipseAxisX(channelMoments_._ellipseAxisX), @@ -36,16 +38,16 @@ Magick::ChannelMoments::ChannelMoments(const ChannelMoments &channelMoments_) _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), @@ -71,6 +73,11 @@ double Magick::ChannelMoments::centroidY(void) const return(_centroidY); } +Magick::ChannelType Magick::ChannelMoments::channel(void) const +{ + return(_channel); +} + double Magick::ChannelMoments::ellipseAxisX(void) const { return(_ellipseAxisX); @@ -102,4 +109,78 @@ double Magick::ChannelMoments::huInvariants(const size_t index_) const 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::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 diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index c3b828cef..1a261b404 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -3396,24 +3396,9 @@ void Magick::Image::modulate(const double brightness_,const double saturation_, ThrowPPException; } -Magick::ChannelMoments Magick::Image::moments(void) +Magick::ImageMoments Magick::Image::moments(void) { - ChannelMoments - channelMoments; - - MagickCore::ChannelMoments* - channel_moments; - - GetPPException; - channel_moments=GetImageMoments(constImage(),&exceptionInfo); - if (channel_moments != (MagickCore::ChannelMoments *) NULL) - { - channelMoments=ChannelMoments(channel_moments); - channel_moments=(MagickCore::ChannelMoments *) RelinquishMagickMemory( - channel_moments); - } - ThrowPPException; - return(channelMoments); + return(ImageMoments(constImage())); } void Magick::Image::morphology(const MorphologyMethod method_, diff --git a/Magick++/lib/Magick++/ChannelMoments.h b/Magick++/lib/Magick++/ChannelMoments.h index fd7773da2..d4d491d2a 100644 --- a/Magick++/lib/Magick++/ChannelMoments.h +++ b/Magick++/lib/Magick++/ChannelMoments.h @@ -29,7 +29,9 @@ namespace Magick // // Implemementation methods // - ChannelMoments(const MagickCore::ChannelMoments *channelMoments_); + + ChannelMoments(const ChannelType channel_, + const MagickCore::ChannelMoments *channelMoments_); // X position of centroid double centroidX(void) const; @@ -37,6 +39,9 @@ namespace Magick // Y position of centroid double centroidY(void) const; + // The channel + ChannelType channel(void) const; + // X position of ellipse axis double ellipseAxisX(void) const; @@ -57,6 +62,7 @@ namespace Magick private: std::vector _huInvariants; + ChannelType _channel; double _centroidX; double _centroidY; double _ellipseAxisX; @@ -66,6 +72,30 @@ namespace Magick 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 _channels; + }; } #endif // Magick_ChannelMoments_header \ No newline at end of file diff --git a/Magick++/lib/Magick++/Image.h b/Magick++/lib/Magick++/Image.h index 8909d9680..c10344b00 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -1032,7 +1032,7 @@ namespace Magick const double hue_); // Returns the normalized moments of one or more image channels. - ChannelMoments moments(void); + ImageMoments moments(void); // Applies a kernel to the image according to the given mophology method. void morphology(const MorphologyMethod method_,const std::string kernel_,