image is shown vertically
4 views (last 30 days)
Show older comments
I tried to implement the GUI. When I upload an image, it is sucessfully convert to gray scale image. But when I click preprocess and edge detection button, the image is gone to vertical. What is the issue. Please help me.
This is GUI. When I click convert to gray scale, it is shown as below.
When I click preprocess image, it is shown as below.
This is my code.
function varargout = DiameterWithGui(varargin)
% DIAMETERWITHGUI MATLAB code for DiameterWithGui.fig
% DIAMETERWITHGUI, by itself, creates a new DIAMETERWITHGUI or raises the existing
% singleton*.
%
% H = DIAMETERWITHGUI returns the handle to a new DIAMETERWITHGUI or the handle to
% the existing singleton*.
%
% DIAMETERWITHGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DIAMETERWITHGUI.M with the given input arguments.
%
% DIAMETERWITHGUI('Property','Value',...) creates a new DIAMETERWITHGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DiameterWithGui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DiameterWithGui_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 DiameterWithGui
% Last Modified by GUIDE v2.5 27-Mar-2021 21:21:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DiameterWithGui_OpeningFcn, ...
'gui_OutputFcn', @DiameterWithGui_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 DiameterWithGui is made visible.
function DiameterWithGui_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 DiameterWithGui (see VARARGIN)
% Choose default command line output for DiameterWithGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DiameterWithGui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DiameterWithGui_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 diameterEditText_Callback(hObject, eventdata, handles)
% hObject handle to diameterEditText (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,'String') returns contents of diameterEditText as text
% str2double(get(hObject,'String')) returns contents of diameterEditText as a double
% --- Executes during object creation, after setting all properties.
function diameterEditText_CreateFcn(hObject, eventdata, handles)
% hObject handle to diameterEditText (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit 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
% --- Executes on button press in inputImage.
function inputImage_Callback(hObject, eventdata, handles)
% hObject handle to inputImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[fname path] = uigetfile('*.*', 'Enter an Image');
fname = strcat(path, fname);
a = imread(fname);
%im = imresize(im, [300 NaN]);
%a = get(handles.diameterEditText, 'string');
set(handles.diameterEditText, 'string', a);
axes(handles.axes2);
imshow(a);
setappdata(0, 'a', a);
% --- Executes on button press in preprocessImage.
function preprocessImage_Callback(hObject, eventdata, handles)
% hObject handle to preprocessImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Add noise
data = getappdata(0, 'gray');
J = imnoise(data,'poisson');
%Remove noise
%wiener = wiener2(J,[5 5]);
axes(handles.axes2);
%imshow(J);
imshow(data);
% --- Executes on button press in ConvertToGrayScale.
function ConvertToGrayScale_Callback(hObject, eventdata, handles)
% hObject handle to ConvertToGrayScale (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
a = getappdata(0, 'a');
agray = rgb2gray(a);
axes(handles.axes2);
imshow(agray);
setappdata(0, 'gray', gray);
% --- Executes on button press in checkDiameter.
function checkDiameter_Callback(hObject, eventdata, handles)
% hObject handle to checkDiameter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in edgeDetection.
function edgeDetection_Callback(hObject, eventdata, handles)
% hObject handle to edgeDetection (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = getappdata(0, 'gray');
%Add noise
J = imnoise(data,'poisson');
%Remove noise
wiener = wiener2(J,[5 5]);
BW1 = edge(wiener,'sobel');
axes(handles.axes2);
imshow(BW1);
9 Comments
Image Analyst
on 28 Mar 2021
Make it easy for your users to select an image. Don't force them to browse to it. That's not convenient at all for the user - it's a hassle. Simply put a listbox on your window and use dir() to load it up with filenames. Then in the callback of the listbox, simply get the filename, read it in, and display it. Then all a user has to do is simply click on a filename - much easier and better than what you're making them do.
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!