How to proceed with image processing in GUI?

I have set up a GUI whereby the first push button(Load a MRI image) is to allow the user to select any image. I would like to proceed with image processing using the selected image from the first pushbutton. I have other pushbuttons like 'image enhancement', 'roi detection'. How can I proceed with image processing using the selected image from the first pushbutton?

Respuestas (3)

Walter Roberson
Walter Roberson el 14 de En. de 2016

0 votos

1 comentario

Gee Cheng Mun
Gee Cheng Mun el 14 de En. de 2016
Editada: Walter Roberson el 14 de En. de 2016
I tried but I don't understand. I can't save the image and process it under the second pushbutton.
% --- Executes on button press in load_mri.
function load_mri_Callback(hObject, eventdata, handles)
path='G:\FYP2\';
filter='*.png;*.jpg;*.tif;*.png;*.gif';'All Image Files';
[selectedFile, selectedPath]=uigetfile(fullfile(path, filter));
handles.img=imread([selectedPath, selectedFile]);
axes(handles.axes2);
image(handles.img);
setappdata(load_mri, 'Load MRI Image'); %save the application data
% --- Executes on button press in enhancement.
function enhanchObjectement_Callback(hObject, eventdata, handles)
yourVariable = getappdata(load_mri, 'Load MRI Image')
mri=imread(yourVariable);
gray=rgb2gray(mri);
I=imadjust(gray);
imshow(I);

Iniciar sesión para comentar.

Walter Roberson
Walter Roberson el 14 de En. de 2016
Below I show proper use of both handles and setappdata
% --- Executes on button press in load_mri.
function load_mri_Callback(hObject, eventdata, handles)
path='G:\FYP2\';
filter='*.png;*.jpg;*.tif;*.png;*.gif';'All Image Files';
[selectedFile, selectedPath]=uigetfile(fullfile(path, filter));
[~, image_name, ~] = basename(selectedFile);
image_file = fullfile(selectedPath, selectedFile);
image_data = imread(image_name);
axes(handles.axes2);
image(image_data);
%image name is small, you can afford to store it in handles
handles.image_name = image_name;
handles.image_file = image_file;
guidata(hObject, handles);
%image content could be big, do not store it in handles
myfig = ancestor(hObject, 'figure');
setappdata(myfig, 'Loaded_MRI_Image', image_data); %save the application data
% --- Executes on button press in enhancement.
function enhanchObjectement_Callback(hObject, eventdata, handles)
myfig = ancestor(hObject, 'figure');
mri = getappdata(myfig, 'Loaded_MRI_Image'); %it is already the image
image_name = handles.image_name;
gray = rgb2gray(mri);
I = imadjust(gray);
imshow(I);
title( sprintf('Contrast adjusted "%s"', image_name) );

4 comentarios

Gee Cheng Mun
Gee Cheng Mun el 14 de En. de 2016
Editada: Gee Cheng Mun el 14 de En. de 2016
I tried your code and I am not able to display the image. Initially, the code allows me to display this image. However, now it is not able to.
Undefined function 'basename' for input arguments of type 'char'.
Error in Finaldraft>load_mri_Callback (line 81) [~, image_name, ~] = basename(selectedFile);
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Finaldraft (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Finaldraft('load_mri_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Sorry, I should have used the function fileparts instead of basename
[~, image_name, ~] = fileparts(selectedFile);
I am now able to load the image but not able to process it under enhancement, using the same loaded image.
Error using feval Undefined function 'enhancement_Callback' for input arguments of type 'struct'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Finaldraft (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)Finaldraft('enhancement_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
myfig = ancestor(hObject, 'figure');
mri = getappdata(myfig, 'Load_MRI_Image', image_data); %it is already the image
gray = rgb2gray(mri);
I = imadjust(gray);
imshow(I);
title( sprintf('Contrast adjusted "%s"', image_name) );
Image Analyst
Image Analyst el 15 de En. de 2016
enhancement_Callback is not spelled the same as enhanchObjectement_Callback, so which is it? Which is the right name?

Iniciar sesión para comentar.

Image Analyst
Image Analyst el 14 de En. de 2016

0 votos

You might try MAGIC: http://www.mathworks.com/matlabcentral/fileexchange/24224-magic-matlab-generic-imaging-component All that stuff is already worked out for you. You just put your analysis code into the function AnalyzeSingleImage. It handles all the rest from listing image names in a listbox to displaying them to batch processing them to sending results to Excel.

Categorías

Más información sobre Convert Image Type en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 14 de En. de 2016

Comentada:

el 15 de En. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by