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

Understanding Transformation Matrix

July 4, 2017

In last few posts we had looked into various Affine transformation and we learned about the transformation matrix. Let’s summarize the Affine transformation matrices in this post with animation, which is written in pure Scilab script.

Run the following script in Scilab to see the animation:

 

// 4 points square
x = [0 1 1 0]';
y = [0 0 1 1]';
 
// Plot the points
plot(x,y,'*');
ax = gca();
ax.data_bounds = [-1 -1;5 5];
ax.children.children.mark_size = 10;
xnumb(x,y,1:4);
 
// Initialize points for the transformation
plot(x,y,'or');
e = gce();
ax = gca();
ax.children.children.mark_size = 10;
 
// Change this for slower animation, in ms
delay = 1;
cnt2 = 1;
// Translation
for cnt = [0:0.1:3 3:-0.1:0]   
    sleep(delay);
    m = [1 0; 0 1; cnt cnt];
    xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1)
    e.children.data = xy;
    title('$ Translation\\ \left[\begin{array}{c}1 & 0 \\0 & 1 \\' + string(cnt) + '&' + string(cnt) + '\end{array}\right] $','position',[-1 2],'fontsize',5);
end 
 
// Rotation
for cnt = [5:5:45 45:-5:0]     
    sleep(delay);
    m = [cosd(cnt) -sind(cnt); sind(cnt) cosd(cnt); 0 0];
    xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1)
    e.children.data = xy;
    title('$ Rotation\\ \left[\begin{array}{c}cosd('+string(cnt)+') & -sind('+string(cnt)+')\\-sind('+string(cnt)+') & cosd('+string(cnt)+')\\ 0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5);
end 
 
// Scaling
for cnt = [1:0.1:5 5:-0.1:1]    
    sleep(delay);
    m = [cnt 0 ;0 cnt;0 0];
    xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1)
    e.children.data = xy;
    title('$ Scaling\\ \left[\begin{array}{c}' + string(cnt) + ' & 0 \\0 & ' + string(cnt) + ' \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5);
 
end 
// Shearing
for cnt = [0:0.1:1 1:-0.1:0]    
    sleep(delay);
    m = [1 cnt ;cnt 1;0 0];
    xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1)
    e.children.data = xy;
    title('$ Shearing\\ \left[\begin{array}{c}1 & ' + string(cnt) + ' \\' + string(cnt) + ' & 1 \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5);    
end

// 4 points square x = [0 1 1 0]'; y = [0 0 1 1]'; // Plot the points plot(x,y,'*'); ax = gca(); ax.data_bounds = [-1 -1;5 5]; ax.children.children.mark_size = 10; xnumb(x,y,1:4); // Initialize points for the transformation plot(x,y,'or'); e = gce(); ax = gca(); ax.children.children.mark_size = 10; // Change this for slower animation, in ms delay = 1; cnt2 = 1; // Translation for cnt = [0:0.1:3 3:-0.1:0] sleep(delay); m = [1 0; 0 1; cnt cnt]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Translation\\ \left[\begin{array}{c}1 & 0 \\0 & 1 \\' + string(cnt) + '&' + string(cnt) + '\end{array}\right] $','position',[-1 2],'fontsize',5); end // Rotation for cnt = [5:5:45 45:-5:0] sleep(delay); m = [cosd(cnt) -sind(cnt); sind(cnt) cosd(cnt); 0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Rotation\\ \left[\begin{array}{c}cosd('+string(cnt)+') & -sind('+string(cnt)+')\\-sind('+string(cnt)+') & cosd('+string(cnt)+')\\ 0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end // Scaling for cnt = [1:0.1:5 5:-0.1:1] sleep(delay); m = [cnt 0 ;0 cnt;0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Scaling\\ \left[\begin{array}{c}' + string(cnt) + ' & 0 \\0 & ' + string(cnt) + ' \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end // Shearing for cnt = [0:0.1:1 1:-0.1:0] sleep(delay); m = [1 cnt ;cnt 1;0 0]; xy= [x y] * m(1:2,1:2) + repmat(m(3,:),4,1) e.children.data = xy; title('$ Shearing\\ \left[\begin{array}{c}1 & ' + string(cnt) + ' \\' + string(cnt) + ' & 1 \\0 & 0\end{array}\right] $','position',[-1 2],'fontsize',5); end

The following animation is the similar result you will see when you run the above script:

In summary, the Affine transform will reallocate the pixel value in the “blue star” location to the “red circle” location.

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

Post navigation

Previous Post:

Affine Transformation – Shearing

Next Post:

Perspective Transformation – A Manual Way

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