Why function gradmag isn´t working for me?

5 visualizzazioni (ultimi 30 giorni)
Veronika
Veronika il 29 Mar 2017
Risposto: Cris Luengo il 20 Lug 2018
Dear all,
I have this code:
%addpath('/Applications/MATLAB_R2015b.app/toolbox/dip/common/dipimage')
% dip_initialise
%dipsetpref('imagefilepath','/Applications/MATLAB_R2015b.app/toolbox/dip/images')
%addpath /Applications/MATLAB_R2015b.app/toolbox/dip/common/dipimage/demos
img1 = imread('2_ct_bw150.png');
img = rgb2gray(img1);
x = 350+350*cos(0:0.1:2*pi)';
y = 350+350*sin(0:0.1:2*pi)';
imshow(img1);
hold on
plot([x;x(1)],[y;y(1)],'g')
alpha = 0.001;
beta = 0.9;
gamma = 100;
iterations = 50;
N = length(x);
a = gamma*(2*alpha+6*beta)+1;
b = gamma*(-alpha-4*beta);
c = gamma*beta;
P = diag(repmat(a,1,N));
P = P + diag(repmat(b,1,N-1), 1) + diag( b, -N+1);
P = P + diag(repmat(b,1,N-1),-1) + diag( b, N-1);
P = P + diag(repmat(c,1,N-2), 2) + diag([c,c],-N+2);
P = P + diag(repmat(c,1,N-2),-2) + diag([c,c], N-2);
P = inv(P);
f = gradient(gradmag(img,30));
for ii = 1:iterations
% Calculate external force
coords = [x,y];
fex = get_subpixel(f{1},coords,'linear');
fey = get_subpixel(f{2},coords,'linear');
% Move control points
x = P*(x+gamma*fex);
y = P*(y+gamma*fey);
if mod(ii,5)==0
plot([x;x(1)],[y;y(1)],'b')
end
end
plot([x;x(1)],[y;y(1)],'r')
hold off
for segmentation, but this error appears:
Undefined function or variable 'gradmag'.
Error in ct_snakes (line 32)
f = gradient(gradmag(img,30));
Can you advise me, where is mistake? Thank you for your answers.

Risposte (2)

Richard Zappulla
Richard Zappulla il 30 Mar 2017
gradmag is not standard MATLAB function. If downloaded it from the file exchange or GITHUB, make sure the folder in which it resides is on your path. Chances are, this is the issue causing the error you listed.
For convenience, here is the link to the MATLAB page describing how to add a folder to your path.

Cris Luengo
Cris Luengo il 20 Lug 2018
This code, which you have copied from my blog, requires DIPimage to run. Get it here: http://www.diplib.org/. Make sure you read the installation instructions.

Categorie

Scopri di più su Communications Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by