Friday, 18 January 2013

How to Make GUI in Matlab.


GUI Tutorial



Making Graphical User Interfaces in Matlab is very simple. A good place to begin learning about GUI development on the Matlab platform is to first understand how Matlab manages graphical objects.

How Does Matlab GUI Work


Inspector Property 
GUI in Matlab is in essence a collection of objects. Every object in the GUI has a unique handle (name), This handle will allow developers to access the objects properties

      i.e: let’s say we wanted to change the text on the button from 'Push Button' to 'Press ME'. All we have to do is obtain the object’s handle. Once we have the handle we can then set the 'text' property of the object to 'Press ME'.

to change it for any object , you had to open  the property inspector (Right click ) then you will find as in figure.Property Inspector,

you will need to Change String and Tag to your needed data.

String : is the name of the object that viewed in the GUI.
Tag: is the name of the object that will be used in control the component  (object)
NB: every component has difference Property Inspector (PI) but all of them contain sting/tag property . 



How do I obtain the Handle of an Object ?


Example………
>> fig = openfig('test.fig'); %loads the figure.
>> handles = guihandles(fig) %Gets handles.

To obtain a handle in the previous version the user must poll the object for it’s handle. To
poll the object the user must give every GUI object a unique ‘Tag’. For instance the
default tag for the ‘PushButton’ is ‘pustbutton1’. There for the following is what the user
would need to do in order to obtain the handle of the object.

how to open the GUI:
  >> guide 
in command window or click on in the guide button from the tool bar.




how to get the object:
  >> pushbutton1_handle = findobj(‘Tag’,’pushbutton1’);
now you got the pushbutton1 handler and can work on it.

how do we change properties?


Matlab has two very important functions, which allow the user to alter an object’s properties at their discretion. These functions are listed below.

GET: Get object properties.
     GET(H,'PropertyName') returns the value of the specified property for the graphics object with handle H.

SET: Set object properties.

SET(H,'PropertyName',PropertyValue) sets the value of the specified property for the graphics object with handle H.



SUMMARY:

• Guihandle() -> This function obtains all the handles in the GUI.
• Get() -> Allows users to obtain an object for a single property at runtime.
• Set() -> Allows users to change an objects property at runtime.


References:

  1. http://www.mathworks.com/discovery/matlab-gui.html
  2. http://blogs.mathworks.com/videos/category/gui-or-guide/
  3. http://www.mathworks.com/matlabcentral/answers/30070-gui-guide-tutorials
  4. http://www.fatih.edu.tr/~aserdogan/Matlab/MatLabGUItutorial.pdf

read and view Image

you can start with any programing language but here for simplicity ,
I will start with matlab.

reading Image

image = imread ('coin.pmb');

 image is stored in 'image' array either will be gray level or RGB image.


Change RGB to gray image:

to change it from RGB to gray with loosing data.
          gray_image = unit8(image);

now it will be gray level , with cell values  from 0 to 8. and that will make it easier to handel it in image processing data working.


Show image:

you can show and add labels in the x and y directory and show title of the image by using below commands.

   figure,imshow('gray_image ');

   legend ('Normal Cases' , 'Abnormal Cases');
   xlabel (' X label') ;
   ylabel ('Y label') ;
   title (' here is title');

print image:

to print image after showing automatically in your work-space directory ,you can use below command. 
     print -dpng image.png