What is this error about?

Hi
I am trying to use an active contour and I get the error
Error using contour (line 46)
Input arguments for contour must be real. Use the function REAL to get the real part of the inputs.
Error in ruller (line 184)
hold on,[c,h] = contour(phi,[0 0],'r','linewidth',1); hold off
Can someone please explain me what this error is all about?

5 Commenti

Guillaume
Guillaume il 31 Gen 2019
The error message seems clear. Some elements of phi are complex. contour (nothing to do with active contour) only work on real inputs, not complex
[c,h] = contour(real(phi),[0 0],'r','linewidth',1);
It is something wrong going on. The specific code, never had issue. Since, I integrated to an another code I get errors, such as the forementioned, where I shouldn't.
Althought, with KSSV suggestion I made the contour work, still it is not satisfactory working.
I attach two images.
How it used to work previously, where it was running autonomously and the error.jpg, that indicates how it is running now, which is not the way I want.
What's wrong with it?
I use that code
us = {'Iterations:','Time Step:', 'Kernel Size (sigma):', 'Data Term Weight'};
t = cell2mat(us);
e = str2num(t);
numberOfLines = 4;
dialogTitle = 'Specify optimization parameters for LGD';
def = {'300', '0.1', '5', '20'};
U = inputdlg(us,dialogTitle,numberOfLines,def);
i = cellfun(@str2num,U);
r = real(i);
Img = double(J(:,:,1));
NumIter = r(1); %iterations
timestep= 0.1; %time step
mu=0.1/timestep;% level set regularization term, please refer to "Chunming Li and et al. Level Set Evolution Without Re-initialization: A New Variational Formulation, CVPR 2005"
sigma = r(2);%size of kernel
epsilon = 1;
c0 = 2; % the constant value
lambda1=1.05;%outer weight, please refer to "Chunming Li and et al, Minimization of Region-Scalable Fitting Energy for Image Segmentation, IEEE Trans. Image Processing, vol. 17 (10), pp. 1940-1949, 2008"
lambda2=1.0;%inner weight
%if lambda1>lambda2; tend to inflate
%if lambda1<lambda2; tend to deflate
nu = 0.001*255*255;%length term
alf = r(4);%data term weight
This is a strange code. Why do you convert the cell string us to a matrix at first and try to convert it into a number by str2num? What do you expect as number output for the char vector 'Iterations:'? I assume, that:
t = cell2mat(us);
e = str2num(t);
is orphaned and should be deleted.
What is J ? The rest of the code does not contain the failing call to contour, so what is the relation to the question?

Accedi per commentare.

Risposte (0)

Commentato:

Jan
il 31 Gen 2019

Community Treasure Hunt

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

Start Hunting!

Translated by