summaryrefslogtreecommitdiff
path: root/macros/undistortImage.sci
diff options
context:
space:
mode:
authorshamikam2017-01-16 02:56:17 +0530
committershamikam2017-01-16 02:56:17 +0530
commita6df67e8bcd5159cde27556f4f6a315f8dc2215f (patch)
treee806e966b06a53388fb300d89534354b222c2cad /macros/undistortImage.sci
downloadFOSSEE_Image_Processing_Toolbox-master.tar.gz
FOSSEE_Image_Processing_Toolbox-master.tar.bz2
FOSSEE_Image_Processing_Toolbox-master.zip
First CommitHEADmaster
Diffstat (limited to 'macros/undistortImage.sci')
-rw-r--r--macros/undistortImage.sci68
1 files changed, 68 insertions, 0 deletions
diff --git a/macros/undistortImage.sci b/macros/undistortImage.sci
new file mode 100644
index 0000000..9fccd42
--- /dev/null
+++ b/macros/undistortImage.sci
@@ -0,0 +1,68 @@
+function new_image = undistortImage(image, cameramatrix, varargin)
+// Transforms an image to compensate for lens distortion.
+//
+// Calling Sequence
+// newimage = undistortImage(image, cameramatrix)
+// newimage = undistortImage(image, cameramatrix, ["Parameter1", value1,["Parameter2", value2]])
+//
+// Parameters
+// image : Distorted input image
+// cameramatrix : Input 3 * 3 cameramatrix
+// distcoeffs : Input vector of distortion coefficients of 4, 5, or 8 elements. If the vector is empty, the zero distortion coefficients are assumed.
+// newCameraMatrix : Camera matrix of the distorted image. By default, it is same as cameramatrix.
+// newimage : Corrected image that has same size and type as original image
+//
+// Description
+// The function returns a newimage containing the input image with lens distortion removed.
+//
+// Examples
+// J = undistortImage(I, cameramatrix)
+// J = undistortImage(I, cameramatrix, "distcoeffs", distcoeffs)
+//
+// Authors
+// Suraj Prakash
+
+ [ lhs rhs ] = argn(0)
+
+ if lhs > 1 then
+ error(msprintf("Too many output arguments"))
+ end
+
+ if rhs > 6 then
+ error(msprintf("Too many input arguments"))
+ end
+
+ if rhs < 2 then
+ error(msprintf("Too less input arguments"))
+ end
+
+ if modulo(rhs, 2) <> 0
+ error(msprintf("Incorrect input arguments"))
+ end
+
+ image_list = mattolist(image)
+
+ if rhs == 2 then
+
+ temp = opencv_undistortImage(image_list, cameramatrix)
+
+ elseif rhs == 4 then
+
+ temp = opencv_undistortImage(image_list, cameramatrix, varargin(1), varargin(2))
+
+ elseif rhs == 6 then
+
+ temp = opencv_undistortImage(image_list, cameramatrix, varargin(1), varargin(2), varargin(3), varargin(4))
+
+ else
+ error(msprintf("Error in input arguments"))
+ end
+
+ sz = size(temp)
+
+ for i=1:sz
+ new_image(:, :, i) = temp(i)
+ end
+
+
+endfunction