IPSDK  4_1_0_2
IPSDK : Image Processing Software Development Kit

Solves an overdeterminated system Ax=b for each pixel using a QR decomposition. More...

IPSDKIPLLINEARALGEBRA_API image::ImagePtr ipsdk::imaproc::la::qrSolverImg (const image::ImageConstPtr &pInSeqImg1, const image::ImageConstPtr &pInSeqImg2, const ipUInt32 inNbFeatures)
 wrapper function for Solves an overdeterminated system Ax=b for each pixel using a QR decomposition More...
 
IPSDKIPLLINEARALGEBRA_API void ipsdk::imaproc::la::qrSolverImg (const image::ImageConstPtr &pInSeqImg, const image::ImageConstPtr &pInSeqImg2, const ipUInt32 inNbFeatures, const image::ImagePtr &pOutSeqImg)
 wrapper function for Solves an overdeterminated system Ax=b for each pixel using a QR decomposition More...
 

Detailed Description

Solves an overdeterminated system Ax=b for each pixel using a QR decomposition.

In some cases, it can be necessary to find the parameters of an analytic model. States before and after applying the model are known, but the way the data are transformed is a black box. A common example is finding the motion field between two images. In that example, positions in both images are known but we want to model the displacement for all pixels

Such a transform can be expressed as an overdetermined linear system $Ax=b$. Where $A$ is a set of data, covering several features (for example gratients) on several images, $b$ is a known result we want to reach with an estimate of the linear model parametrized by the coefficients of $x$.

We have here more equations than unknowns. The most ordinary way to solve the solution is the least squares method :

\[ x = (A^T A)^{-1} A^T b \]

To efficiently achieve this calculation, it is possible to decompose $A$ into two matrices $Q$ and $R$. We can rewrite the problem :

\[ Ax=b \Leftrightarrow QRx=b \Leftrightarrow Rx=Q^{-1} b \]

The first advantage of this factorization is that $Q^{-1} = Q^T$, we can rewrite the previous equation :

\[ Rx=Q^T b \]

The second advantage is that $R$ is diagonal, we can easily solve the system. We choose the Householder reflection to achieve the decomposition.

Given two images InSeqImg1 and InSeqImg2, this algorithm solves the system to find the parameters x, stored in the image OutRealSeqImg.

The input image InSeqImg1 is assigned to $A$, whereas the vector $b$ is represented by InSeqImg2. For each pixel, the coefficients are stored along the temporal dimensions. In the case of InSeqImg1, we use a row-major representation of the matrix $A$.

The temporal size of $A$ equals the temporal size of $b$ multiplied by the temporal size of $x$, and the temporal size of $x$ equals the number of features used in the linear system.

See also
https://en.wikipedia.org/wiki/Overdetermined_system
https://en.wikipedia.org/wiki/QR_decomposition

Attributes description

Attribute description for algorithm :

Name ToolTip Default Initializer
ipsdk::imaproc::attr::InSeqImg1 [Input] First input image sequence X
ipsdk::imaproc::attr::InSeqImg2 [Input] Second input sequence image X
ipsdk::imaproc::attr::InNbFeatures [Input] target number of features to be detected by algorithm X
ipsdk::imaproc::attr::OutRealSeqImg [Output] Real sequence image customOutput (_pOutRealSeqImg, outputQRSolver(_pInSeqImg1,_pInNbFeatures))

Global Rule description

Global rule description for algorithm :
ipsdk::imaproc::customImageProperty (_pInSeqImg2,
 matchQRSolverInput (_pInSeqImg1,_pInNbFeatures)) && 
ipsdk::imaproc::customImageProperty (_pOutRealSeqImg,
 matchQRSolverOutput (_pInSeqImg1,_pInNbFeatures))

Example of Python code :

Example imports

import PyIPSDK
import PyIPSDK.IPSDKIPLLinearAlgebra as la

Code Example

imX = la.qrSolverImg(imA, imB, nbFeatures)

Example of C++ code :

Example informations

Associated library

IPSDKIPLLinearAlgebra

Header file

#include <IPSDKIPL/IPSDKIPLLinearAlgebra/Processor/QRSolverImg/QRSolverImg.h>

Code Example

// We want to solve the system Ax=b for each pixel,
// where the coefficients are stored along the temporal dimensions
// Sample with a generated output image
// ------------------------------------
// Solve the QR system
ImagePtr pAutoOutImg = qrSolverImg(pInImgA, pInImgB, nbFeatures);
// Sample with a provided output image
// -----------------------------------
// create output image
ImageGeometryPtr pOutputImageGeometry = geometrySeq2d(eImageBufferType::eIBT_Real32, sizeX, sizeY, nbFeatures);
boost::shared_ptr<MemoryImage> pOutImg(boost::make_shared<MemoryImage>());
pOutImg->init(*pOutputImageGeometry);
// compute square value of input image
qrSolverImg(pInImgA, pInImgB, nbFeatures, pOutImg);
See also
QRSolverImgLvl1
QRSolverImgLvl2
QRSolverImgLvl3

Function Documentation

◆ qrSolverImg() [1/2]

IPSDKIPLLINEARALGEBRA_API image::ImagePtr ipsdk::imaproc::la::qrSolverImg ( const image::ImageConstPtr pInSeqImg1,
const image::ImageConstPtr pInSeqImg2,
const ipUInt32  inNbFeatures 
)

wrapper function for Solves an overdeterminated system Ax=b for each pixel using a QR decomposition

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure

◆ qrSolverImg() [2/2]

IPSDKIPLLINEARALGEBRA_API void ipsdk::imaproc::la::qrSolverImg ( const image::ImageConstPtr pInSeqImg,
const image::ImageConstPtr pInSeqImg2,
const ipUInt32  inNbFeatures,
const image::ImagePtr pOutSeqImg 
)

wrapper function for Solves an overdeterminated system Ax=b for each pixel using a QR decomposition

Exceptions
ipsdk::processor::IPSDKBaseProcessingExceptionon failure