Thilina's Blog

I might be wrong, but…

View Streamed Image data on Simulink in Real-time

Two more months to go and it ends the final semester of final year at the University. All are rushing to finalise their final year projects, do simulations again and again, create test cases etc. Since our final year project is related to FPGA implementation of an image processing application, we used to work with images and they need to send as a data stream to the FPGA for processing. When performing simulations (Using MATLAB Simulink Xilinx Block set) we created the image in to data stream and sent it via Ethernet cable to the FPGA, so called Hardware co-simulation. The way we created the data stream is described in my previous article and I wish to add another article on Hardware Co-simulations in future.

However we had a small problem which the resulted image can only be viewed after performing the full simulation, which takes a lot of time, sometimes it takes hours. So finally by using a combination of MATLAB function block, unit delay block and video viewer block we were abled to design a model which reshapes the image stream back to its original image in real-time. From this article I will share my experience on creating the real-time image viewer for image streams.

Continue reading

2011 September 25 Posted by | Electronics, FPGA, Image Processing, MATLAB | 11 Comments

Streaming data from MATLAB-workspace to Simulink

Since we are having our final year project term in the university we are working in a rush with the projects. Our final year project is related to a hardware implementation related to image processing; we use MATLAB together with Xilinx for simulations. This is something I did to make our final year project simulations easy. In this article I share my experience on how to send workspace data to MATLAB simulink with respect to a clock and data enable flag generated by simulink blocks.

MATLAB simulink block “from workspace” allows us to send workspace variables to simulink. The data format must be with at-least two column matrix since the first column is considered as the time stamp. To get a basic idea about how “from workspace” block works, let’s use following simulink model.


Continue reading

2011 July 1 Posted by | FPGA, Image Processing, MATLAB | 6 Comments

Photo Effects using MATLAB 1.0

Last few days I edited some of my photos using Picasa 3. In this application I found some interesting effects which can be added to images such as pictures which you can use as Facebook profile pictures etc.


I was quite interested to know how they were implemented. However I came out with a small set of solutions developed by myself to archive similar results to Picasa. In this article I will share my solutions to implement “Soft Focus” and “Focal B&W” by Picasa and an effect bit similar to the “Vignetting Effect” say “Shading Effect”.

Continue reading

2011 June 18 Posted by | Image Processing, MATLAB | 4 Comments

Sorting Algorithms sample codes on JAVA, C++ and MATLAB

Sorting is the process which puts the elements in a list to an order. Sorting algorithms are used to optimize the performance and resources usage in computer science. Since I was interested to work with C++ I decided to implement some of those algorithms to be familiar with the language, but later on I thought it may be useful to implement those in JAVA as well as in MATLAB. From this article I am going to share my experiences in implementing those codes in above languages. I used Wikipedia, sorting algorithms website and the book “Introduction to Algorithms 3e” as my references. The algorithms I implemented was,

  1. Selection Sort
  2. Insertion Sort
  3. Bubble Sort
  4. Quick Sort
  5. Merge Sort
  6. Shell Sort

Sample codes will be as below. In MATAB, this can be used to compare any numeric data type such as uint8, uint16, int8, int16, double, etc. But in case of JAVA and C++ I wrote them to work with integers. Since I am new to C++ I some good points in using arrays/pointers with C++, such as how to initialize an array with a length which is an argument of that function, to get the size of an array, etc. These codes may not be the optimised codes for above algorithms but a small attempt to implement those on three platforms.

Continue reading

2011 June 1 Posted by | C++, Java, MATLAB | 26 Comments

Digital Image Zooming on MATLAB using spline Interpolation

In my previous article on image zooming I shared how I implemented the basic image zooming methods namely ‘nearest neighbour’, ‘bi-linear’, ‘bi-cubic’ on MATLAB. In this article I will share how I used MATLAB built-in function ‘spline ()’ to zooms images on MATLAB.

Function spline () on MATLAB

Just for getting basic idea let’s have a brief look on the MATLAB spline function. MATLAB spline function performs cubic spline interpolation (on Wikipedia, for a given data set. The spline interpolation function is as below.

 yy = spline(x, y, xx) 

The yy[] is the cubic spline interpolated value for the values y[] if underlying function at the breakpoints defined by x[] for the interpolant xx. The first example found in MATLAB help (‘doc spline’) is as below.

x = 0:10;
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);

Continue reading

2011 May 5 Posted by | Image Processing, MATLAB | 22 Comments

Contrast Stretching for Gray Scale images with MATLAB

When studying “Introduction to Image Processing and Machine vision” and “Bio Medical Engineering and Instrumentation” for the end semester exam, I read a small section related to those two modules which can be easily implemented using MATLAB. “Contrast Stretching” is a simple piecewise linear transformation function which expands the range of intensity of the image to user defined span.

Simple mathematical illustration of the process is as below.


Considering Line L1;                             clip_image004

Considering Line L2;                             clip_image006

Considering Line L3;                             clip_image008

Continue reading

2011 March 23 Posted by | Image Processing, MATLAB | 11 Comments


When you using your MATLAB programs such as GUI related things its bit messy to run MATLAB and then to run your MATLAB scripts since MATLAB takes some time to run and it uses more resources from your computer. So it’s very easy if we can run our MATLAB applications without running MATLAB. The MATLAB compiler gives us the opportunity which to convert our m-scripts to exe files. In this article I’ll try to share my experiences on configuring MATLAB compiler and to deploy a MATLAB script to an *.exe file.


Make sure you got installed ANSI C or C++ Compiler in your computer. First type ‘mbuild -setup’ on your MATLAB command prompt.


Press ‘y’ and Enter to continue on operation (Pressing <ENTER> is also sufficient since the default answer is [y].) Then MATLAB will list down all the compilers you have installed in your computer and prompt you to select a compiler to use.


I choose ‘Microsoft Visual C++ 2008 SP1 in C:\Program Files\Microsoft Visual Studio 9.0’ as my compiler, so I enter ‘2’.

Continue reading

2011 February 5 Posted by | MATLAB | 15 Comments

MATLAB GUI programming (code level) 1.0 – Paint Effect for Images

When surfing in facebook I saw a lot of profile pictures which is modified as painted images. Rather than using the facebook apps I thought to write my own program to do it for me. In this article I’ll try to share my experience on GUI programming in MATLAB without MATLAB GUI guide and the construction of the paint brush effect code.

When studying the image with paint brush effect I noticed that the image colour levels are now limited to a low number, which is most likely a one colour intensity to represent a set of colour. By keeping this in mind I coded a small test program as below.

clc, clear all, close all;
im = imread('image_3.jpg');
rateR = 40;
rateG = 60;
rateB = 50;
ima(:,:,1) = cast(rateR*round(im(:,:,1)/rateR),'uint8');
ima(:,:,2) = cast(rateG*round(im(:,:,2)/rateG),'uint8');
ima(:,:,3) = cast(rateB*round(im(:,:,3)/rateB),'uint8');
imhisto(:,1) = imhist(ima(:,:,1));
imhisto(:,2) = imhist(ima(:,:,2));
imhisto(:,3) = imhist(ima(:,:,3));
figure, plot(imhisto);

Hopefully it got worked, what I have done is,

Continue reading

2011 January 25 Posted by | Image Processing, MATLAB | 7 Comments

Switch Mode Power Supplies MATLAB simulation 1.0

When dealing with switch mode power supply design, we faced a problem in simulating SMPS circuits since most of simulation software is not flexible with simulating circuits which has tapped transformers. We face this problem specially on simulating isolated switch mode converters such as fly-back converter.

MATLAB simulink SimPowerSystems block set gives a best solution in simulating switch mode power supplies. From this article I’ll work on design a buck converter works on continuous mode and another in discontinuous mode with calculations and to implement both on MATLAB simulink.

Design Problem


Design switch mode power supply (a buck converter) for Input voltage 30V, output voltage 20V and with 100µH of storage element for,

1. 100W resistive load,

2. 20W resistive load

Find pulse width D for 20 KHz of pulse frequency.


Continue reading

2011 January 16 Posted by | Electronics, MATLAB, Technology | 11 Comments

Chroma Keying MATLAB Implementation 4.0

Hopefully this will be my final article on chroma keying, in this article I will try to address the key disadvantages and faults identified in my previous posts by myself. In my previous chroma keying functions I only segmented a region which has the luminance level of [x, 255] or [0, x]. But on working with function I realised that some colour details in images also has segmented out as a background mask.

With this experience I modified my function to segment out a small colour band which is most likely acts as the background of the foreground image. What I have done is obtain the mean colour (say mR, mG, mB) and its maximum deviation (say sR, sG, sB) on user defined points on the foreground image and then segment the foreground image using the colour band obtained from the above result. Now the modified segemented colour band will be [mR-sR:mR+sR, mG-sG:mG+sG, mB-sB:mB+Sb] which will results in less colour distortion in the resulting image.

Continue reading

2011 January 10 Posted by | Chroma Keying, Image Processing, MATLAB | 2 Comments

%d bloggers like this: