summaryrefslogtreecommitdiff
path: root/dmagick/c/statistic.d
blob: 485a1527cc1cca010aed05672b8d82b3afc632a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
module dmagick.c.statistic;

import dmagick.c.draw;
import dmagick.c.exception;
import dmagick.c.image;
import dmagick.c.magickType;
import dmagick.c.magickVersion;

extern(C)
{
	struct ChannelStatistics
	{
		size_t
			depth;

		static if ( MagickLibVersion >= 0x664 )
		{
			double
				minima,
				maxima,
				sum,
				sum_squared,
				sum_cubed,
				sum_fourth_power,
				mean,
				variance,
				standard_deviation,
				kurtosis,
				skewness;
		}
		else
		{
			double
				minima,
				maxima,
				mean,
				standard_deviation,
				kurtosis,
				skewness;
		}
	}

	static if ( MagickLibVersion >= 0x689 )
	{
		struct ChannelMoments
		{
			double[32]
				I;

			PointInfo
				centroid,
				ellipse_axis;

			double
				ellipse_angle,
				ellipse_eccentricity,
				ellipse_intensity;
		}

		struct ChannelPerceptualHash
		{
			double[32]
				P,
				Q;
		}
	}

	/**
	 * Alter channel pixels by evaluating an arithmetic, relational,
	 * or logical expression.
	 */
	enum MagickEvaluateOperator
	{
		UndefinedEvaluateOperator,      ///
		AddEvaluateOperator,            /// Add value to pixels.
		AndEvaluateOperator,            /// Binary AND of pixels with value.
		DivideEvaluateOperator,         /// Divide pixels by value.
		LeftShiftEvaluateOperator,      /// Shift the pixel values left by value bits.
		MaxEvaluateOperator,            /// Clip pixels at lower bound value.
		MinEvaluateOperator,            /// Clip pixels at upper bound value.
		MultiplyEvaluateOperator,       /// Multiply pixels by value.
		OrEvaluateOperator,             /// Binary OR of pixels with value.
		RightShiftEvaluateOperator,     /// Shift the pixel values right by value bits.
		SetEvaluateOperator,            /// Set pixel equal to value.
		SubtractEvaluateOperator,       /// Subtract value from pixels.
		XorEvaluateOperator,            /// Binary XOR of pixels with value.
		PowEvaluateOperator,            /// Raise normalized pixels to the power value.
		LogEvaluateOperator,            /// Apply scaled logarithm to normalized pixels.
		ThresholdEvaluateOperator,      /// Threshold pixels larger than value.
		ThresholdBlackEvaluateOperator, /// Threshold pixels to zero values equal to or below value.
		ThresholdWhiteEvaluateOperator, /// Threshold pixels to maximum values above value.
		GaussianNoiseEvaluateOperator,       /// 
		ImpulseNoiseEvaluateOperator,        /// ditto
		LaplacianNoiseEvaluateOperator,      /// ditto
		MultiplicativeNoiseEvaluateOperator, /// ditto
		PoissonNoiseEvaluateOperator,        /// ditto
		UniformNoiseEvaluateOperator,        /// ditto
		CosineEvaluateOperator,      /// Apply cosine to pixels with frequency value with 50% bias added.
		SineEvaluateOperator,        /// Apply sine to pixels with frequency value with 50% bias added.
		AddModulusEvaluateOperator,  /// Add value to pixels modulo QuantumRange.
		MeanEvaluateOperator,        /// Add the value and divide by 2.
		AbsEvaluateOperator,         /// Add value to pixels and return absolute value.
		ExponentialEvaluateOperator, /// base-e exponential function.
		MedianEvaluateOperator,      /// Choose the median value from an image sequence.
		SumEvaluateOperator          /// Add value to pixels.
	}

	/**
	 * Apply a function to channel values.
	 * 
	 * See_Also: $(XREF Image, functionImage).
	 */
	enum MagickFunction
	{
		UndefinedFunction,  ///
		PolynomialFunction, /// ditto
		SinusoidFunction,   /// ditto
		ArcsinFunction,     /// ditto
		ArctanFunction      /// ditto
	}

	version(D_Ddoc)
	{
		/**
		 * The statistic method to apply.
		 */
		enum StatisticType
		{
			UndefinedStatistic, /// 
			GradientStatistic,  /// Maximum difference in area.
			MaximumStatistic,   /// Maximum value per channel in neighborhood.
			MeanStatistic,      /// Average value per channel in neighborhood.
			MedianStatistic,    /// Median value per channel in neighborhood.
			MinimumStatistic,   /// Minimum value per channel in neighborhood.
			ModeStatistic,      /// Mode (most frequent) value per channel in neighborhood.
			NonpeakStatistic,   /// Value just before or after the median value per channel in neighborhood.
			StandardDeviationStatistic  /// 
		}
	}
	else
	{
		mixin(
		{
			string types = "enum StatisticType
			{
				UndefinedStatistic,";

				static if ( MagickLibVersion >= 0x670 )
				{
					types ~= "GradientStatistic,";
				}

				types ~= "
				MaximumStatistic,
				MeanStatistic,
				MedianStatistic,
				MinimumStatistic,
				ModeStatistic,
				NonpeakStatistic,";

				static if ( MagickLibVersion >= 0x670 )
				{
					types ~= "StandardDeviationStatistic,";
				}

				types ~= "
			}";

			return types;
		}());
	}

	ChannelStatistics* GetImageChannelStatistics(const(Image)*, ExceptionInfo*);

	static if ( MagickLibVersion >= 0x689 )
	{
		ChannelMoments* GetImageChannelMoments(const(Image)*, ExceptionInfo*);

		ChannelPerceptualHash* GetImageChannelPerceptualHash(const(Image)*, ExceptionInfo*);
	}

	static if ( MagickLibVersion < 0x661 )
	{
		Image* AverageImages(const(Image)*, ExceptionInfo*);
	}

	static if ( MagickLibVersion >= 0x661 )
	{
		Image* EvaluateImages(const(Image)*, const MagickEvaluateOperator, ExceptionInfo*);
	}

	static if ( MagickLibVersion >= 0x681 )
	{
		Image* PolynomialImage(const(Image)*, const size_t, const(double)*, ExceptionInfo*);
		Image* PolynomialImageChannel(const(Image)*, const ChannelType, const size_t, const(double)*, ExceptionInfo*);
	}

	static if ( MagickLibVersion >= 0x669 )
	{
		Image* StatisticImage(const(Image)*, const StatisticType, const size_t, const size_t, ExceptionInfo*);
		Image* StatisticImageChannel(const(Image)*, const ChannelType, const StatisticType, const size_t, const size_t, ExceptionInfo*);
	}

	MagickBooleanType EvaluateImage(Image*, const MagickEvaluateOperator, const double, ExceptionInfo*);
	MagickBooleanType EvaluateImageChannel(Image*, const ChannelType, const MagickEvaluateOperator, const double, ExceptionInfo*);
	MagickBooleanType FunctionImage(Image*, const MagickFunction, const size_t, const(double)*, ExceptionInfo*);
	MagickBooleanType FunctionImageChannel(Image*, const ChannelType, const MagickFunction, const size_t, const(double)*, ExceptionInfo*);
	MagickBooleanType GetImageChannelExtrema(const(Image)*, const ChannelType, size_t*, size_t*, ExceptionInfo*);
	MagickBooleanType GetImageChannelMean(const(Image)*, const ChannelType, double*, double*, ExceptionInfo*);
	MagickBooleanType GetImageChannelKurtosis(const(Image)*, const ChannelType, double*, double*, ExceptionInfo*);
	MagickBooleanType GetImageChannelRange(const(Image)*, const ChannelType, double*, double*, ExceptionInfo*);
	MagickBooleanType GetImageExtrema(const(Image)*, size_t*, size_t*, ExceptionInfo*);
	MagickBooleanType GetImageMean(const(Image)*, double*, double*, ExceptionInfo*);
	MagickBooleanType GetImageKurtosis(const(Image)*, double*, double*, ExceptionInfo*);
	MagickBooleanType GetImageRange(const(Image)*, double*, double*, ExceptionInfo*);
}