From: dirk Date: Sat, 16 Aug 2014 11:03:53 +0000 (+0000) Subject: Renamed ChannelMoments files to Statistic. X-Git-Tag: 7.0.1-0~2092 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7b6b37ee0712fc684e19cf3b7472cf9063b3d2f5;p=imagemagick Renamed ChannelMoments files to Statistic. ImageStatistics/ImageChannelStatistics are not longer nested. Renamed ImageChannelStatistics to ChannelStatistics. --- diff --git a/Magick++/Makefile.am b/Magick++/Makefile.am index 64b2a90ba..00591bdf2 100644 --- a/Magick++/Makefile.am +++ b/Magick++/Makefile.am @@ -73,7 +73,6 @@ 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 \ @@ -86,13 +85,13 @@ Magick___lib_libMagick___@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la_SOURCES = Magick++/lib/Options.cpp \ Magick++/lib/Pixels.cpp \ Magick++/lib/ResourceLimits.cpp \ + Magick++/lib/Statistic.cpp \ Magick++/lib/STL.cpp \ Magick++/lib/Thread.cpp \ Magick++/lib/TypeMetric.cpp \ 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 \ @@ -106,6 +105,7 @@ Magick___lib_libMagick___@MAGICK_MAJOR_VERSION@_@MAGICK_ABI_SUFFIX@_la_SOURCES = Magick++/lib/Magick++/Options.h \ Magick++/lib/Magick++/Pixels.h \ Magick++/lib/Magick++/ResourceLimits.h \ + Magick++/lib/Magick++/Statistic.h \ Magick++/lib/Magick++/STL.h \ Magick++/lib/Magick++/Thread.h \ Magick++/lib/Magick++/TypeMetric.h @@ -126,7 +126,6 @@ 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 \ @@ -138,6 +137,7 @@ MAGICKPP_INCHEADERS_OPT = \ Magick++/lib/Magick++/Montage.h \ Magick++/lib/Magick++/Pixels.h \ Magick++/lib/Magick++/ResourceLimits.h \ + Magick++/lib/Magick++/Statistic.h \ Magick++/lib/Magick++/STL.h \ Magick++/lib/Magick++/TypeMetric.h diff --git a/Magick++/lib/ChannelMoments.cpp b/Magick++/lib/ChannelMoments.cpp deleted file mode 100644 index a355107ec..000000000 --- a/Magick++/lib/ChannelMoments.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// 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" -#include "Magick++/Exception.h" - -using namespace std; - -Magick::ChannelMoments::ChannelMoments(void) - : _huInvariants(8), - _channel(UndefinedChannel), - _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), - _channel(channelMoments_._channel), - _centroidX(channelMoments_._centroidX), - _centroidY(channelMoments_._centroidY), - _ellipseAxisX(channelMoments_._ellipseAxisX), - _ellipseAxisY(channelMoments_._ellipseAxisY), - _ellipseAngle(channelMoments_._ellipseAngle), - _ellipseEccentricity(channelMoments_._ellipseEccentricity), - _ellipseIntensity(channelMoments_._ellipseIntensity) -{ -} - -Magick::ChannelMoments::~ChannelMoments(void) -{ -} - -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), - _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); -} - -Magick::ChannelType Magick::ChannelMoments::channel(void) const -{ - return(_channel); -} - -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 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[RedPixelChannel])); - _channels.push_back(Magick::ChannelMoments(GreenChannel, - &channel_moments[GreenPixelChannel])); - _channels.push_back(Magick::ChannelMoments(BlueChannel, - &channel_moments[BluePixelChannel])); - break; - case CMYKColorspace: - _channels.push_back(Magick::ChannelMoments(CyanChannel, - &channel_moments[CyanPixelChannel])); - _channels.push_back(Magick::ChannelMoments(MagentaChannel, - &channel_moments[MagentaPixelChannel])); - _channels.push_back(Magick::ChannelMoments(YellowChannel, - &channel_moments[YellowPixelChannel])); - _channels.push_back(Magick::ChannelMoments(BlackChannel, - &channel_moments[BlackPixelChannel])); - break; - case GRAYColorspace: - _channels.push_back(Magick::ChannelMoments(GrayChannel, - &channel_moments[GrayPixelChannel])); - break; - } - if (image->alpha_trait == BlendPixelTrait) - _channels.push_back(Magick::ChannelMoments(AlphaChannel, - &channel_moments[AlphaPixelChannel])); - if (image->colorspace != GRAYColorspace) - _channels.push_back(Magick::ChannelMoments(CompositeChannels, - &channel_moments[CompositePixelChannel])); - 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 9636ee7f3..8ffb4decb 100644 --- a/Magick++/lib/Image.cpp +++ b/Magick++/lib/Image.cpp @@ -4378,51 +4378,9 @@ void Magick::Image::spread(const size_t amount_) ThrowPPException; } -void Magick::Image::statistics(ImageStatistics *statistics) +Magick::ImageStatistics Magick::Image::statistics() { - double - maximum, - minimum; - - GetPPException; - - SetPPChannelMask(RedChannel); - (void) GetImageRange(constImage(),&minimum,&maximum,exceptionInfo); - statistics->red.minimum=minimum; - statistics->red.maximum=maximum; - (void) GetImageMean(constImage(),&statistics->red.mean, - &statistics->red.standard_deviation,exceptionInfo); - (void) GetImageKurtosis(constImage(),&statistics->red.kurtosis, - &statistics->red.skewness,exceptionInfo); - - (void) SetImageChannelMask(image(),GreenChannel); - (void) GetImageRange(constImage(),&minimum,&maximum,exceptionInfo); - statistics->green.minimum=minimum; - statistics->green.maximum=maximum; - (void) GetImageMean(constImage(),&statistics->green.mean, - &statistics->green.standard_deviation,exceptionInfo); - (void) GetImageKurtosis(constImage(),&statistics->green.kurtosis, - &statistics->green.skewness,exceptionInfo); - - (void) SetImageChannelMask(image(),GreenChannel); - (void) GetImageRange(constImage(),&minimum,&maximum,exceptionInfo); - statistics->blue.minimum=minimum; - statistics->blue.maximum=maximum; - (void) GetImageMean(constImage(),&statistics->blue.mean, - &statistics->blue.standard_deviation,exceptionInfo); - (void) GetImageKurtosis(constImage(),&statistics->blue.kurtosis, - &statistics->blue.skewness,exceptionInfo); - - (void) SetImageChannelMask(image(),AlphaChannel); - (void) GetImageRange(constImage(),&minimum,&maximum,exceptionInfo); - statistics->alpha.minimum=minimum; - statistics->alpha.maximum=maximum; - (void) GetImageMean(constImage(),&statistics->alpha.mean, - &statistics->alpha.standard_deviation,exceptionInfo); - (void) GetImageKurtosis(constImage(),&statistics->alpha.kurtosis, - &statistics->alpha.skewness,exceptionInfo); - RestorePPChannelMask; - ThrowPPException; + return(ImageStatistics(constImage())); } void Magick::Image::stegano(const Image &watermark_) diff --git a/Magick++/lib/Magick++/ChannelMoments.h b/Magick++/lib/Magick++/ChannelMoments.h deleted file mode 100644 index d4d491d2a..000000000 --- a/Magick++/lib/Magick++/ChannelMoments.h +++ /dev/null @@ -1,101 +0,0 @@ -// 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 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; - - // 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; - ChannelType _channel; - double _centroidX; - double _centroidY; - double _ellipseAxisX; - double _ellipseAxisY; - double _ellipseAngle; - double _ellipseEccentricity; - 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 be45d57b3..bcf685d8b 100644 --- a/Magick++/lib/Magick++/Image.h +++ b/Magick++/lib/Magick++/Image.h @@ -12,11 +12,11 @@ #include #include #include "Magick++/Blob.h" -#include "Magick++/ChannelMoments.h" #include "Magick++/Color.h" #include "Magick++/Drawable.h" #include "Magick++/Exception.h" #include "Magick++/Geometry.h" +#include "Magick++/Statistic.h" #include "Magick++/TypeMetric.h" namespace Magick @@ -53,35 +53,6 @@ namespace Magick { public: - // Obtain image statistics. Statistics are normalized to the range - // of 0.0 to 1.0 and are output to the specified ImageStatistics - // structure. - typedef struct _ImageChannelStatistics - { - /* Minimum value observed */ - double maximum; - /* Maximum value observed */ - double minimum; - /* Average (mean) value observed */ - double mean; - /* Standard deviation, sqrt(variance) */ - double standard_deviation; - /* Variance */ - double variance; - /* Kurtosis */ - double kurtosis; - /* Skewness */ - double skewness; - } ImageChannelStatistics; - - typedef struct _ImageStatistics - { - ImageChannelStatistics red; - ImageChannelStatistics green; - ImageChannelStatistics blue; - ImageChannelStatistics alpha; - } ImageStatistics; - // Default constructor Image(void); @@ -1325,7 +1296,7 @@ namespace Magick // Spread pixels randomly within image by specified ammount void spread(const size_t amount_=3); - void statistics(ImageStatistics *statistics); + Magick::ImageStatistics statistics(); // Add a digital watermark to the image (based on second image) void stegano(const Image &watermark_); diff --git a/Magick++/lib/Magick++/Include.h b/Magick++/lib/Magick++/Include.h index a9a6d9a8f..0e35a6dc1 100644 --- a/Magick++/lib/Magick++/Include.h +++ b/Magick++/lib/Magick++/Include.h @@ -863,6 +863,8 @@ namespace Magick // Pixel traits using MagickCore::PixelTrait; using MagickCore::UndefinedPixelTrait; + using MagickCore::CopyPixelTrait; + using MagickCore::UpdatePixelTrait; using MagickCore::BlendPixelTrait; // Preview types. Not currently used by Magick++ diff --git a/Magick++/lib/Magick++/Statistic.h b/Magick++/lib/Magick++/Statistic.h new file mode 100644 index 000000000..3be0734c5 --- /dev/null +++ b/Magick++/lib/Magick++/Statistic.h @@ -0,0 +1,214 @@ +// 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); + + // X position of centroid + double centroidX(void) const; + + // Y position of centroid + double centroidY(void) const; + + // The channel + PixelChannel channel(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; + + // Does object contain valid channel moments? + bool isValid() const; + + // + // Implemementation methods + // + + ChannelMoments(const PixelChannel channel_, + const MagickCore::ChannelMoments *channelMoments_); + + private: + std::vector _huInvariants; + PixelChannel _channel; + double _centroidX; + double _centroidY; + double _ellipseAxisX; + double _ellipseAxisY; + double _ellipseAngle; + double _ellipseEccentricity; + double _ellipseIntensity; + }; + + // Obtain image statistics. Statistics are normalized to the range + // of 0.0 to 1.0 and are output to the specified ImageStatistics + // structure. + class MagickPPExport ChannelStatistics + { + public: + + // Default constructor + ChannelStatistics(void); + + // Copy constructor + ChannelStatistics(const ChannelStatistics &channelStatistics_); + + // Destroy channel statistics + ~ChannelStatistics(void); + + // Area + double area() const; + + // The channel + PixelChannel channel(void) const; + + // Depth + size_t depth() const; + + // Does object contain valid channel statistics? + bool isValid() const; + + // Kurtosis + double kurtosis() const; + + // Minimum value observed + double maxima() const; + + // Average (mean) value observed + double mean() const; + + // Maximum value observed + double minima() const; + + // Skewness + double skewness() const; + + // Standard deviation, sqrt(variance) + double standardDeviation() const; + + // Sum + double sum() const; + + // Sum cubed + double sumCubed() const; + + // Sum fourth power + double sumFourthPower() const; + + // Sum squared + double sumSquared() const; + + // Variance + double variance() const; + + // + // Implemementation methods + // + + ChannelStatistics(const PixelChannel channel_, + const MagickCore::ChannelStatistics *channelStatistics_); + + private: + PixelChannel _channel; + double _area; + size_t _depth; + double _kurtosis; + double _maxima; + double _mean; + double _minima; + double _skewness; + double _standardDeviation; + double _sum; + double _sumSquared; + double _sumCubed; + double _sumFourthPower; + double _variance; + }; + + 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 PixelChannel channel_) const; + + // + // Implemementation methods + // + ImageMoments(const MagickCore::Image *image_); + + private: + std::vector _channels; + }; + + class MagickPPExport ImageStatistics + { + public: + + // Default constructor + ImageStatistics(void); + + // Copy constructor + ImageStatistics(const ImageStatistics &imageStatistics_); + + // Destroy image statistics + ~ImageStatistics(void); + + // Returns the statistics for the specified channel + ChannelStatistics channel(const PixelChannel channel_) const; + + // + // Implemementation methods + // + ImageStatistics(const MagickCore::Image *image_); + + private: + std::vector _channels; + }; +} + +#endif // Magick_ChannelMoments_header \ No newline at end of file diff --git a/Magick++/lib/Statistic.cpp b/Magick++/lib/Statistic.cpp new file mode 100644 index 000000000..e5d5dbb2b --- /dev/null +++ b/Magick++/lib/Statistic.cpp @@ -0,0 +1,369 @@ +// 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++/Exception.h" +#include "Magick++/Statistic.h" + +using namespace std; + +Magick::ChannelMoments::ChannelMoments(void) + : _huInvariants(8), + _channel(SyncPixelChannel), + _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), + _channel(channelMoments_._channel), + _centroidX(channelMoments_._centroidX), + _centroidY(channelMoments_._centroidY), + _ellipseAxisX(channelMoments_._ellipseAxisX), + _ellipseAxisY(channelMoments_._ellipseAxisY), + _ellipseAngle(channelMoments_._ellipseAngle), + _ellipseEccentricity(channelMoments_._ellipseEccentricity), + _ellipseIntensity(channelMoments_._ellipseIntensity) +{ +} + +Magick::ChannelMoments::~ChannelMoments(void) +{ +} + +double Magick::ChannelMoments::centroidX(void) const +{ + return(_centroidX); +} + +double Magick::ChannelMoments::centroidY(void) const +{ + return(_centroidY); +} + +Magick::PixelChannel Magick::ChannelMoments::channel(void) const +{ + return(_channel); +} + +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 ErrorOption("Valid range for index is 0-7"); + + return(_huInvariants.at(index_)); +} + +bool Magick::ChannelMoments::isValid() const +{ + return(_channel != SyncPixelChannel); +} + +Magick::ChannelMoments::ChannelMoments(const PixelChannel channel_, + const MagickCore::ChannelMoments *channelMoments_) + : _huInvariants(), + _channel(channel_), + _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]); +} + +Magick::ChannelStatistics::ChannelStatistics(void) + : _channel(SyncPixelChannel), + _area(0.0), + _depth(0.0), + _kurtosis(0.0), + _maxima(0.0), + _mean(0.0), + _minima(0.0), + _skewness(0.0), + _standardDeviation(0.0), + _sum(0.0), + _sumCubed(0.0), + _sumFourthPower(0.0), + _sumSquared(0.0), + _variance(0.0) +{ +} + +Magick::ChannelStatistics::ChannelStatistics( + const ChannelStatistics &channelStatistics_) + : _channel(channelStatistics_._channel), + _area(channelStatistics_._area), + _depth(channelStatistics_._depth), + _kurtosis(channelStatistics_._kurtosis), + _maxima(channelStatistics_._maxima), + _mean(channelStatistics_._mean), + _minima(channelStatistics_._minima), + _skewness(channelStatistics_._skewness), + _standardDeviation(channelStatistics_._standardDeviation), + _sum(channelStatistics_._sum), + _sumCubed(channelStatistics_._sumCubed), + _sumFourthPower(channelStatistics_._sumFourthPower), + _sumSquared(channelStatistics_._sumSquared), + _variance(channelStatistics_._variance) +{ +} + +Magick::ChannelStatistics::~ChannelStatistics(void) +{ +} + +double Magick::ChannelStatistics::area() const +{ + return(_area); +} + +Magick::PixelChannel Magick::ChannelStatistics::channel() const +{ + return(_channel); +} + +size_t Magick::ChannelStatistics::depth() const +{ + return(_depth); +} + +bool Magick::ChannelStatistics::isValid() const +{ + return(_channel != SyncPixelChannel); +} + +double Magick::ChannelStatistics::kurtosis() const +{ + return(_kurtosis); +} + +double Magick::ChannelStatistics::maxima() const +{ + return(_maxima); +} + +double Magick::ChannelStatistics::mean() const +{ + return(_mean); +} + +double Magick::ChannelStatistics::minima() const +{ + return(_minima); +} + +double Magick::ChannelStatistics::skewness() const +{ + return(_skewness); +} + +double Magick::ChannelStatistics::standardDeviation() const +{ + return(_standardDeviation); +} + +double Magick::ChannelStatistics::sum() const +{ + return(_sum); +} + +double Magick::ChannelStatistics::sumCubed() const +{ + return(_sumCubed); +} + +double Magick::ChannelStatistics::sumFourthPower() const +{ + return(_sumFourthPower); +} + +double Magick::ChannelStatistics::sumSquared() const +{ + return(_sumSquared); +} + +double Magick::ChannelStatistics::variance() const +{ + return(_variance); +} + +Magick::ChannelStatistics::ChannelStatistics(const PixelChannel channel_, + const MagickCore::ChannelStatistics *channelStatistics_) + : _channel(channel_), + _area(channelStatistics_->area), + _depth(channelStatistics_->depth), + _kurtosis(channelStatistics_->kurtosis), + _maxima(channelStatistics_->maxima), + _mean(channelStatistics_->mean), + _minima(channelStatistics_->minima), + _skewness(channelStatistics_->skewness), + _standardDeviation(channelStatistics_->standard_deviation), + _sum(channelStatistics_->sum), + _sumCubed(channelStatistics_->sum_cubed), + _sumFourthPower(channelStatistics_->sum_fourth_power), + _sumSquared(channelStatistics_->sum_squared), + _variance(channelStatistics_->variance) +{ +} + +Magick::ImageMoments::ImageMoments(void) + : _channels() +{ +} + +Magick::ImageMoments::ImageMoments(const ImageMoments &imageMoments_) + : _channels(imageMoments_._channels) +{ +} + +Magick::ImageMoments::~ImageMoments(void) +{ +} + +Magick::ChannelMoments Magick::ImageMoments::channel( + const PixelChannel 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) + { + register ssize_t + i; + + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelChannel channel=GetPixelChannelChannel(image,i); + PixelTrait traits=GetPixelChannelTraits(image,channel); + if (traits == UndefinedPixelTrait) + continue; + if ((traits & UpdatePixelTrait) == 0) + continue; + _channels.push_back(Magick::ChannelMoments(channel, + &channel_moments[channel])); + } + _channels.push_back(Magick::ChannelMoments(CompositePixelChannel, + &channel_moments[CompositePixelChannel])); + channel_moments=(MagickCore::ChannelMoments *) RelinquishMagickMemory( + channel_moments); + } + ThrowPPException; +} + +Magick::ImageStatistics::ImageStatistics(void) + : _channels() +{ +} + +Magick::ImageStatistics::ImageStatistics( + const ImageStatistics &imageStatistics_) + : _channels(imageStatistics_._channels) +{ +} + +Magick::ImageStatistics::~ImageStatistics(void) +{ +} + +Magick::ChannelStatistics Magick::ImageStatistics::channel( + const PixelChannel channel_) const +{ + for (std::vector::const_iterator it = _channels.begin(); + it != _channels.end(); ++it) + { + if (it->channel() == channel_) + return(*it); + } + return(ChannelStatistics()); +} + +Magick::ImageStatistics::ImageStatistics(const MagickCore::Image *image) + : _channels() +{ + MagickCore::ChannelStatistics* + channel_statistics; + + GetPPException; + channel_statistics=GetImageStatistics(image,exceptionInfo); + if (channel_statistics != (MagickCore::ChannelStatistics *) NULL) + { + register ssize_t + i; + + for (i=0; i < (ssize_t) GetPixelChannels(image); i++) + { + PixelChannel channel=GetPixelChannelChannel(image,i); + PixelTrait traits=GetPixelChannelTraits(image,channel); + if (traits == UndefinedPixelTrait) + continue; + if ((traits & UpdatePixelTrait) == 0) + continue; + _channels.push_back(Magick::ChannelStatistics(channel, + &channel_statistics[channel])); + } + _channels.push_back(Magick::ChannelStatistics(CompositePixelChannel, + &channel_statistics[CompositePixelChannel])); + channel_statistics=(MagickCore::ChannelStatistics *) RelinquishMagickMemory( + channel_statistics); + } + ThrowPPException; +} \ No newline at end of file