You are on page 1of 17

Image Processing with MATLAB

Graphical User Interface (GUI)


Project Introduction:

Image processing is a practice commonly used by people who can access computers,

cameras and anything that can capture and make a photo. A person can actually alter the

rendered images and detect their edges, improve the contrast, use different mathematical

operations to the images, and even measure the image intensity with a little money to invest

on. Although the said techniques are powerful, it should be borne in mind that an average user

often tries to manipulate an image abundantly digitally. Rarely, understanding the basic

principles of manipulation suffices for the simplest techniques of image processing.

Digital image processing basically involves the use of various computer algorithms to

develop, process, view and distribute digital images. This type of processing could be mainly

used to:

- Extract the image's scale, size, or number of objects.

- Increase efficiency, such as noise reduction and other artefacts

- Help to transform signals sent by an image sensor to a digital image.

- Compress the picture so it's easy to transfer between networks.

One of the software’s used for digital image processing is the MATLAB. MATLAB is a

computing and programming language of high standard that provides powerful yet easy to

understand commands and syntaxes. MATLAB offers many processes such as computing,
developing algorithms, analyzing data and even having simulation through the use of Simulink.

MATLAB may be said not only to be a programming interface, but also to be an environment.

With the support of MATLAB, one can perform the most basic operations to high level

algorithms and create programs as well. One thing to note is that MATLAB may be high and

efficient, but it needs to be useful to the application itself as it can not isolate applications to be

individually useful to all operating systems.

This project was made as a final target for the students via MATLAB. The software is an

image processing program that would use MATLAB operations' different capabilities. This

project uses the MATLAB Graphical User Interface or better known as the MATLAB GUI to

display the techniques of image processing as required. The project uses a Graphical User

Interface format so that the program will be user friendly for both knowledgeable people with

MATLAB as well as beginners.

Acknowledgement

We would like to express our special thanks of gratitude to Engr. Leonardo D. Valiente

Jr. who gave us the golden opportunity to do this wonderful project on MATLAB, which also

helped us in doing a lot of research and we came to know about so many new things we are

really thankful to them. Secondly we would also like to thank our parents and friends who

helped us a lot in finalizing this project within the limited time frame.
Program Description

The program aims to use the MATLAB Graphical User Interface System to display various

filter characteristics of an image. It should be able to display the following:

 Binary Image

 Image Type

 Indexed Image

 Intensity Image

 Multiframe Image

 RGB (red, green, and blue) Image

 FIR Filter

 Morphological Opening o estimate the Background

 Subtraction of the Background Image from the Original Image

 Image contrast Adjustment

 Threshold of the image

The program will also display both the original and filtered characteristics of the image

at the same time. The program should be able to display both the filtered and the original

images which the user will be using. The program’s functions have been embedded with the

Graphical User Interface program file to reduce the amount actions needed for the program to

execute such as opening the directory to initiate the function files.


Scope and Limitations

The created program cover’s a limited amount of filtering characteristics and only uses

the FIR filter. The created program is only applicable to the MATLAB and Simulink database and

would only operate if the MATLAB program is installed on the running computer. It should also

be remembered that only photographs can be processed in this software and nothing else.

The created program can process filters and image processing one at a time. If the

image is of a higher resolution, it will take a longer time for the system to measure and load the

image output. The solution for this type of problem is to choose a lower-dimensional image for

the software to be able to render quicker.

Screen capture of image file


Files and functions used in the project

function varargout = Imahe(varargin)


% IMAHE MATLAB code for Imahe.fig
% IMAHE, by itself, creates a new IMAHE or raises the existing
% singleton*.
%
% H = IMAHE returns the handle to a new IMAHE or the handle to
% the existing singleton*.
%
% IMAHE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMAHE.M with the given input arguments.
%
% IMAHE('Property','Value',...) creates a new IMAHE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Imahe_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Imahe_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Imahe

% Last Modified by GUIDE v2.5 20-Jan-2020 02:08:13

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Imahe_OpeningFcn, ...
'gui_OutputFcn', @Imahe_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT

% --- Executes just before Imahe is made visible.


function Imahe_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Imahe (see VARARGIN)

% Choose default command line output for Imahe


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes Imahe wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = Imahe_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure


varargout{1} = handles.output;

% --- Executes on button press in Browse_Image.


%This function does browse your File Explorer to put image.
function Browse_Image_Callback(hObject, eventdata, handles)
% hObject handle to Browse_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Filename,Pathname]=uigetfile('.jpg','File Selector');
name=strcat(Pathname,Filename);
global orig_img
orig_img = imread(name);
axes(handles.axes1);
imshow(orig_img);

% --- Executes on button press in Save_Image.


%This function does to save your process image.
function Save_Image_Callback(hObject, eventdata, handles)
% hObject handle to Save_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global new_img
[filename, foldername] = uiputfile('new img.jpg');
complete_name = fullfile(foldername, filename);
imwrite(new_img, complete_name)

% --- Executes on button press in Morphological_Opening.


function Morphological_Opening_Callback(hObject, eventdata, handles)
% hObject handle to Morphological_Opening (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img
bw = im2bw(orig_img);
SE=[0 1 0; 1 1 1;0 1 0];
bw1 = imopen(bw,SE);
new_img = imcomplement(bw1);
axes(handles.axes2);
imshow(new_img);

% --- Executes on slider movement.


function Brightness_Callback(hObject, eventdata, handles)
% hObject handle to Brightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider
global orig_img valofbright

valofbright = 0.5*get(hObject, 'Value')-0.5;


imgBright = orig_img + valofbright;
axes(handles.axes2);
imshow(imgBright);

% --- Executes during object creation, after setting all properties.


function Brightness_CreateFcn(hObject, eventdata, handles)
% hObject handle to Brightness (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on button press in FIR.


function FIR_Callback(hObject, eventdata, handles)
% hObject handle to FIR (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

fir=fspecial('motion',80,69);
new_img=imfilter(orig_img,fir);
axes(handles.axes2)
imshow(new_img);

% --- Executes on slider movement.


function Contrast_Slider_Callback(hObject, eventdata, handles)
% hObject handle to Contrast_Slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider
global orig_img
global new_img
amnt=get(handles.Contrast_Slider,'Value');
new_img = localcontrast(orig_img, 0.4, amnt);
axes(handles.axes2);
imshow(new_img)

% --- Executes during object creation, after setting all properties.


function Contrast_Slider_CreateFcn(hObject, eventdata, handles)
% hObject handle to Contrast_Slider (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on button press in Thresh.


function Thresh_Callback(hObject, eventdata, handles)
% hObject handle to Thresh (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img imgFile
imgGry = rgb2gray(orig_img);
imageBlk = im2bw(imgGry);
axes(handles.axes2);
imshow(imageBlk);
imgFile = getimage(handles.axes2);

% --- Executes on button press in Red.


function Red_Callback(hObject, eventdata, handles)
% hObject handle to Red (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,2:3)=0;
axes(handles.axes2);
imshow(new_img)

% --- Executes on button press in Green.


function Green_Callback(hObject, eventdata, handles)
% hObject handle to Green (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,1)=0;
new_img(:,:,3)=0;
axes(handles.axes2);
imshow(new_img)

% --- Executes on button press in Blue.


function Blue_Callback(hObject, eventdata, handles)
% hObject handle to Blue (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,1)=0;
new_img(:,:,2)=0;
axes(handles.axes2);
imshow(new_img)

% --- Executes on button press in Binary_Image.


function Binary_Image_Callback(hObject, eventdata, handles)
% hObject handle to Binary_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img = im2bw(orig_img);
axes(handles.axes2);
imshow(new_img)

% --- Executes on button press in Intensity_Image.


function Intensity_Image_Callback(hObject, eventdata, handles)
% hObject handle to Intensity_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img = rgb2gray(orig_img);
axes(handles.axes2);
imshow(new_img)

% --- Executes on button press in Indexed_Image.


function Indexed_Image_Callback(hObject, eventdata, handles)
% hObject handle to Indexed_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

[new_img,map] = rgb2ind(orig_img,100);
axes(handles.axes2);
imshow(new_img,map)

% --- Executes on button press in Multiframe_Image.


function Multiframe_Image_Callback(hObject, eventdata, handles)
% hObject handle to Multiframe_Image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

axes(handles.axes2);
new_img=repmat(orig_img,[ 1 1 1 6 ]);
axes(handles.axes2);
montage(new_img)

% --- Executes on button press in Subtract_Background.


function Subtract_Background_Callback(hObject, eventdata, handles)
% hObject handle to Subtract_Background (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img sub_img

Background = imopen(orig_img,strel('disk',13));
Subtract = imsubtract(orig_img, Background);
axes(handles.axes2);
imshow(Subtract);
sub_img = axes(handles.axes2);

% --- Executes on slider movement.


function Brightness2_Callback(hObject, eventdata, handles)
% hObject handle to Brightness2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider
global orig_img valofbright

valofbright = 0.5*get(hObject, 'Value')-0.5;


imgBright = orig_img + valofbright;
axes(handles.axes3);
imshow(imgBright);

% --- Executes during object creation, after setting all properties.


function Brightness2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Brightness2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on slider movement.


function Contrast_Slider2_Callback(hObject, eventdata, handles)
% hObject handle to Contrast_Slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'Value') returns position of slider


% get(hObject,'Min') and get(hObject,'Max') to determine range of
slider
global orig_img
global new_img
amnt=get(handles.Contrast_Slider,'Value');
new_img = localcontrast(orig_img, 0.4, amnt);
axes(handles.axes3);
imshow(new_img)

% --- Executes during object creation, after setting all properties.


function Contrast_Slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to Contrast_Slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: slider controls usually have a light gray background.


if isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end

% --- Executes on button press in Binary_Image2.


function Binary_Image2_Callback(hObject, eventdata, handles)
% hObject handle to Binary_Image2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img = im2bw(orig_img);
axes(handles.axes3);
imshow(new_img)

% --- Executes on button press in Intensity_Image2.


function Intensity_Image2_Callback(hObject, eventdata, handles)
% hObject handle to Intensity_Image2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img = rgb2gray(orig_img);
axes(handles.axes3);
imshow(new_img)

% --- Executes on button press in Indexed_Image2.


function Indexed_Image2_Callback(hObject, eventdata, handles)
% hObject handle to Indexed_Image2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

[new_img,map] = rgb2ind(orig_img,100);
axes(handles.axes3);
imshow(new_img,map)

% --- Executes on button press in Multiframe_Image2.


function Multiframe_Image2_Callback(hObject, eventdata, handles)
% hObject handle to Multiframe_Image2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

axes(handles.axes3);
new_img=repmat(orig_img,[ 1 1 1 6 ]);
axes(handles.axes3);
montage(new_img)

% --- Executes on button press in Red2.


function Red2_Callback(hObject, eventdata, handles)
% hObject handle to Red2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,2:3)=0;
axes(handles.axes3);
imshow(new_img)

% --- Executes on button press in Green2.


function Green2_Callback(hObject, eventdata, handles)
% hObject handle to Green2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,1)=0;
new_img(:,:,3)=0;
axes(handles.axes3);
imshow(new_img)

% --- Executes on button press in Blue2.


function Blue2_Callback(hObject, eventdata, handles)
% hObject handle to Blue2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

new_img=orig_img;
new_img(:,:,1)=0;
new_img(:,:,2)=0;
axes(handles.axes3);
imshow(new_img)

% --- Executes on button press in Morphological_Opening2.


function Morphological_Opening2_Callback(hObject, eventdata, handles)
% hObject handle to Morphological_Opening2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img
bw = im2bw(orig_img);
SE=[0 1 0; 1 1 1;0 1 0];
bw1 = imopen(bw,SE);
new_img = imcomplement(bw1);
axes(handles.axes3);
imshow(new_img);

% --- Executes on button press in FIR2.


function FIR2_Callback(hObject, eventdata, handles)
% hObject handle to FIR2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img
global new_img

fir=fspecial('motion',80,69);
new_img=imfilter(orig_img,fir);
axes(handles.axes3)
imshow(new_img);

% --- Executes on button press in Thresh2.


function Thresh2_Callback(hObject, eventdata, handles)
% hObject handle to Thresh2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img imgFile
imgGry = rgb2gray(orig_img);
imageBlk = im2bw(imgGry);
axes(handles.axes3);
imshow(imageBlk);
imgFile = getimage(handles.axes3);

% --- Executes on button press in Subtract_Background2.


function Subtract_Background2_Callback(hObject, eventdata, handles)
% hObject handle to Subtract_Background2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global orig_img sub_img

Background = imopen(orig_img,strel('disk',13));
Subtract = imsubtract(orig_img, Background);
axes(handles.axes3);
imshow(Subtract);
sub_img = axes(handles.axes3);
Sample Outputs
References

https://electronicsforu.com/electronics-projects/image-processing-using-matlab-part-1

https://electronicsforu.com/electronics-projects/software-projects-ideas/image-processing-

using-matlab-basic-operations-part-2-4

https://www.mathworks.com/help/matlab/ref/rgb2gray.html

https://www.mathworks.com/help/images/process-multiframe-image-arrays.html

https://www.mathworks.com/matlabcentral/answers/340791-how-do-i-use-the-fir-filter-on-

an-image

https://www.mathworks.com/matlabcentral/answers/251519-i-need-negative-image

https://www.mathworks.com/help/images/morphological-filtering.html

https://www.mathworks.com/help/images/ref/imadjust.html

https://www.mathworks.com/discovery/image-thresholding.html

https://www.mathworks.com/help/images/adjust-image-contrast-in-image-viewer-app.html

https://www.mathworks.com/matlabcentral/answers/369024-how-to-do-background-

subtraction-between-two-images-to-find-the-roi

https://www.mathworks.com/matlabcentral/answers/360646-how-can-i-get-a-rgb-values-

from-a-picture

You might also like