# Thilina's Blog

## MATLAB GUI programming (code level) 2.0 – Undocumented MATLAB – JAVA codes in MATLAB M-files

This is something I found really interesting in MATLAB. We can write m-scripts with JAVA codes, this is very useful when designing UI components for MATLAB applications. In this article I will share my experience on creating GUI in MATLAB using JAVA and also an implementation of video cropping software (backend part will be discussed on my next article).

When using JAVA codes in *.m files we do not use “new” keywords to initiate any objects.  I am not sure the usage of import keyword in MATLAB/JAVA. Therefore JFrame must be used as  java.swing.JFrame. It is quite different from JAVA.

`JFrame frame = new JFrame; // Java Syntax`
`frame = javax.swing.JFrame; % matlab syntax`

2012 May 30

## Photo Effects using MATLAB 2.0 – Optical Illusion using MATLAB – Shake your head and see the image

This is something I found really interesting while wandering in facebook. Most of facebook fan pages shares a set of images which has black and white columns saying “shake your head and see the image”, which will results in seeing a hidden image in black and white column grid. Later when I search google, also found a number of images which similar to the images shared around facebook. In this article I share my attempts and experience on how I create my own optical illusion (shake your head and see image) using MATLAB.

When we look at the image closely we can notice the hidden image with very low intensity, which is not noticeable when we look at it from a average distance of our eye to monitor. This is what I have done and it gives much better results when we use gray scale images than colour images. Fist I made a frame which has black and white columns (binary image) in same size of my source image. Then I performed element-wise multiplication with source image and created brightness shifted and normalized image as follows. Then again it was multiplied element-wise with the negation of frame.

2012 April 12 Posted by | Image Processing, MATLAB | 1 Comment

## Translation Invariant Image Registration using Phase Correlation – Panorama Imaging on MATLAB

Panorama Imaging is one of most specialized techniques in photography. The ratio of this photo is 2:1 or larger in size. Nowadays even modern mobile phones also have the feature of capturing panorama images, specially accelerometer based techniques have made it easier to capture wonderful pieces of images in panoramic way. Unfortunately in my mobile phone camera, even though it has panoramic imaging, it does not have such flexible feature on creating panorama images, therefore what I do is take two pictures and stitch them using MATLAB.

2012 March 24 Posted by | Image Processing, MATLAB, Technology | 9 Comments

## Hardware co-simulations for image processing applications using MATLAB Simulink Xilinx Block-set

When working with image processing applications on hardware level, during the simulations I personally felt, very hard to work with bit/byte data, without seeing the resulting image/video data. For this kind of application we need to stream in and stream out data bits/bytes to and for the hardware module we implemented. MATLAB Simulink with combination of Xilinx Block-set gives great help in dealing this issue. By using MATLAB we can reshape images in to data stream as well as reshape data streams back in to images in MATLAB environment as I discussed in my previous article.

But the problem rises with the complexity of the system in interest. According to the performance of your computer the simulation time can be varying, sometimes it may be able to take hours. Hardware Co simulations on MATLAB come as the solution for the pc performance limitation issue. In this article I am going to share my experiences on performing a hardware co-simulation on MATLAB with the FPGA development kit Atlys Spartan 6 with xls45-3 FPGA.

2011 December 6

## 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.

2011 September 25

## 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. 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”.

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

## Using Xilinx Core Generator – Division in FPGA

Xilinx ISE comes with a number of cores which can be used with their products. While we are working on our Final Year Project at the university we used a number of these cores to make our work easy. In this article I will share my experiences on Xilinx core generator by implementing a division core as an example.

Verilog HDL supports division by a constant such as

· (constant)/ (constant) or

· (variable)/(constant with power of two manner)

But when it goes to division of variable by variable or constant by variable it will not support a simple division and must use separate core (using Xilinx core generator or an advanced module designed by someone else). Look at following example.

```module simpleDivision(
quo,
div,
clk
);
input clk;
input [7:0] div;
output reg [7:0] quo = 0;
always @ (posedge clk)
quo = div/4;
endmodule
```

I used following test bench program to simulate above code and observed that the results will come within single clock cycle as below.

```module test_simpleDiv;
reg [7:0] div;
reg clk;
wire [7:0] quo;
simpleDivision uut (
.quo(quo),
.div(div),
.clk(clk)
);
initial begin
div = 0;
clk = 0;
#100;
#10 div = 20;
#10 div = 5;
#10 div = 121;
#10 div = 13;
#30 \$finish;
end
always #5 clk = ~clk;
endmodule
```

Note that the line

```always #5 clk = ~clk;
```

will generate the clock signal with the period of 10ns. Result was as below. When It goes to (variable/variable) division, Xilinx core generator supports a division core with two modes which can be used with division,

I’ll discuss how to generate the radix division core using Xilinx core generator, add a simple wrapper to the core and simulation results of the division.

2011 June 6 Posted by | Electronics, FPGA, Technology | 8 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,

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.

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, gatech.edu) 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);
plot(x,y,'o',xx,yy);
```

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