Image Analysis from GUI with menu, listbox and pushbutton

2 vues (au cours des 30 derniers jours)
Muhammad Abir
Muhammad Abir le 3 Août 2018
Hello,
I would like to create a mainGUI which will have a menu bar and a listbox. I want to perform as follows: Step 1: Open Image from the menu 'Open Image' option. The listbox will show 'Image imported'.
Step 2: 'Median Filtering' from the menu: When 'Median Filter' is clicked, a subGUI for median filtering will pop up for filtering window options. Then I select my suitable filter size. Once 'Done' is clicked on the subGUI of the median filtering, the median filtering option will perform and then the listbox of the mainGUI will show the name of my process as 'Median Filter' with window size (that I selected from subGUI) displayed next to it.
A 'Delete' pushbutton on the bottom of the listbox to delete the 'median filter" if user wants to delete the median filtering. If I select'median filter' from the listbox and click 'Delete' pushbutton, then the median filtering step will be deleted and the image will go back to step 1.
Step 3: I also want to save all the steps that I performed as a text file so in future if I load that text file, I can run the steps that I perform previously. Also, I want to save a log file of all the steps including the values I have chosen.
Thanks in advance
  1 commentaire
Rik
Rik le 3 Août 2018
What have you tried so far?
Have a read here (or here for more general advice) and here. It will greatly improve your chances of getting an answer.

Connectez-vous pour commenter.

Réponse acceptée

Muhammad Abir
Muhammad Abir le 4 Août 2018
Modifié(e) : Walter Roberson le 4 Août 2018
Dear Image Analyst,
I checked the MAGIC gui but I do not see the required things I need. I specially need to display each step of my image processing on the listbox.
Let's say, When I load an Image, the axes1 will display the image and the listbox will show 'Image Loaded' Then I apply median filtering from menu. Then the listbox will show 'Median Filter'. The main thing I am interested is: When I select 'Median Filter' from the listbox and click 'Delete' pushbutton, the median filter step will be removed and the axes will display the loaded raw image.
Here is the gui that I am trying to make. I just don't understand how I can pass the string to the listbox and how the listbox can be interactive as I described.
function varargout = test_image_process(varargin)
% TEST_IMAGE_PROCESS MATLAB code for test_image_process.fig
% TEST_IMAGE_PROCESS, by itself, creates a new TEST_IMAGE_PROCESS or raises the existing
% singleton*.
%
% H = TEST_IMAGE_PROCESS returns the handle to a new TEST_IMAGE_PROCESS or the handle to
% the existing singleton*.
%
% TEST_IMAGE_PROCESS('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST_IMAGE_PROCESS.M with the given input arguments.
%
% TEST_IMAGE_PROCESS('Property','Value',...) creates a new TEST_IMAGE_PROCESS or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_image_process_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_image_process_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 test_image_process
% Last Modified by GUIDE v2.5 03-Aug-2018 21:34:57
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_image_process_OpeningFcn, ...
'gui_OutputFcn', @test_image_process_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 test_image_process is made visible.
function test_image_process_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 test_image_process (see VARARGIN)
% Choose default command line output for test_image_process
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test_image_process wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_image_process_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;
% --------------------------------------------------------------------
function file_menu_Callback(hObject, eventdata, handles)
% hObject handle to file_menu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function open_image_Callback(hObject, eventdata, handles)
% hObject handle to open_image (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% handles structure with handles and user data (see GUIDATA)
[fileName, pathName] = uigetfile('*.*', 'MultiSelect', 'on');
% Cancel if user hit cancel
if isequal(fileName, 0); return; end
% Make sure that fileName is a cell
if ischar(fileName); fileName = {fileName}; end
% Load all images into a cell array and store it in the handles structure
filenames = fullfile(pathName, fileName);
handles.imagedata = cellfun(@imread, filenames, 'uniformoutput', 0);
% Display the first one and store the graphics handle to the imshow object
handles.image = imshow(handles.imagedata{1}, 'Parent', handles.axes1);
guidata(hObject, handles);
% --------------------------------------------------------------------
% --- Executes on selection change in listbox1.
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --------------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
function image_processing_Callback(hObject, eventdata, handles)
% hObject handle to image_processing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function median_filter_Callback(hObject, eventdata, handles)
% hObject handle to median_filter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.FilterImage = arrayfun(@(k) medfilt2( handles.imagedata {k},[3,3]),1:numel(handles.imagedata ), 'UniformOutput',false);
handles.image = imshow( handles.FilterImage{1}, 'Parent', handles.axes1);
guidata(hObject, handles);
% --- Executes on button press in pushbutton_delete.
function pushbutton_delete_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_delete (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
  1 commentaire
Image Analyst
Image Analyst le 4 Août 2018
Well not right out of the box it won't. You have to adapt it of course, but it will give you a good start.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 3 Août 2018

Muhammad Abir
Muhammad Abir le 4 Août 2018
I was able to add string of the process, however, the text is static, not interactive. For example, I want to delete median filtering from the listbox so I can delete this step from my analysis. The process will update automatically to the previous open image step and the axes will also show only open image step.
oldstr = get(handles.listbox1,'String') % The string as it is now. addstr = {oldstr,get(hObject, 'Label')} % The string to add to the stack. set(handles.listbox1,'String',addstr); % Put the new string on bottom.
  2 commentaires
Image Analyst
Image Analyst le 4 Août 2018
Why not make the choice of median filtering to be a checkbox?
Muhammad Abir
Muhammad Abir le 4 Août 2018
I want to build a work flow where I can add/delete each process. Deleteing each process will go back to previous step automatically

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by