public Image2DMatrix GetImageMatrix() { Image2DMatrix sourceMatrix = _imageLoader.GetImageMatrix(); if (Quadrilateral != null) { //Bilinear transformations have 8 Parameter. These parameter can be obtained //by solving two linear equation systems. This will be done in the following. Quadrilateral targetQuadrilateral = GetTargetQuadrilateral(); Matrix <double> m = GetmMatrix(); Vector <double> a = GetaVector(targetQuadrilateral, m); Vector <double> b = GetbVector(targetQuadrilateral, m); double a0 = a[0]; double a1 = a[1]; double a2 = a[2]; double a3 = a[3]; double b0 = b[0]; double b1 = b[1]; double b2 = b[2]; double b3 = b[3]; return(Image2DMatrix.Transform(sourceMatrix, (x, y) => { x = (int)(a0 * x + a1 * y + a2 * x * y + a3); y = (int)(b0 * x + b1 * y + b2 * x * y + b3); return (x, y); })); } return(sourceMatrix); }
private Image2DMatrix ApplyTransformationMatrix(Image2DMatrix imageMatrix, TransformationMatrix transformationMatrix) { if (transformationMatrix != TransformationMatrix.UnitMatrix3x3) { if (SourceToTargetEnabled) { imageMatrix = Image2DMatrix.Transform(imageMatrix, transformationMatrix); } else { //With target to source enabled, the inverted transformation matrix is needed. Image2DMatrix targetMatrix = new Image2DMatrix(TargetImageHeight, TargetImageWidth, imageMatrix.BytePerPixel); imageMatrix = Image2DMatrix.TransformTargetToSource(imageMatrix, targetMatrix, transformationMatrix.Invert2D()); } } return(imageMatrix); }