Skip to content

Commit

Permalink
Merge branch 'mpd'
Browse files Browse the repository at this point in the history
  • Loading branch information
deseilligny committed May 15, 2024
2 parents cb17a27 + 39d1061 commit 0063cc0
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 23 deletions.
85 changes: 75 additions & 10 deletions MMVII/Doc/Programmer/Interpolators.tex
Original file line number Diff line number Diff line change
Expand Up @@ -666,34 +666,99 @@ \subsubsection{{\tt GetValueAndGradInterpol}}

% = = = = = = = = = = = = = = = = = = = = = = =

\subsection{Interpolator and images optimization}
\subsection{Usage of interpolators}

%% bool InsideInterpolator(const cInterpolator1D &,const cPtxd<double,Dim> & aP,tREAL8 aMargin=0.0) const; ///< Inside for Bilin

We give a brieve description of possible usage of interpolators.

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

%% GetVBl +ValInterpol
% = = = = = = = = = = = = = = = = = = = = = = =
\subsubsection{Image ressampling}

The classical usage of interpolators , nothing special to say, can be used for computing explicitely
an image transformation or "on the fly" for example in image correlation.

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

\subsubsection{Interpolator and gradient}

The method {\tt GetValueAndGradInterpol} can be used for computing the gradient in place
of other classical algorithm (sobel, deriche \dots), don't know the value of it, by the way
can give it a try.

Perhaps more interesting is when we want to compute simultaneously a geometric transformation $\phi$
and the gradient of the transformed image, if may be interesting for each pixel $p$ to :

\begin{itemize}
\item computing simultaneously $I(\phi(p))$ and its gradient;
\item use the jacobian on $\phi(p)$ for infering the gradient in transformed image.
\end{itemize}

% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

%% cDiffInterpolator1D * cDiffInterpolator1D::AllocFromNames(const std::vector<std::string> & aVName)
\subsubsection{Interpolator and images optimization}

When image are use in non linear optmisation (see~\ref{ImageOptDiff}), it is necessary to consider it like a
continuous function $\RR^2 \rightarrow \RR$. In this case there is two option in
\PPP (see \ref{SampleImageDiff}) :

%% Image differ
\begin{itemize}
\item create an explicit interpolation function on formulas, see ~\ref{InterpBilCase};
\item make a local linear approximation (see~\ref{ImDifGradMode}), in this case the
method {\tt GetValueAndGradInterpol} can be on option.
\end{itemize}

% = = = = = = = = = = = = = = = = = = = = = = =
% = = = = = = = = = = = = = = = = = = = = = = =
% = = = = = = = = = = = = = = = = = = = = = = =

\section{Maintener's view}

By maintener's we mean personn that would : make bug correction or make evolve the library .

\label{InterpolMaintener}

Efficiency
New interpol
Bug correction
Point partially inside
% = = = = = = = = = = = = = = = = = = = = = = =

\subsection{Evolution}

The following evolution can be envisaged :

\begin{itemize}
\item \emph{add a new interpolator}, in this case it is recommanded to study the bench library describe
bellow;
\item \emph{Efficiency} the main cost of computation are probably the internal loop that compute
the scalar produtc between a line of image and the coeffx in x (search {\tt SCALARPRODUCT}
in function {\tt GetValueInterpol, GetValueAndGradInterpol}

\item \emph{Efficiency} a minor enhancement would be to add a method that compute not a single
weight, but, for a given phase $Ph$ compute the vector of weight for $Ph-k,Ph-k+1,\dots Ph+k$,
for tabulated interpolator some computation would be shared;

\item \emph{Partially inside} the fact that all the point must be inside the image with the sz of the kernel
may be too restrictive, especially with high kernel, maybe write a method for points that are not
enough inside image.
\end{itemize}

% = = = = = = = = = = = = = = = = = = = = = = =

\subsection{Bench for interpolator}

Several "bench" method have been written to check the correctness of interpolation. When making evolve the
libray, they should be at least run again to check that there is no regression, and eventually completed,
for example when adding new interpolator.

\begin{itemize}
\item {\tt TplInterpol\_CmpLinearGetVBL}
\item {\tt TplInterpol\_CmpCubicFoncLinear}
\item {\tt TplInterpol\_FuncLowFreq}
\item {\tt BenchIntrinsiqOneInterpol}
\item {\tt BenchIntrinsiqMMVIIInterpol}
\end{itemize}


%% GetVBl +ValInterpol




16 changes: 11 additions & 5 deletions MMVII/Doc/Programmer/NonLinearOptim.tex
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,8 @@ \subsection{Compute next iteration}

\section{Image, optmization and differenciation in MMVII}

\label{ImageOptDiff}

% - - - - - - - - - - - - - - - - - - -
\subsection{Introduction}

Expand Down Expand Up @@ -817,6 +819,8 @@ \subsubsection{General formalization}
% - - - - - - - - - - - - - - - - - - -
\subsubsection{Bilinear case}

\label{InterpBilCase}

Let $p$ be a point and $q=(\tilde{x}_q,\tilde{y}_q)=\phi(p)$ its transformation by $\phi$. Let $x_0$ and $y_0$
be the lower bound of $q$, and $x_1=x_0+1, y_1 = y_0+1$:

Expand Down Expand Up @@ -846,7 +850,7 @@ \subsubsection{Bicubic case}
% - - - - - - - - - - - - - - - - - - -
\subsubsection{Linear with gradient}

\label{GradMode}
\label{ImDifGradMode}

Bi-linear and Bi-cubic case have the advantage to be a rigourous continuous analytical modelization of
image interpolated on whole $\RR^2$. By the way bi-linear is known to be aliased, and bi-cubic
Expand Down Expand Up @@ -911,7 +915,7 @@ \subsubsection{For using generated code}
% - - - - - - - - - - - - - - - - - - -
\subsection{Facility functions for gradient mode}

For gradient mode corresponding to modelization of~\ref{GradMode}, we have very similar functions.
For gradient mode corresponding to modelization of~\ref{ImDifGradMode}, we have very similar functions.
For code generation we have :

\begin{itemize}
Expand All @@ -933,6 +937,7 @@ \subsection{Facility functions for gradient mode}
%---------------------------------------------

\section{Test example for image differenciation in MMVII}
\label{SampleImageDiff}

In this section we describe a test example, that has been implemented in MicMac, this example
has two objective : (1) make a didactic illustration of the fonctionnalities and (2)
Expand Down Expand Up @@ -1048,10 +1053,11 @@ \subsection{Variant with gradient mode}
make a list of adaptations :

\begin{itemize}
\item class {\tt cDeformImHomotethy} was added a member indicating if it works in mode gradient
\item in class {\tt cDeformImHomotethy} was added a member indicating if it has to works
in mode gradient;
\item in the class {\tt cTestDeformIm}, there is a member indicating the interpolator if
it exist (else we ar in bilinear mode); searching all the occurence of {\tt mInterpol} in
this class will show the adaptation to do.
it exist (else when we are in bilinear mode); searching all the occurence of {\tt mInterpol} in
this class will show the difference between the two modes.
\end{itemize}

%---------------------------------------------
Expand Down
14 changes: 8 additions & 6 deletions MMVII/src/Bench/BenchInterpolators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,22 +372,24 @@ void BenchInterpol(cParamExeBench & aParam)
delete aPtrTabInt2;

}
// test that the two definition of cMMVII2Inperpol coincide (the spcialized with analyticall formula
// and the general, with paraméter 2, that solve a system (and test also with tab version)
{
cMMVII2Inperpol aM2;
cMMVIIKInterpol aMK2(2.0);
cTabulatedInterpolator aMKT2(cMMVIIKInterpol(2.0),1000,true);
cMMVII2Inperpol aM2; // version analytical formula
cMMVIIKInterpol aMK2(2.0); // version solve system
cTabulatedInterpolator aMKT2(cMMVIIKInterpol(2.0),1000,true); // tabulated
for (tREAL8 aPh=-2.0 ; aPh<2.0 ; aPh+=0.1245)
{
tREAL8 aD1 = std::abs( aM2.Weight(aPh)-aMK2.Weight(aPh));
tREAL8 aD2 = std::abs( aM2.Weight(aPh)-aMKT2.Weight(aPh));
tREAL8 aD1 = std::abs( aM2.Weight(aPh)-aMK2.Weight(aPh)); // Cmp analytical/solve syst
tREAL8 aD2 = std::abs( aM2.Weight(aPh)-aMKT2.Weight(aPh)); // Cmp analytical/tabulated
// StdOut() << "M2PHHhh= " << aD1 << " " << aD2 << "\n";
MMVII_INTERNAL_ASSERT_bench((aD1<1e-5) && (aD2<1e-5) ,"Interpol MMVII : Weigh=1");
}
}

// Bench on bicub interpola
//
for (const auto & aP : {0.0,1.0,2.0,3.0})
for (const auto & aP : {0.0,1.0,2.0,3.0}) // Test different param of cubic
{
cCubicInterpolator anI3(aP);

Expand Down
4 changes: 2 additions & 2 deletions MMVII/src/ImagesBase/cIm2d_Interpolators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <class Type> tREAL8 cDataIm2D<Type>::GetValueInterpol(const cInterpola
// const tREAL8 * aCurWX = aLineWXInit;
tREAL8 aSomWIx = 0.0;

for (int aKX=0 ; aKX< aNbX ; aKX++)
for (int aKX=0 ; aKX< aNbX ; aKX++) // doc SCALARPRODUCT
aSomWIx += aLineIm[aKX] * aLineWX[aKX] ;

/* to see if this old style optim is any faster ? which I doubt ...
Expand Down Expand Up @@ -156,7 +156,7 @@ template <class Type>

tREAL8 aSomWIx = 0.0;
tREAL8 aSomDerWIx = 0.0;
for (int aKX=0 ; aKX< aNbX ; aKX++)
for (int aKX=0 ; aKX< aNbX ; aKX++) // doc SCALARPRODUCT
{
aSomWIx += aLineIm[aKX] * aLineWX [aKX];
aSomDerWIx += aLineIm[aKX] * aLineDerWX[aKX];
Expand Down

0 comments on commit 0063cc0

Please sign in to comment.