Home > Image Processing > 2. SciLab Basics

2. SciLab Basics

For the rest of the semester, I’d probably be using a couple of essential tools on my journey to learning image processing. One brilliant software I encountered is SciLab, an high-level cross-platform programming language very efficient for numerical computations and scientific visualizations. Many researchers choose SciLab for its vast capabilities on signal processing and image enhancement. Best of all, unlike other software, SciLab is non-proprietary and completely open-source. The product is in the public domain – freely downloadable online. Anyone can run, copy, modify and redistribute its packages. For the download location, click here.

SciLab offers a good Integrated Development Environment (IDE) for the user for working with codes and figures. The following is a screenshot I have captured from my own desktop.

Figure 1. A snapshot of the SciLab IDE

The tool offers a console for easy preview of short one-liner codes, and an embedded test editor, called SciPad, for working with files.

My primary operating system is Linux (specializing in GNU-based applications).  Currently I am using the Ubuntu distribution.  For installing SciLab in Ubuntu, one can open the package list at:

System > Administration > Synaptic Package Manager

then mark SciLab* for installation.

Alternatively, simply open the terminal and enter (as root):

sudo apt-get install scilab

The image processing end of the software is referred as the SciLab Image and Video Processing Toolbox (SIVP), an equivalent of the SIP in Windows.  To install this extension, run:

sudo apt-get install sivp

This tool can be loaded from the SciLab console via:

Toolboxes > sivp

*Latest stable version as of article date: SciLab 5.2.1-8, compatible with SIVP 0.5.0-1.

For a good jumpstart, I used SciLab scripts to familiarize with the basic functionalities (and workarounds) of the imaging tool.  On a 2D canvass, I constructed basic shapes using binary matrices.  The initial scipt [1] reads:

nx = 500; ny = 500;      // defines the number of elements along x and y
x = linspace(-1, 1, nx); //defines the range
y = linspace(-1, 1, ny);
[X, Y] = ndgrid(x, y);   // creates two 2-D arrays of x and y coordinates
A = zeros(nx, ny);

This basically prepares a 500×500 matrix filled with zeroes (ready to be filled with data later).  The script to create a circle will be:

r = sqrt(X.^2 + Y.^2);   // element-per-element squaring of X and Y
A (find((r<0.7))) = 1;  // values of r where r<0.7

Modifying this code creates an annulus:

A (find((r < 0.7) & (r > 0.4))) = 1; // values of r where  0.4<r<0.7

To view the figure, insert:

imshow(A);    // displays the 2D matrix A

Load the program into the console via:

Execute > Load into SciLab

or simply, Ctrl+L.  Figure 2A shows the output figure of the set of code.

Figure 2. A. annulus, B. square

In order to produce the square image (Figure 2B), the script would be:

A (find((abs(X) < 0.5) & (abs(Y) < 0.5))) = 1; // values of x and y from -0.5 to 0.5

where abs() is a built-in function for taking absolute values.

Next up, would be to create a set of horizontal gratings, which can be created using loops:

for i=1:1:500
   for j=1:100:500       // 100 being the period for how the gratings repeat
      A(j:j+50, i) = 1;   // 50 being the width of every grating

This script, when displayed, results to a fairly striped image (Figure 3A).

Figure 3. A. horizontal gratings, B. 2D sinusoid

Diverting from binary matrices, a smooth 2D sinusoidal function is created by:

freqc = 5*%pi;      // frequency of the sinusoidal
A = sin(X*freqc);

Lastly, to produce a 2D Gaussian distribution (Figure 4), we write:

r = sqrt(X.^2 + Y.^2); // note element-per-element squaring of X and Y
A = exp(-4*r);         // 2D Gaussian

Figure 4. 2D Gaussian

Saving the image into a file takes the one-liner:

imwrite(A, 'gaussian.bmp'); // also works with png, jpg, tif and gif

That wraps up my initial set of familiarization on SciLab.  This just marks the beginning of an exciting bunch of image processing ahead.  One final note, I believe it is always best to develop good coding habits.  For SciLab coding standards, let me share the Code Conventions for the SciLab Programming Language.

For this section, I would rate myself 10 for being able to comprehend the important ideas and produce the desired outputs.


[1] Soriano, M. (2010). A2 – Scilab Basics. Applied Physics 186.

About these ads
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Get every new post delivered to your Inbox.

%d bloggers like this: