Matlab

How to display image in GUI using Matlab

Steps to display image in GUI using Matlab

Step 1: Open GUI

Open Matlab -> Go to Start -> GUIDE(GUI Builder)


Select Blank GUI(Default) in GUIDE Quick Start


Step 2: Create Axes

Click on axes and create axes. Adjust size (width x height) according to your necessary.


Step 3: Save GUI

Now save GUI and click on M-file Editor


Step 4: Write code to display image

Write code after guidata(hObject, handles) in Updata handles structure

axes(handles.axes1);
imshow('G:\display\sample_image.jpg')

Here sample_image is image name & display is folder where image is saved.
Axes1 is name of axes.

It looks like this

% Update handles structure
guidata(hObject, handles);
axes(handles.axes1);
imshow('G:\display\sample_image.jpg')


Step 5: Run GUI

Now click on Run button to see result.

How to display image in Matlab

Matlab can display any image format like jpg, gif, tif etc using imshow command.


imshow('path\image_name.jpg')

imshow is command to display image in Matlab.

path is dir where image is present.

image_name is name of image is to be display.

Example :-
If image test.jpg is present in naikgroup folder in G drive than

imshow('G:\naikgroup\test.jpg')

if image test present in tif format than

imshow('G:\naikgroup\test.tif')

if more than 1 image have to display than use figure before imshow.

figure
imshow('path\image_name.jpg')

Example :-
if you want to display 2 image called test1.jpg and test2.jpg from naik folder in G drive than code will be

figure
imshow('G:\naik\test1.jpg')
figure
imshow('G:\naik\test2.jpg')

Note:- change path according to your image present in drive.

How to save image using Matlab

Matlab Can save image in hard disk in any format using imwrite command.

imwrite(image_name,'path/image_name.jpg','jpg');

imwrite is command used to save image in hard disk.

image_name is name of image.

path is dir where you want to save image.

example :-
if you want have image named test in jpg format in naikgroup folder in D drive.

imwrite(test,'D:\naikgroup\test.jpg','jpg');

Back to Top