Skip to content

Commit f1aa180

Browse files
committed
Merge pull request opencv#9574 from saskatchewancatch:i9482
2 parents 8c7f198 + c9d3c0f commit f1aa180

File tree

4 files changed

+87
-61
lines changed

4 files changed

+87
-61
lines changed

doc/mymath.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ MathJax.Hub.Config(
66
matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
77
fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
88
forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
9+
forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
910
vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
1011
vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
1112
hdotsfor: ["\\dots", 1],

doc/mymath.sty

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,14 @@
2828
#3 & \mbox{#4}\\
2929
#5 & \mbox{#6}\\
3030
\end{array} \right.}
31-
31+
\newcommand{\forkthree}[8]{
32+
\left\{
33+
\begin{array}{l l}
34+
#1 & \mbox{#2}\\
35+
#3 & \mbox{#4}\\
36+
#5 & \mbox{#6}\\
37+
#7 & \mbox{#8}\\
38+
\end{array} \right.}
3239
\newcommand{\vecthree}[3]{
3340
\begin{bmatrix}
3441
#1\\

modules/core/include/opencv2/core.hpp

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -640,43 +640,50 @@ Scalar_ 's.
640640
CV_EXPORTS_W void meanStdDev(InputArray src, OutputArray mean, OutputArray stddev,
641641
InputArray mask=noArray());
642642

643-
/** @brief Calculates an absolute array norm, an absolute difference norm, or a
644-
relative difference norm.
645-
646-
The function cv::norm calculates an absolute norm of src1 (when there is no
647-
src2 ):
648-
649-
\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
650-
{ \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
651-
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
652-
653-
or an absolute or relative difference norm if src2 is there:
654-
655-
\f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
656-
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
657-
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
658-
659-
or
660-
661-
\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) }
662-
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
663-
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }\f]
664-
665-
The function cv::norm returns the calculated norm.
643+
/** @brief Calculates the absolute norm of an array.
644+
645+
This version of cv::norm calculates the absolute norm of src1. The type of norm to calculate is specified using cv::NormTypes.
646+
647+
As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
648+
The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
649+
is calculated as follows
650+
\f{align*}
651+
\| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
652+
\| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
653+
\| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
654+
\f}
655+
and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
656+
\f{align*}
657+
\| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
658+
\| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
659+
\| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
660+
\f}
661+
The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$.
662+
It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$.
663+
![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
666664
667665
When the mask parameter is specified and it is not empty, the norm is
666+
667+
If normType is not specified, NORM_L2 is used.
668668
calculated only over the region specified by the mask.
669669
670-
A multi-channel input arrays are treated as a single-channel, that is,
670+
Multi-channel input arrays are treated as single-channel arrays, that is,
671671
the results for all channels are combined.
672672
673+
Hamming norms can only be calculated with CV_8U depth arrays.
674+
673675
@param src1 first input array.
674676
@param normType type of the norm (see cv::NormTypes).
675677
@param mask optional operation mask; it must have the same size as src1 and CV_8UC1 type.
676678
*/
677679
CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
678680

679-
/** @overload
681+
/** @brief Calculates an absolute difference norm or a relative difference norm.
682+
683+
This version of cv::norm calculates the absolute difference norm
684+
or the relative difference norm of arrays src1 and src2.
685+
The type of norm to calculate is specified using cv::NormTypes.
686+
680687
@param src1 first input array.
681688
@param src2 second input array of the same size and the same type as src1.
682689
@param normType type of the norm (cv::NormTypes).

modules/core/include/opencv2/core/base.hpp

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -152,46 +152,57 @@ enum DecompTypes {
152152
};
153153

154154
/** norm types
155-
- For one array:
156-
\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
157-
{ \| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
158-
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
159-
160-
- Absolute norm for two arrays
161-
\f[norm = \forkthree{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
162-
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
163-
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }\f]
164-
165-
- Relative norm for two arrays
166-
\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) }
167-
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
168-
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }\f]
169-
170-
As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
171-
The \f$ L_{1}, L_{2} \f$ and \f$ L_{\infty} \f$ norm for the sample value \f$r(-1) = \begin{pmatrix} -1 \\ 2 \end{pmatrix}\f$
172-
is calculated as follows
173-
\f{align*}
174-
\| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
175-
\| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
176-
\| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
177-
\f}
178-
and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
179-
\f{align*}
180-
\| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
181-
\| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
182-
\| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
183-
\f}
184-
The following graphic shows all values for the three norm functions \f$\| r(x) \|_{L_1}, \| r(x) \|_{L_2}\f$ and \f$\| r(x) \|_{L_\infty}\f$.
185-
It is notable that the \f$ L_{1} \f$ norm forms the upper and the \f$ L_{\infty} \f$ norm forms the lower border for the example function \f$ r(x) \f$.
186-
![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
187-
*/
188-
enum NormTypes { NORM_INF = 1,
155+
156+
src1 and src2 denote input arrays.
157+
*/
158+
159+
enum NormTypes {
160+
/**
161+
\f[
162+
norm = \forkthree
163+
{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
164+
{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
165+
{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) }
166+
\f]
167+
*/
168+
NORM_INF = 1,
169+
/**
170+
\f[
171+
norm = \forkthree
172+
{\| \texttt{src1} \| _{L_1} = \sum _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\)}
173+
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
174+
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
175+
\f]*/
189176
NORM_L1 = 2,
177+
/**
178+
\f[
179+
norm = \forkthree
180+
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
181+
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
182+
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }
183+
\f]
184+
*/
190185
NORM_L2 = 4,
186+
/**
187+
\f[
188+
norm = \forkthree
189+
{ \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)}
190+
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) }
191+
{ \left(\frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}}\right)^2 }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }
192+
\f]
193+
*/
191194
NORM_L2SQR = 5,
195+
/**
196+
In the case of one input array, calculates the Hamming distance of the array from zero,
197+
In the case of two input arrays, calculates the Hamming distance between the arrays.
198+
*/
192199
NORM_HAMMING = 6,
200+
/**
201+
Similar to NORM_HAMMING, but in the calculation, each two bits of the input sequence will
202+
be added and treated as a single bit to be used in the same calculation as NORM_HAMMING.
203+
*/
193204
NORM_HAMMING2 = 7,
194-
NORM_TYPE_MASK = 7,
205+
NORM_TYPE_MASK = 7, //!< bit-mask which can be used to separate norm type from norm flags
195206
NORM_RELATIVE = 8, //!< flag
196207
NORM_MINMAX = 32 //!< flag
197208
};

0 commit comments

Comments
 (0)