Skip to content

Commit b32685c

Browse files
i9482: Improve documentation concerning norm functionality.
Added forkfour Latex command to math js support. Split cv::norm documentation between the cv::norm and its overload, to make things clearer Corrected some typos and cleaned up grammar. Result is clearer documentation for the norms. Work pending...
1 parent 1caca21 commit b32685c

File tree

4 files changed

+52
-34
lines changed

4 files changed

+52
-34
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: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -640,34 +640,44 @@ 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.
643+
/** @brief Calculates an absolute array norm.
645644
646-
The function cv::norm calculates an absolute norm of src1 (when there is no
647-
src2 ):
645+
This version of cv::norm calculates the absolute norm of src1. The type of norm to calculate is specified using cv::NormTypes.
648646
649-
\f[norm = \forkthree{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
647+
\f[norm = \forkfour{\|\texttt{src1}\|_{L_{\infty}} = \max _I | \texttt{src1} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
650648
{ \| \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]
649+
{ \| \texttt{src1} \| _{L_2} = \sqrt{\sum_I \texttt{src1}(I)^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
650+
{ \| \texttt{src1} \| _{L_2} ^{2} = \sum_I \texttt{src1}(I)^2} {if \(\texttt{normType} = \texttt{NORM_L2SQR}\)}\f]
651+
652+
If normType is not specified, NORM_L2 is used.
652653
653654
or an absolute or relative difference norm if src2 is there:
654655
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]
658656
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]
657+
As example for one array consider the function \f$r(x)= \begin{pmatrix} x \\ 1-x \end{pmatrix}, x \in [-1;1]\f$.
658+
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$
659+
is calculated as follows
660+
\f{align*}
661+
\| r(-1) \|_{L_1} &= |-1| + |2| = 3 \\
662+
\| r(-1) \|_{L_2} &= \sqrt{(-1)^{2} + (2)^{2}} = \sqrt{5} \\
663+
\| r(-1) \|_{L_\infty} &= \max(|-1|,|2|) = 2
664+
\f}
665+
and for \f$r(0.5) = \begin{pmatrix} 0.5 \\ 0.5 \end{pmatrix}\f$ the calculation is
666+
\f{align*}
667+
\| r(0.5) \|_{L_1} &= |0.5| + |0.5| = 1 \\
668+
\| r(0.5) \|_{L_2} &= \sqrt{(0.5)^{2} + (0.5)^{2}} = \sqrt{0.5} \\
669+
\| r(0.5) \|_{L_\infty} &= \max(|0.5|,|0.5|) = 0.5.
670+
\f}
671+
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$.
672+
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$.
673+
![Graphs for the different norm functions from the above example](pics/NormTypes_OneArray_1-2-INF.png)
664674
665675
The function cv::norm returns the calculated norm.
666676
667677
When the mask parameter is specified and it is not empty, the norm is
668678
calculated only over the region specified by the mask.
669679
670-
A multi-channel input arrays are treated as a single-channel, that is,
680+
Multi-channel input arrays are treated as single-channel arrays, that is,
671681
the results for all channels are combined.
672682
673683
@param src1 first input array.
@@ -676,7 +686,24 @@ the results for all channels are combined.
676686
*/
677687
CV_EXPORTS_W double norm(InputArray src1, int normType = NORM_L2, InputArray mask = noArray());
678688

679-
/** @overload
689+
/** @brief Calculates an absolute difference norm or a relative difference norm.
690+
691+
This version of cv::norm calculates the absolute difference norm
692+
or the relative difference norm of arrays src1 and src2.
693+
The type of norm to calculate is specified using cv::NormTypes.
694+
695+
\f[norm = \forkfour{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} = \max _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_INF}\) }
696+
{ \| \texttt{src1} - \texttt{src2} \| _{L_1} = \sum _I | \texttt{src1} (I) - \texttt{src2} (I)|}{if \(\texttt{normType} = \texttt{NORM_L1}\) }
697+
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} = \sqrt{\sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2} }{if \(\texttt{normType} = \texttt{NORM_L2}\) }
698+
{ \| \texttt{src1} - \texttt{src2} \| _{L_2} ^{2} = \sum_I (\texttt{src1}(I) - \texttt{src2}(I))^2 }{if \(\texttt{normType} = \texttt{NORM_L2SQR}\) }
699+
\f]
700+
701+
or
702+
703+
\f[norm = \forkthree{\frac{\|\texttt{src1}-\texttt{src2}\|_{L_{\infty}} }{\|\texttt{src2}\|_{L_{\infty}} }}{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_INF}\) }
704+
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
705+
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }\f]
706+
680707
@param src1 first input array.
681708
@param src2 second input array of the same size and the same type as src1.
682709
@param normType type of the norm (cv::NormTypes).

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,6 @@ enum DecompTypes {
167167
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_1} }{\|\texttt{src2}\|_{L_1}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L1}\) }
168168
{ \frac{\|\texttt{src1}-\texttt{src2}\|_{L_2} }{\|\texttt{src2}\|_{L_2}} }{if \(\texttt{normType} = \texttt{NORM_RELATIVE | NORM_L2}\) }\f]
169169
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)
187170
*/
188171
enum NormTypes { NORM_INF = 1,
189172
NORM_L1 = 2,

0 commit comments

Comments
 (0)