Reputation: 108
I got an error when using active contour:
??? Undefined function or method 'activecontour' for input arguments of type 'single'.
Error in ==> Segmentasi>threshold_Callback at 114 final = activecontour(image2,mask , 100);
image1 = handles.citra1;
level=0.008;
bw = edge(image1,'Canny');
axes(handles.axes2);
imshow(bw,[]);
%active contour
image2 = bwdist(~bw);
mask = zeros(size(image2));
mask(25:end-25,25:end-25) = 1;
final = activecontour(image2,mask , 100);
axes(handles.axes5)
imshow(final,[]);
handles.data3 = final;
guidata(hObject,handles);
I am using an image from dicom files (sagital image)
Upvotes: 0
Views: 496
Reputation: 6434
The problim is that the output of the bwdist
function is a matrix and the input of the activecontour
function is a grayscale image. So you need to convert the matrix to a grayscale image before using it. This is done using a function called mat2gray
. To do so, after using bwdist
apply mat2gray
as follows:
image2 = mat2gray(bwdist(~bw));
And then the rest of the code works. Check my simple example:
bw = zeros(200,200);
bw(50,50) = 1;
bw(50,150) = 1;
bw(150,50) = 1;
D1 = bwdist(bw);
D2 = mat2gray(D1);
mask = zeros(size(D2));
mask(25:end-25,25:end-25) = 1;
final = activecontour(D2,mask,100);
subplot(1,3,1);imshow(bw)
subplot(1,3,2);imshow(mat2gray(D1))
subplot(1,3,3);imshow(final,[]);
Upvotes: 3