From: dirk Date: Sun, 20 Apr 2014 10:42:32 +0000 (+0000) Subject: Added image moments to Magick++. X-Git-Tag: 7.0.1-0~2434 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=617c1234f713a6b7068e2a5abbf94a23f77c8181;p=imagemagick Added image moments to Magick++. --- diff --git a/Magick++/Makefile.am b/Magick++/Makefile.am index e4d8420fc..e380b2319 100644 --- a/Magick++/Makefile.am +++ b/Magick++/Makefile.am @@ -71,6 +71,7 @@ MAGICKPP_CLEANFILES = \ Magick___lib_libMagick___@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la_SOURCES = \ Magick++/lib/Blob.cpp \ Magick++/lib/BlobRef.cpp \ + Magick++/lib/ChannelMoments.cpp \ Magick++/lib/CoderInfo.cpp \ Magick++/lib/Color.cpp \ Magick++/lib/Drawable.cpp \ @@ -89,6 +90,7 @@ Magick___lib_libMagick___@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la_SOURCES = Magick++/lib/Magick++.h \ Magick++/lib/Magick++/Blob.h \ Magick++/lib/Magick++/BlobRef.h \ + Magick++/lib/Magick++/ChannelMoments.h \ Magick++/lib/Magick++/CoderInfo.h \ Magick++/lib/Magick++/Color.h \ Magick++/lib/Magick++/Drawable.h \ @@ -118,6 +120,7 @@ magickppinc_HEADERS = $(MAGICKPP_INCHEADERS) MAGICKPP_INCHEADERS_OPT = \ Magick++/lib/Magick++/Blob.h \ + Magick++/lib/Magick++/ChannelMoments.h \ Magick++/lib/Magick++/CoderInfo.h \ Magick++/lib/Magick++/Color.h \ Magick++/lib/Magick++/Drawable.h \ diff --git a/Magick++/lib/ChannelMoments.cpp b/Magick++/lib/ChannelMoments.cpp new file mode 100644 index 000000000..60e864ce3 --- /dev/null +++ b/Magick++/lib/ChannelMoments.cpp @@ -0,0 +1,104 @@ +// This may look like C code, but it is really -*- C++ -*- +// +// Copyright Dirk Lemstra, 2014 +// +// Implementation of channel moments. +// + +#define MAGICKCORE_IMPLEMENTATION 1 +#define MAGICK_PLUSPLUS_IMPLEMENTATION 1 + +#include "Magick++/Include.h" +#include "Magick++/ChannelMoments.h" + +using namespace std; + +Magick::ChannelMoments::ChannelMoments(void) + : _huInvariants(), + _centroidX(0.0), + _centroidY(0.0), + _ellipseAxisX(0.0), + _ellipseAxisY(0.0), + _ellipseAngle(0.0), + _ellipseEccentricity(0.0), + _ellipseIntensity(0.0) +{ +} + +Magick::ChannelMoments::ChannelMoments(const ChannelMoments &channelMoments_) + : _huInvariants(channelMoments_._huInvariants), + _centroidX(channelMoments_._centroidX), + _centroidY(channelMoments_._centroidY), + _ellipseAxisX(channelMoments_._ellipseAxisX), + _ellipseAxisY(channelMoments_._ellipseAxisY), + _ellipseAngle(channelMoments_._ellipseAngle), + _ellipseEccentricity(channelMoments_._ellipseEccentricity), + _ellipseIntensity(channelMoments_._ellipseIntensity) +{ +//channelMoments_ +} + +Magick::ChannelMoments::~ChannelMoments(void) +{ +} + +Magick::ChannelMoments::ChannelMoments( + const MagickCore::ChannelMoments *channelMoments_) + : _huInvariants(), + _centroidX(channelMoments_->centroid.x), + _centroidY(channelMoments_->centroid.y), + _ellipseAxisX(channelMoments_->ellipse_axis.x), + _ellipseAxisY(channelMoments_->ellipse_axis.y), + _ellipseAngle(channelMoments_->ellipse_angle), + _ellipseEccentricity(channelMoments_->ellipse_eccentricity), + _ellipseIntensity(channelMoments_->ellipse_intensity) +{ + size_t + i; + + for (i=0; i<8; i++) + _huInvariants.push_back(channelMoments_->I[i]); +} + +double Magick::ChannelMoments::centroidX(void) const +{ + return(_centroidX); +} + +double Magick::ChannelMoments::centroidY(void) const +{ + return(_centroidY); +} + +double Magick::ChannelMoments::ellipseAxisX(void) const +{ + return(_ellipseAxisX); +} + +double Magick::ChannelMoments::ellipseAxisY(void) const +{ + return(_ellipseAxisY); +} + +double Magick::ChannelMoments::ellipseAngle(void) const +{ + return(_ellipseAngle); +} + +double Magick::ChannelMoments::ellipseEccentricity(void) const +{ + return(_ellipseEccentricity); +} + +double Magick::ChannelMoments::ellipseIntensity(void) const +{ + return(_ellipseIntensity); +} + +double Magick::ChannelMoments::huInvariants(const size_t index_) const +{ + if (index_ > 7) + throw std::out_of_range("Valid range for index is 0-7"); + + return(_huInvariants.at(index_)); +} \ No newline at end of file diff --git a/Magick++/lib/Image.cpp b/Magick++/lib/Image.cpp index 3c433877f..b08d4abcb 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -3361,6 +3361,26 @@ void Magick::Image::modulate(const double brightness_,const double saturation_, ThrowPPException; } +Magick::ChannelMoments 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); +} + void Magick::Image::morphology(const MorphologyMethod method_, const std::string kernel_,const ssize_t iterations_) { diff --git a/Magick++/lib/Magick++/ChannelMoments.h b/Magick++/lib/Magick++/ChannelMoments.h new file mode 100644 index 000000000..fd7773da2 --- /dev/null +++ b/Magick++/lib/Magick++/ChannelMoments.h @@ -0,0 +1,71 @@ +// This may look like C code, but it is really -*- C++ -*- +// +// Copyright Dirk Lemstra, 2014 +// +// Definition of channel moments. +// + +#if !defined (Magick_ChannelMoments_header) +#define Magick_ChannelMoments_header + +#include "Magick++/Include.h" +#include + +namespace Magick +{ + class MagickPPExport ChannelMoments + { + public: + + // Default constructor + ChannelMoments(void); + + // Copy constructor + ChannelMoments(const ChannelMoments &channelMoments_); + + // Destroy channel moments + ~ChannelMoments(void); + + // + // Implemementation methods + // + ChannelMoments(const MagickCore::ChannelMoments *channelMoments_); + + // X position of centroid + double centroidX(void) const; + + // Y position of centroid + double centroidY(void) const; + + // X position of ellipse axis + double ellipseAxisX(void) const; + + // Y position of ellipse axis + double ellipseAxisY(void) const; + + // Ellipse angle + double ellipseAngle(void) const; + + // Ellipse eccentricity + double ellipseEccentricity(void) const; + + // Ellipse intensity + double ellipseIntensity(void) const; + + // Hu invariants (valid range for index is 0-7) + double huInvariants(const size_t index_) const; + + private: + std::vector _huInvariants; + double _centroidX; + double _centroidY; + double _ellipseAxisX; + double _ellipseAxisY; + double _ellipseAngle; + double _ellipseEccentricity; + double _ellipseIntensity; + }; + +} + +#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 bb388d10f..7d4bd5151 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -12,6 +12,7 @@ #include #include #include "Magick++/Blob.h" +#include "Magick++/ChannelMoments.h" #include "Magick++/Color.h" #include "Magick++/Drawable.h" #include "Magick++/Exception.h" @@ -1018,6 +1019,9 @@ namespace Magick void modulate(const double brightness_,const double saturation_, const double hue_); + // Returns the normalized moments of one or more image channels. + ChannelMoments moments(void); + // Applies a kernel to the image according to the given mophology method. void morphology(const MorphologyMethod method_,const std::string kernel_, const ssize_t iterations_=1); diff --git a/Magick++/lib/Magick++/Include.h b/Magick++/lib/Magick++/Include.h index 9fd087ac4..57f0ef64e 100644 --- a/Magick++/lib/Magick++/Include.h +++ b/Magick++/lib/Magick++/Include.h @@ -1214,6 +1214,7 @@ namespace Magick using MagickCore::GetExceptionInfo; using MagickCore::GetGeometry; using MagickCore::GetImageArtifact; + using MagickCore::GetImageMoments; using MagickCore::GetImageBoundingBox; using MagickCore::GetImageDistortion; using MagickCore::GetImageDepth;