Reputation: 1
I want to create a GUI with matlab, to browse for an image and process it before displaying it to some axes.
I can't browse the image with my current program, and the image that I want to display is related to the previous process. Is it possible to browse and display all of the processed images to the axes with just one pushbutton? Can someone help me create the GUI for this sample program?
folder = 'D:\wildlife';
baseFileName = 'page-6.png';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %Gambar tidak ditemukan.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = .
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(2, 3, 1);
imshow(rgbImage);
title('Gambar Asli', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
%set the morphology
SE = strel ('square', 3);
j=imerode (rgbImage, SE);
subplot(2, 3, 2);
imshow(j);
title('Penebalan Citra', 'FontSize', fontSize);
% Binarize to find black pixels
% Find where either red, green, or blue channel is dark.
thresholdValue = 55;
binaryImage = j(:,:, 1) < thresholdValue | j(:,:, 2) < thresholdValue | j(:,:, 3) < thresholdValue;
% Display the image.
subplot(2, 3, 3);
imshow(binaryImage);
title('Citra Biner', 'FontSize', fontSize);
% Fill the image
filledImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 3, 4);
imshow(filledImage);
title('Pengisian Citra Biner', 'FontSize', fontSize);
drawnow;
Upvotes: 0
Views: 2623
Reputation: 279
To create the GUI, Matlab's GUIDE feature is well documented and relatively easy to use and learn (http://www.mathworks.com/help/matlab/gui-building-basics.html). Simply type 'guide' at the Matlab prompt to bring up the quick start menu.
Once you create a new blank GUI, you can add a push button and as many axes as you need to display the various images (4 for your sample code above). Then the code to browse for, process, and display the image can be placed in the callback for the push button. To open the callback code, right click on the push button and select "View Callbacks -> Callback" from the menu.
Then you can us something like the following to browse for the desired image:
[baseFileName, folder, FilterIndex] = uigetfile('*.png');
To display the image in the desired axis, specify the appropriate axis handle as the 'Parent' argument in your calls to 'imshow', rather than using 'subplot':
% Display the original color image.
fullFileName = [folder baseFileName];
rgbImage = imread(fullFileName);
imshow(rgbImage, 'Parent', handles.axes1);
Upvotes: 1