Skip to content

Scilab IPCV

Image Processing and Computer Vision Module for Scilab 6.0!

  • Installation
    • Installation IPCV v1.1
    • Installation IPCV v1.2
  • Getting Started
  • Subscribe for FREE
  • Support Us
  • Courses
    • Artificial Intelligence with Scilab
    • Image Processing with Scilab

Perspective Transformation – A Manual Way

July 10, 2017

In last few posts we deal with Affine transforms, which we constructed our own transformation matrices to perform the transformation.

Today, we will look into a more useful transformation –> Perspective Transform, which used to transform the 3d world into 2d image. 

Let say we have an image taken by camera as below:

Notice that the image was taken from the left angle and the Sudoku puzzle box was slanted. Our purpose today is to make the slanted image flat to our view in 2D, so that we could used it in our coming post, including solving the puzzle by Scilab. 🙂

Let’s do it in manual way today.

// Import image
S=imread('sudoku1.jpg');
 
// Select 4 points from the figure
src = warpmatselect(S,4);

// Import image S=imread('sudoku1.jpg'); // Select 4 points from the figure src = warpmatselect(S,4);

At this stage, a figure with the image above will be shown and waiting for the user to click on the image to select 4 meaningful points as the source. Select the points in proper sequences as below:

Next, we will choose the location which we want our image to map to:

tgt = warpmatselect(S,4);

tgt = warpmatselect(S,4);

Do note that you need to choose the points in the same orientation with the sources points in order to get the desired result.

The perspective transform will map the source’s point 1 to target’s point 1, and so on.

 

// Find the transformation matrix and perform the transformation 
mat = imgettransform(src,tgt,'perspective');
Snew = imtransform(S,mat,'perspective');
imshow(Snew);

// Find the transformation matrix and perform the transformation mat = imgettransform(src,tgt,'perspective'); Snew = imtransform(S,mat,'perspective'); imshow(Snew);

Still not satisfied with the result? You could always make it better by defining the target points manually:

 

sz = size(S);
tgt = [0 0;0 sz(1);sz(1) sz(1);sz(1) 0];
mat = imgettransform(src,tgt,'perspective');
Snew2 = imtransform(S,mat,'perspective');
Snew3 = imcrop(Snew2,[1 1 sz(1) sz(1)]);
imshow(Snew3);

sz = size(S); tgt = [0 0;0 sz(1);sz(1) sz(1);sz(1) 0]; mat = imgettransform(src,tgt,'perspective'); Snew2 = imtransform(S,mat,'perspective'); Snew3 = imcrop(Snew2,[1 1 sz(1) sz(1)]); imshow(Snew3);

How about now?

Please take note that the image coordinates are different with Cartesian Coordinates, where the origin of the image is on the upper left corner while the Cartesian space origin located at the bottom left.

 

Share on Facebook Share
Share on TwitterTweet
Share on Google Plus Share
Share on LinkedIn Share
Send email Mail

Post navigation

Previous Post:

Understanding Transformation Matrix

Next Post:

Solving Sudoku In Image with Scilab

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Support Us

By Buying Us Coffee :)

Topics

  • Computer Vision & Hardware Interfaces
  • Feature Detection, Description and Matching
  • Image Fusion
  • Image Linear Filtering
  • Image Reading, Display and Exploration
  • Image Stitching
  • Image Types and Color Space Conversions
  • Installation
  • Introduction
  • Machine Learning & Deep Learning
  • Morphological Operations
  • Object Detection
  • Object Recognition
  • Spatial Transformations
  • Super Resolution
  • Uncategorized
  • Utilities

Recent Posts

  • Deep Learning Inference with Scilab IPCV – Lenet5 with MNIST Visualization
  • Deep Learning Inference with Scilab IPCV – Pre-Trained Lenet5 with MNIST
  • What’s New in IPCV 2.0
  • Computer Vision – Live Video from Webcam
  • Drawing Shapes by Overwriting Pixel Value




Tags

Affine affine transform Clarifai cnn computer vision convert to binary image convolution convolutional neural network correlation covert rgb to gray deep learning dnn feature detection feature extraction Google Vision API graphic user interface gui image 3d plot image filtering image matching image measurement image processing image reading image resize image rotation image scaling image shearing image stitching image transform installation introduction linear regression machine learning map mapping morphology object detection object removal panoramic perspective perspective transform scilab spatial transform sudoku translation
© 2021 Scilab IPCV