]> granicus.if.org Git - imagemagick/commitdiff
Added image moments to Magick++.
authordirk <dirk@git.imagemagick.org>
Sun, 20 Apr 2014 10:42:32 +0000 (10:42 +0000)
committerdirk <dirk@git.imagemagick.org>
Sun, 20 Apr 2014 10:42:32 +0000 (10:42 +0000)
Magick++/Makefile.am
Magick++/lib/ChannelMoments.cpp [new file with mode: 0644]
Magick++/lib/Image.cpp
Magick++/lib/Magick++/ChannelMoments.h [new file with mode: 0644]
Magick++/lib/Magick++/Image.h
Magick++/lib/Magick++/Include.h

index e4d8420fcd408f7483f8f9f06f5a944856d7dcb0..e380b23197b4661101647f5ea24152f035df6b96 100644 (file)
@@ -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 (file)
index 0000000..60e864c
--- /dev/null
@@ -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
index 3c433877f102f17ba8abadd0c18cbf16551db8f8..b08d4abcb12e5dac2096ef81960730e7e2a194f2 100644 (file)
@@ -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 (file)
index 0000000..fd7773d
--- /dev/null
@@ -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 <vector>
+
+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<double> _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
index bb388d10f4c0a075464eded361d4b97e9e8f280b..7d4bd51515461c975bf2f002f404be4af2edd55f 100644 (file)
@@ -12,6 +12,7 @@
 #include <string>
 #include <list>
 #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);
index 9fd087ac42afd43c17fb6a564cb1dc2d434bc382..57f0ef64e62be34027482ed67eff213918e05a3b 100644 (file)
@@ -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;