Group of Toggle button Fix

조회 수: 1 (최근 30일)
Parthkumar Patel
Parthkumar Patel 2020년 12월 10일
답변: Sahithi Kanumarlapudi 2020년 12월 15일
Hi,
I created app designer. My app can open image file from computer. show user real and gray image. but now i am trying to use togglegroup button, i don't know how to use it. i did write code for all toggle code. I don't understand how to connect with togglebutton selection.
selectedButton = app.ImageProcessingFunctionsButtonGroup.SelectedObject;
if isempty(imgray)
warndlg('Please select Image!')
return;
end
I= imgray;
% a. Mean and Median filtering with different sizes of kernels.
% Users should be able to type the size of the kernel.
choice = questdlg('Which filter do you select?', ...
'Filter Select', ...
'Mean','Median','Median');
switch choice
case 'Mean'
prompt={'Enter a size of kernal'};
name = 'kernal size';
defaultans = {'3'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
if ~isempty(answer)
windowWidth=str2double(answer{1});
kernal = ones(windowWidth) / windowWidth ^2;
J = conv2(double(I),kernal);
str='Mean Filtered Image';
else
return;
end
case 'Median'
prompt={'Enter a sizes of kernals'};
name = 'kernal sizes';
defaultans = {'[3 3]'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
if ~isempty(answer)
mn=str2num(answer{1});
J = medfilt2(I,[mn(1) mn(2)]);
str='Median Filtered Image';
else
return;
end
end
if isempty(imgray)
warndlg('Please select Image!')
return;
end
I=imgray;
%% b. Automatic thresholding based on the image histogram:
% The application should automatically select a threshold using Otsu’s method
% and manual thresholding value and then display the resulting binary image.
choice = questdlg('Which thresholding method do you select?', ...
'Method Select', ...
'Automatic','Manual','Manual');
% Handle response
switch choice
case 'Automatic'
level = graythresh(I);
J = imbinarize(I,level);
str='Automatic Thresholding Value';
case 'Manual'
prompt={'Enter a sizes of thresholding value'};
name = 'thresholding value';
defaultans = {'0.5'};
options.Interpreter = 'tex';
answer = inputdlg(prompt,name,[1 40],defaultans,options);
if ~isempty(answer)
level=str2num(answer{1});
J = imbinarize(I,level);
str='Manual Thresholding Value';
else
return;
end
end
% --- Executes on button press in togglebutton3.
function togglebutton3_Callback(app,event)
if isempty(imgray)
warndlg('Please select Image!')
return;
end
I=imgray;
% c. Edge detection algorithms:
% Sobel, Prewitt, and Roberts edge with default kernels in Matlab.
choice = questdlg('Which edge detection algorithms do you select?', ...
'Edge detection select', ...
'Sobel','Prewitt','Roberts','Roberts');
switch choice
case 'Sobel'
J=edge(I,'sobel');
str='Sobel Edge Detection';
case 'Prewitt'
J=edge(I,'prewitt');
str='Prewitt Edge Detection';
case 'Roberts'
J=edge(I,'roberts');
str='Roberts Edge Detection';
end
% --- Executes on button press in togglebutton4.
function togglebutton4_Callback(app,eventdata)
% hObject handle to togglebutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(imgray)
warndlg('Please select Image!')
return;
end
I=handles.imgray;
% d. Region growing segmentation algorithm:
% Users should be able to select a single point using mouse.
reg_maxdist=0.2;
[x, y] = getpts;
J = regiongrowing(I,x,y,reg_maxdist);
str='Region growing segmentation';
end
% --- Executes on button press in togglebutton5.
function togglebutton5_Callback(app, eventdata)
% eventdata reserved - to be defined in a future version of MATLAB
if isempty(imgray)
warndlg('Please select Image!')
return;
end
I=imbinarize(imgray);
%e. Morphological operations: Dilation, erosion, opening, filling, thinning, etc.
choice = choosedialog;
se = strel('line', 8, 8);
if strcmp(choice,'Dilation')==1
J = imdilate(I, se);
str='Dilated Image';
elseif strcmp(choice,'erosion')==1
J = imerode(I, se);
str='Eroded Image';
elseif strcmp(choice,'opening')==1
J = imopen(I, se);
str='Opened Image';
elseif strcmp(choice,'filling')==1
J = imfill(I,[3 3],8);
str='Filled Image';
elseif strcmp(choice,'thinning')==1
J = bwmorph(I,'thin');
str='Thining Image';
end

답변 (1개)

Sahithi Kanumarlapudi
Sahithi Kanumarlapudi 2020년 12월 15일
Hi,
I understad that you want to know how to create and interact with toggle buttons.
You can create a togglebutton with the 'uitogglebutton' function. Below is an example on for the same
fig = uifigure('Position',[680 678 398 271]);
bg = uibuttongroup(fig,'Position',[137 113 123 85]);
tb1 = uitogglebutton(bg,'Position',[10 50 100 22]);
For more information on how to use this function refer to the below documentation link
As per the documentation, To make your program respond when the app user selects a radio button or toggle button that is inside a button group. define a SelectionChangedFcn callback function for the ButtonGroup object. You cannot define callbacks for the individual buttons.
An example on how to interact with toggle button using ButtonGroup can be found in the below link
Hope this Helps!

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by