add an slider to get value for activecontour

% Display segmented image
BWsIbf = activecontour(ImCh1,BWCh1, 400, 'edge');
% FinalImwithMask=imfuse(BWsIbf,ImCh1);
% imshow(FinalImwithMask);
% figure, imshow(ImCh1);
%title('Segmented Image');
[B,L] = bwboundaries(BWsIbf,'noholes');
imshow(ImCh1,[]);%label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
end

7 Comments

Is there a question there somewhere??
@ Santhana Raj the user want's to add an slider to get value for activecontour. So he is asking us to include it in his code I suppose.
KSSV, you are correct, I am so new to creating GUI. I spend a whole day on this problem. I would like to create a GUI without GUIDE that displays an image and have a slider.
I would appreciate your help. Cheers Peyman
This is how far I get it (see the code below), but I am getting an error:
function making_SliderForIm(ImCh1,BWCh1)
global I
global Imask
Imask=BWCh1;
I=ImCh1;
imshow(I,[]);
%create a slider
sld=uicontrol('Style', 'slider',...
'Min',1,'Max',50,'Value',41,...
'Position', [400 20 120 20],...
'Callback', @SliderVal);
function SliderVal(source,event)
val=source.Value;
% Display segmented image
BWsIbf = activecontour(I,Imask, 1+val, 'edge');
[B,L] = bwboundaries(BWsIbf,'noholes');
imshow(I,[]);%label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
end
end
end
the error is :
Error using activecontour
Expected input number 3, N, to be integer-valued.
Error in activecontour>parse_inputs (line 302)
validateattributes(N,{'numeric'},{'positive','scalar','finite', ...
Error in activecontour (line 224)
[A, mask, N, method, smoothfactor,contractionbias] = parse_inputs(varargin{:});
sliders have floating point values when you drag them. You can just use
round( val )
to make it integer.
I used ceil , thanks.
There is another problem, I need the image to get updated. At the moment, it get the value and open another figure.
function making_SliderForIm(ImCh1,BWCh1)
global I
global Imask
Imask=BWCh1;
I=ImCh1;
imshow(I,[]);
%create a slider
sld=uicontrol('Style', 'slider',...
'Min',1,'Max',50,'Value',41,...
'Position', [400 20 120 20],...
'Callback', @SliderVal);
function SliderVal(source,event)
val=ceil(source.Value);
% Display segmented image
BWsIbf = activecontour(I,Imask, 1+val, 'edge');
[B,L] = bwboundaries(BWsIbf,'noholes');
imshow(I,[]);%label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 2);
end
end
end

Sign in to comment.

Answers (1)

The final code is provided here:
https://au.mathworks.com/matlabcentral/answers/332877-update-image-in-gui-without-guide

Tags

Asked:

on 30 Mar 2017

Answered:

on 5 Apr 2017

Community Treasure Hunt

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

Start Hunting!