9#define MAGICKCORE_IMPLEMENTATION 1
10#define MAGICK_PLUSPLUS_IMPLEMENTATION 1
12#include "Magick++/Include.h"
13#include "Magick++/Exception.h"
14#include "Magick++/Statistic.h"
15#include "Magick++/Image.h"
19Magick::ChannelMoments::ChannelMoments(
void)
20 : _channel(SyncPixelChannel),
27 _ellipseEccentricity(0.0),
28 _ellipseIntensity(0.0)
32Magick::ChannelMoments::ChannelMoments(
const ChannelMoments &channelMoments_)
33 : _channel(channelMoments_._channel),
34 _huInvariants(channelMoments_._huInvariants),
35 _centroidX(channelMoments_._centroidX),
36 _centroidY(channelMoments_._centroidY),
37 _ellipseAxisX(channelMoments_._ellipseAxisX),
38 _ellipseAxisY(channelMoments_._ellipseAxisY),
39 _ellipseAngle(channelMoments_._ellipseAngle),
40 _ellipseEccentricity(channelMoments_._ellipseEccentricity),
41 _ellipseIntensity(channelMoments_._ellipseIntensity)
45Magick::ChannelMoments::~ChannelMoments(
void)
49double Magick::ChannelMoments::centroidX(
void)
const
54double Magick::ChannelMoments::centroidY(
void)
const
59Magick::PixelChannel Magick::ChannelMoments::channel(
void)
const
64double Magick::ChannelMoments::ellipseAxisX(
void)
const
66 return(_ellipseAxisX);
69double Magick::ChannelMoments::ellipseAxisY(
void)
const
71 return(_ellipseAxisY);
74double Magick::ChannelMoments::ellipseAngle(
void)
const
76 return(_ellipseAngle);
79double Magick::ChannelMoments::ellipseEccentricity(
void)
const
81 return(_ellipseEccentricity);
84double Magick::ChannelMoments::ellipseIntensity(
void)
const
86 return(_ellipseIntensity);
89double Magick::ChannelMoments::huInvariants(
const size_t index_)
const
92 throw ErrorOption(
"Valid range for index is 0-7");
94 return(_huInvariants.at(index_));
97bool Magick::ChannelMoments::isValid()
const
99 return(_channel != SyncPixelChannel);
102Magick::ChannelMoments::ChannelMoments(
const PixelChannel channel_,
103 const MagickCore::ChannelMoments *channelMoments_)
104 : _channel(channel_),
106 _centroidX(channelMoments_->centroid.x),
107 _centroidY(channelMoments_->centroid.y),
108 _ellipseAxisX(channelMoments_->ellipse_axis.x),
109 _ellipseAxisY(channelMoments_->ellipse_axis.y),
110 _ellipseAngle(channelMoments_->ellipse_angle),
111 _ellipseEccentricity(channelMoments_->ellipse_eccentricity),
112 _ellipseIntensity(channelMoments_->ellipse_intensity)
118 _huInvariants.push_back(channelMoments_->invariant[i]);
121Magick::ChannelPerceptualHash::ChannelPerceptualHash(
void)
122 : _channel(SyncPixelChannel),
128Magick::ChannelPerceptualHash::ChannelPerceptualHash(
129 const ChannelPerceptualHash &channelPerceptualHash_)
130 : _channel(channelPerceptualHash_._channel),
131 _srgbHuPhash(channelPerceptualHash_._srgbHuPhash),
132 _hclpHuPhash(channelPerceptualHash_._hclpHuPhash)
136Magick::ChannelPerceptualHash::ChannelPerceptualHash(
137 const PixelChannel channel_,
const std::string &hash_)
138 : _channel(channel_),
145 if (hash_.length() != 70)
146 throw ErrorOption(
"Invalid hash length");
156 if (sscanf(hash_.substr(i*5,5).c_str(),
"%05x",&hex) != 1)
157 throw ErrorOption(
"Invalid hash value");
159 value=((
unsigned short)hex) / pow(10.0, (
double)(hex >> 17));
163 _srgbHuPhash[i]=value;
165 _hclpHuPhash[i-7]=value;
169Magick::ChannelPerceptualHash::~ChannelPerceptualHash(
void)
173Magick::ChannelPerceptualHash::operator std::string()
const
182 return(std::string());
196 value=_srgbHuPhash[i];
198 value=_hclpHuPhash[i-7];
201 while(hex < 7 && fabs(value*10) < 65536)
210 hex=(hex<<16)+(
unsigned int)(value < 0.0 ? -(value - 0.5) : value + 0.5);
211 (void) FormatLocaleString(buffer,6,
"%05x",hex);
212 hash+=std::string(buffer);
217Magick::PixelChannel Magick::ChannelPerceptualHash::channel()
const
222bool Magick::ChannelPerceptualHash::isValid()
const
224 return(_channel != SyncPixelChannel);
227double Magick::ChannelPerceptualHash::sumSquaredDifferences(
228 const ChannelPerceptualHash &channelPerceptualHash_)
239 ssd+=((_srgbHuPhash[i]-channelPerceptualHash_._srgbHuPhash[i])*
240 (_srgbHuPhash[i]-channelPerceptualHash_._srgbHuPhash[i]));
241 ssd+=((_hclpHuPhash[i]-channelPerceptualHash_._hclpHuPhash[i])*
242 (_hclpHuPhash[i]-channelPerceptualHash_._hclpHuPhash[i]));
247double Magick::ChannelPerceptualHash::srgbHuPhash(
const size_t index_)
const
250 throw ErrorOption(
"Valid range for index is 0-6");
252 return(_srgbHuPhash.at(index_));
255double Magick::ChannelPerceptualHash::hclpHuPhash(
const size_t index_)
const
258 throw ErrorOption(
"Valid range for index is 0-6");
260 return(_hclpHuPhash.at(index_));
263Magick::ChannelPerceptualHash::ChannelPerceptualHash(
264 const PixelChannel channel_,
265 const MagickCore::ChannelPerceptualHash *channelPerceptualHash_)
266 : _channel(channel_),
275 _srgbHuPhash[i]=channelPerceptualHash_->phash[0][i];
276 _hclpHuPhash[i]=channelPerceptualHash_->phash[1][i];
280Magick::ChannelStatistics::ChannelStatistics(
void)
281 : _channel(SyncPixelChannel),
290 _standardDeviation(0.0),
293 _sumFourthPower(0.0),
299Magick::ChannelStatistics::ChannelStatistics(
300 const ChannelStatistics &channelStatistics_)
301 : _channel(channelStatistics_._channel),
302 _area(channelStatistics_._area),
303 _depth(channelStatistics_._depth),
304 _entropy(channelStatistics_._entropy),
305 _kurtosis(channelStatistics_._kurtosis),
306 _maxima(channelStatistics_._maxima),
307 _mean(channelStatistics_._mean),
308 _minima(channelStatistics_._minima),
309 _skewness(channelStatistics_._skewness),
310 _standardDeviation(channelStatistics_._standardDeviation),
311 _sum(channelStatistics_._sum),
312 _sumCubed(channelStatistics_._sumCubed),
313 _sumFourthPower(channelStatistics_._sumFourthPower),
314 _sumSquared(channelStatistics_._sumSquared),
315 _variance(channelStatistics_._variance)
319Magick::ChannelStatistics::~ChannelStatistics(
void)
323double Magick::ChannelStatistics::area()
const
328Magick::PixelChannel Magick::ChannelStatistics::channel()
const
333size_t Magick::ChannelStatistics::depth()
const
338double Magick::ChannelStatistics::entropy()
const
343bool Magick::ChannelStatistics::isValid()
const
345 return(_channel != SyncPixelChannel);
348double Magick::ChannelStatistics::kurtosis()
const
353double Magick::ChannelStatistics::maxima()
const
358double Magick::ChannelStatistics::mean()
const
363double Magick::ChannelStatistics::minima()
const
368double Magick::ChannelStatistics::skewness()
const
373double Magick::ChannelStatistics::standardDeviation()
const
375 return(_standardDeviation);
378double Magick::ChannelStatistics::sum()
const
383double Magick::ChannelStatistics::sumCubed()
const
388double Magick::ChannelStatistics::sumFourthPower()
const
390 return(_sumFourthPower);
393double Magick::ChannelStatistics::sumSquared()
const
398double Magick::ChannelStatistics::variance()
const
403Magick::ChannelStatistics::ChannelStatistics(
const PixelChannel channel_,
404 const MagickCore::ChannelStatistics *channelStatistics_)
405 : _channel(channel_),
406 _area(channelStatistics_->area),
407 _depth(channelStatistics_->depth),
408 _entropy(channelStatistics_->entropy),
409 _kurtosis(channelStatistics_->kurtosis),
410 _maxima(channelStatistics_->maxima),
411 _mean(channelStatistics_->mean),
412 _minima(channelStatistics_->minima),
413 _skewness(channelStatistics_->skewness),
414 _standardDeviation(channelStatistics_->standard_deviation),
415 _sum(channelStatistics_->sum),
416 _sumCubed(channelStatistics_->sum_cubed),
417 _sumFourthPower(channelStatistics_->sum_fourth_power),
418 _sumSquared(channelStatistics_->sum_squared),
419 _variance(channelStatistics_->variance)
423Magick::ImageMoments::ImageMoments(
void)
428Magick::ImageMoments::ImageMoments(
const ImageMoments &imageMoments_)
429 : _channels(imageMoments_._channels)
433Magick::ImageMoments::~ImageMoments(
void)
438 const PixelChannel channel_)
const
440 for (std::vector<ChannelMoments>::const_iterator it = _channels.begin();
441 it != _channels.end(); ++it)
443 if (it->channel() == channel_)
446 return(ChannelMoments());
449Magick::ImageMoments::ImageMoments(
const Image &image_)
452 MagickCore::ChannelMoments*
456 channel_moments=GetImageMoments(image_.constImage(),exceptionInfo);
457 if (channel_moments != (MagickCore::ChannelMoments *) NULL)
462 for (i=0; i < (ssize_t) GetPixelChannels(image_.constImage()); i++)
464 PixelChannel channel=GetPixelChannelChannel(image_.constImage(),i);
465 PixelTrait traits=GetPixelChannelTraits(image_.constImage(),channel);
466 if (traits == UndefinedPixelTrait)
468 if ((traits & UpdatePixelTrait) == 0)
471 &channel_moments[channel]));
474 &channel_moments[CompositePixelChannel]));
475 channel_moments=(MagickCore::ChannelMoments *) RelinquishMagickMemory(
478 ThrowPPException(image_.quiet());
481Magick::ImagePerceptualHash::ImagePerceptualHash(
void)
486Magick::ImagePerceptualHash::ImagePerceptualHash(
487 const ImagePerceptualHash &imagePerceptualHash_)
488 : _channels(imagePerceptualHash_._channels)
492Magick::ImagePerceptualHash::ImagePerceptualHash(
const std::string &hash_)
495 if (hash_.length() != 210)
496 throw ErrorOption(
"Invalid hash length");
499 hash_.substr(0, 70)));
501 hash_.substr(70, 70)));
503 hash_.substr(140, 70)));
506Magick::ImagePerceptualHash::~ImagePerceptualHash(
void)
510Magick::ImagePerceptualHash::operator std::string()
const
513 return(std::string());
515 return static_cast<std::string
>(_channels[0]) +
516 static_cast<std::string
>(_channels[1]) +
517 static_cast<std::string
>(_channels[2]);
521 const PixelChannel channel_)
const
523 for (std::vector<ChannelPerceptualHash>::const_iterator it =
524 _channels.begin(); it != _channels.end(); ++it)
526 if (it->channel() == channel_)
529 return(ChannelPerceptualHash());
532bool Magick::ImagePerceptualHash::isValid()
const
534 if (_channels.size() != 3)
537 if (_channels[0].channel() != RedPixelChannel)
540 if (_channels[1].channel() != GreenPixelChannel)
543 if (_channels[2].channel() != BluePixelChannel)
549double Magick::ImagePerceptualHash::sumSquaredDifferences(
550 const ImagePerceptualHash &channelPerceptualHash_)
559 throw ErrorOption(
"instance is not valid");
560 if (!channelPerceptualHash_.isValid())
561 throw ErrorOption(
"channelPerceptualHash_ is not valid");
566 ssd+=_channels[i].sumSquaredDifferences(_channels[i]);
571Magick::ImagePerceptualHash::ImagePerceptualHash(
575 MagickCore::ChannelPerceptualHash*
576 channel_perceptual_hash;
582 channel_perceptual_hash=GetImagePerceptualHash(image_.constImage(),
584 if (channel_perceptual_hash != (MagickCore::ChannelPerceptualHash *) NULL)
586 traits=GetPixelChannelTraits(image_.constImage(),RedPixelChannel);
587 if ((traits & UpdatePixelTrait) != 0)
589 &channel_perceptual_hash[RedPixelChannel]));
590 traits=GetPixelChannelTraits(image_.constImage(),GreenPixelChannel);
591 if ((traits & UpdatePixelTrait) != 0)
593 &channel_perceptual_hash[GreenPixelChannel]));
594 traits=GetPixelChannelTraits(image_.constImage(),BluePixelChannel);
595 if ((traits & UpdatePixelTrait) != 0)
597 &channel_perceptual_hash[BluePixelChannel]));
598 channel_perceptual_hash=(MagickCore::ChannelPerceptualHash *)
599 RelinquishMagickMemory(channel_perceptual_hash);
601 ThrowPPException(image_.quiet());
604Magick::ImageStatistics::ImageStatistics(
void)
609Magick::ImageStatistics::ImageStatistics(
610 const ImageStatistics &imageStatistics_)
611 : _channels(imageStatistics_._channels)
615Magick::ImageStatistics::~ImageStatistics(
void)
620 const PixelChannel channel_)
const
622 for (std::vector<ChannelStatistics>::const_iterator it = _channels.begin();
623 it != _channels.end(); ++it)
625 if (it->channel() == channel_)
628 return(ChannelStatistics());
631Magick::ImageStatistics::ImageStatistics(
const Image &image_)
634 MagickCore::ChannelStatistics*
638 channel_statistics=GetImageStatistics(image_.constImage(),exceptionInfo);
639 if (channel_statistics != (MagickCore::ChannelStatistics *) NULL)
644 for (i=0; i < (ssize_t) GetPixelChannels(image_.constImage()); i++)
646 PixelChannel channel=GetPixelChannelChannel(image_.constImage(),i);
647 PixelTrait traits=GetPixelChannelTraits(image_.constImage(),channel);
648 if (traits == UndefinedPixelTrait)
650 if ((traits & UpdatePixelTrait) == 0)
653 &channel_statistics[channel]));
656 &channel_statistics[CompositePixelChannel]));
657 channel_statistics=(MagickCore::ChannelStatistics *) RelinquishMagickMemory(
660 ThrowPPException(image_.quiet());