Вы находитесь на странице: 1из 3

EXPERIMENT NO.

-5(a)
AIM: - Creating a GUI and performing Basic Image transformations through Buttons and Axes.

GRAPHICAL USER INTERFACE in MATLAB:-

GUIs (also known as graphical user interfaces or UIs) provide point-and-click control of software
applications, eliminating the need to learn a language or type commands in order to run the
application.

MATLAB apps are self-contained MATLAB programs with GUI front ends that automate a task or
calculation. The GUI typically contains controls such as menus, toolbars, buttons, and sliders. Many
MATLAB products, such as Curve Fitting Toolbox™, Signal Processing Toolbox™, and Control
System Toolbox™ include apps with custom user interfaces. You can also create your own custom
apps, including their corresponding UIs, for others to use.

 Open up MATLAB. Go to new and select GRAPHICAL USER INTERFACE.

 Choose the first option Blank GUI (Default) and you will see the following screen

 For the experiment, we need panels, buttons and axes.

 Click on the "ok" button in the left hand side of the window. This will allow you to
drag and drop a pushbutton. Similarly, do for axes and panels.

 Double click on the components you just created. A property manager will pop up and
then change the properties according to your requirements, like, colour, text style, test
size etc. Following will be the design:-

Figure 1
 Basic Image Transformations, as discussed in the previous experiments, are done in
the corresponding buttons. Right Click on the button and go to ‘View Callback ’ to go
to the function code of corresponding push button.
 PUSH BUTTON 1= GRAY IMAGE:
global imgbw As the image imgbw will be required in the entire
program, it is made global in this function as well as
in the functions in which it’ll be used.
[filename,path]=uigetfile(... Image and its path is stored in filename and path.
uigetfile opens a prompt box to select an image. Three
dots at end represent continue.
{'*.jpg','Jpg file(*.jpg)';... Jpg type file can be selected.

'*.tif','Tiff file(*.tif)';... Tiff file can be selected.


'*.*','Any File';},... Any type of file can be selected.
'Pick Image'); This is the name given to the prompt box.
img=imread(filename); ‘img’ variable stores the image in the filename
variable.
imgbw=rgb2gray(img); Converting img to gray scale image and storing it in
imgbw.
axes(handles.axes1); Command to access the axes to display the image on
it.
imshow(imgbw); Outputs the image on the axes.

 PUSH BUTTON 2 – IDENTITY :

global imgbw The variables imgbw, m and n will be used in other


global m functions as well, hence, they are made global.
global n
[m n]=size(imgbw); To access every pixel value of image, it is necessary
to identify size i.e. no. of rows and no. of columns.

for i=1:m Two for loops to access every row and column.
for j=1:n Calculating the identity matrix of original image by
id(i,j)=imgbw(i,j); cpying every pixel of imgbw image into id matrix.
end
end

axes(handles.axes2); Displaying identity image in the axes 2.


imshow(id);

 PUSH BUTTON 3 – NEGATIVE IMAGE :

global imgbw The variables imgbw, m and n will be used in other


global m functions as well, hence, they are made global.
global n

for i=1:m Calculating negative of the image imgbw by


for j=1:n subtracting each pixel value from highest value i.e.
neg(i,j)=255-imgbw(i,j); 255.
end
end
axes(handles.axes3); Displaying Negative image in the axes 3.
imshow(neg);

 PUSH BUTTON 4 – LOGARITHMIC IMAGE :


global imgbw The variables imgbw, m and n will be used in other
global m functions as well, hence, they are made global.
global n

img1=im2double(imgbw); Log function always works with an image in ‘double’


format. Hence, image imgbw is converted to double.
for i=1:m Calculating logarithmic value of each pixel valueof
for j=1:n image imgbw and storing it in imglog.

imglog(i,j)=log10(1+img1(i,j));
end
end
axes(handles.axes4); Displaying Log image in the axes 4.
imshow(imglog);

 PUSH BUTTON 5 – POWER LAW :

global imgbw The variables imgbw, m and n will be used in other


global m functions as well, hence, they are made global.
global n

for i=1:m Calculating Power Law value by squaring each pixel


for j=1:n value of image imgbw and storing it in pl.

pl(i,j)=power(imgbw(i,j),2);
end
end
axes(handles.axes5); Displaying Power Law image in the axes 5.
imshow(pl);

After performing every operation in the callbacks of every push button, the final output is
given in the below figure:

Figure 2

Вам также может понравиться