GUI How to make multiple slider
2 次查看(过去 30 天)
显示 更早的评论
Hi, I am trying to write edge detection that threshold based on length and intensity. I create a ui for it but everytime i update length then intensity got resetted and everytime i update intensity length got resetted. how do i make sure the data is kept. means if intensity 10 and length 10 and i push slider so length 100 then intensity stays at 10 not go back to 0. code below help thanks
function myui
Im = imread('42049.jpg');
threshold = 0;
length = 10;
% Create a figure and axes
f = figure('Visible','off');
ax = axes('Units','pixels');
BW = edge(Im, 'sobel', threshold);
imshow(BW);
% Slider for threshold
sld = uicontrol('Style', 'slider',...
'Min',0,'Max',1,'Value',0,...
'Position', [400 20 120 20],...
'Callback', @thresh_slider);
% Slider for length
sld = uicontrol('Style', 'slider',...
'Min',0,'Max',500,'Value',0,...
'Position', [200 20 120 20],...
'Callback', @length_slider);
% Add text for slider
txt = uicontrol('Style','text',...
'Position',[400 45 120 20],...
'String','Threshold');
txt = uicontrol('Style','text',...
'Position',[200 45 120 20],...
'String','Length');
% Make figure visble after adding all components
f.Visible = 'on';
function thresh_slider(source,callbackdata)
threshold = source.Value;
BW = edge(Im, 'sobel', threshold);
ConnectedComponents = bwlabel(BW);
a = unique(ConnectedComponents);
out = [a,histc(ConnectedComponents(:),a)];
FinalImage = zeros(size(BW,1), size(BW,2));
for i = 1:size(ConnectedComponents,1)
for j = 1:size(ConnectedComponents,2)
componentID = ConnectedComponents(i,j);
componentLength = out(componentID+1,2);
if(componentID == 0)
FinalImage(i,j) = 0;
elseif(componentLength > source.Value && componentID ~= 0)
FinalImage(i,j) = 1;
end
end
end
imshow(FinalImage);
end
function length_slider(source,callbackdata)
length = source.Value;
BW = edge(Im, 'sobel', threshold);
ConnectedComponents = bwlabel(BW);
a = unique(ConnectedComponents);
out = [a,histc(ConnectedComponents(:),a)];
FinalImage = zeros(size(BW,1), size(BW,2));
for i = 1:size(ConnectedComponents,1)
for j = 1:size(ConnectedComponents,2)
componentID = ConnectedComponents(i,j);
componentLength = out(componentID+1,2);
if(componentID == 0)
FinalImage(i,j) = 0;
elseif(componentLength > length && componentID ~= 0)
FinalImage(i,j) = 1;
end
end
end
imshow(FinalImage);
end
end
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!