matlab 程序解释 急需

求助~!!急 程序解释
下面是用水平集算法的图像分割程序,哪位高手帮忙大概解释一下 特别是图像显示的那一块(红色字体的是在调用evolution.m)急用~~

Img = imread('t11.jpg'); % The same cell image in the paper is used here
Img=double(Img(:,:,1));
sigma=1.5; % scale parameter in Gaussian kernel for smoothing.
G=fspecial('gaussian',15,sigma);
Img_smooth=conv2(Img,G,'same'); % smooth image by Gaussiin convolution
[Ix,Iy]=gradient(Img_smooth);
f=Ix.^2+Iy.^2;
g=1./(1+f); % edge indicator function.
epsilon=1.5; % the papramater in the definition of smoothed Dirac function
timestep=5; % time step, try timestep=10, 20, ..., 50, ...
mu=0.2/timestep; % coefficient of the internal (penalizing) energy term P(\phi)
% Note: the product timestep*mu must be less than 0.25 for stability!
lambda=5; % coefficient of the weighted length term Lg(\phi)
alf=1.5; % coefficient of the weighted area term Ag(\phi);
% Note: Choose a positive(negative) alf if the initial contour is outside(inside) the object.

[nrow, ncol]=size(Img);
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
text(6,6,'Left click to get points, right click to get end point','FontSize',[12],'Color', 'r');
% Click mouse to specify initial contour/region
BW = roipoly; % get a region R inside a polygon, BW is a binary image with 1 and 0 inside or outside the polygon;
c0=4; % the constant value used to define binary level set function;
initialLSF= c0*2*(0.5-BW); % initial level set function: -c0 inside R, c0 outside R;
u=initialLSF;
[c,h] = contour(u,[0 0],'r');
u=initialLSF;
figure;imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
title('Initial contour');
% start level set evolution
for n=1:300
u=EVOLUTION(u, g ,lambda, mu, alf, epsilon, timestep, 1);
if mod(n,20)==0
pause(0.001);
imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
iterNum=[num2str(n), ' iterations'];
title(iterNum);
hold off;
end
end
close ('figure 1')
close ('figure 2')
axes(handles.fgh);
imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
totalIterNum=[num2str(n), ' iterations'];
我是超级菜鸟

第1个回答  2013-09-23
在这里:
function u = EVOLUTION(u0, g, lambda, mu, alf, epsilon, delt, numIter)
% EVOLUTION(u0, g, lambda, mu, alf, epsilon, delt, numIter) updates the level set function
% according to the level set evolution equation in Chunming Li et al's paper:
% "Level Set Evolution Without Reinitialization: A New Variational Formulation"
% in Proceedings CVPR'2005,
% Usage:
% u0: level set function to be updated
% g: edge indicator function
% lambda: coefficient of the weighted length term L(\phi)
% mu: coefficient of the internal (penalizing) energy term P(\phi)
% alf: coefficient of the weighted area term A(\phi), choose smaller alf
% epsilon: the papramater in the definition of smooth Dirac function, default value 1.5
% delt: time step of iteration, see the paper for the selection of time step and mu
% numIter: number of iterations.
%

u=u0;
[vx,vy]=gradient(g);

for k=1:numIter
u=NeumannBoundCond(u);
[ux,uy]=gradient(u);
normDu=sqrt(ux.^2 + uy.^2 + 1e-10);
Nx=ux./normDu;
Ny=uy./normDu;
diracU=Dirac(u,epsilon);
K=curvature_central(Nx,Ny);
weightedLengthTerm=lambda*diracU.*(vx.*Nx + vy.*Ny + g.*K);
penalizingTerm=mu*(4*del2(u)-K);
weightedAreaTerm=alf.*diracU.*g;
u=u+delt*(weightedLengthTerm + weightedAreaTerm + penalizingTerm); % update the level set function
end

% the following functions are called by the main function EVOLUTION
function f = Dirac(x, sigma) %水平集狄拉克计算
f=(1/2/sigma)*(1+cos(pi*x/sigma));
b = (x<=sigma) & (x>=-sigma);
f = f.*b;

function K = curvature_central(nx,ny); %曲率中心
[nxx,junk]=gradient(nx);
[junk,nyy]=gradient(ny);
K=nxx+nyy;

function g = NeumannBoundCond(f)
% Make a function satisfy Neumann boundary condition
[nrow,ncol] = size(f);
g = f;
g([1 nrow],[1 ncol]) = g([3 nrow-2],[3 ncol-2]);
g([1 nrow],2:end-1) = g([3 nrow-2],2:end-1);
g(2:end-1,[1 ncol]) = g(2:end-1,[3 ncol-2]);
第2个回答  2009-07-03
d
第3个回答  2012-05-28
楼主现在会了没?我也急用啊

询问matlab一个程序的各个语句什么意思,求讲解。急……
1,模拟噪声信号。在程序里 xr 为初始信号,b 为噪声,x 即为叠加噪声的信号 (这个程序里只有加性噪声,其他情况下有时还可能有乘性噪声,可随机应变),x也即为之后滤波的输入信号 (维度均为200)这是第一个for循环做的事情,之后再初始化各个矩阵、向量就不用多说了。2,滤波。滤波的基本思想...

急求matlab程序注释和指导
先把function PQ=paddedsize(AB,CD,PARAM)存成paddedsize.m文件 f=imread('lena.gif'); 以下是主函数 (重要)dftuv这个函数没有,它会出错,从程序的作用来看,它应该是一个拿paddedsize函数的输出值来计算高斯滤波器参数H的一个函数 整个这个程序说白了就是先给图像增加噪声,再比较几种滤波(去噪)...

求大神帮忙给这段matlab程序加上注释,跪谢,急求!
f=imread('cameraman.tif'); % 读图f=im2double(f); % 转化为double型数据[r c]=size(f);%设置矩阵的行列数,图的大小h=fspecial('gaussian',[r c],0.5); % 模糊核g=imfilter(f,h,'circular'); % 图像模糊a=0.1;b=0.000000000001;n=a+b*randn(r,c); % 噪声,均值为0.1...

matlab程序解释
n); %获得相应分布密度值plot(x,yd_c,'b'),hold on %画图%绘制分布函数着色部分xxf=0:0.1:x_a; % 0~临界值yyf=chi2pdf(xxf,n);fill([xxf,

好心人帮注释一下这个MATLAB程序吧,最好每句都注释,急急急!万分感谢...
N=length(x); %求x矩阵的长度 Ft=(1:N)*Fs\/N; %求1--N之间的值,步长为1,根据公式求的一组数给Ft X=abs(fft(x)); %傅里叶变换 figure(1); %作第一个图 subplot(2,1,1) %画第二行,第一列,画到第一幅图上 plot(Ft,X); ...

关于MATLAB程序解释
function [Phi, Gamma] = c2d(a, b, t)error(nargchk(3,3,nargin));%检查输入变量的个数,变量个数不能大于3,也不能小于3,否则报错。error(abcdchk(a,b));% 检查a,b,c,d各维空间向量是否前后一致,否则报错。[m,n] = size(a);%a是m行n列的矩阵 [m,nb] = size(b);%b是m...

求人帮我注解一下这段MATLAB程序
function result=QRS(n,q,i,x) %%%%%%%%%%%%%%定义result函数,是n,q,i,x的函数。因此这四个量在数据计算中是给定的量。也就是已知量。r=0;%%%给定初值;for k=i:1:(i+q-1)%%%for循环;sum=0;%%%% 给定sum的初值;for j=1:1:n %%%%for循环 sum=sum+(x(j)-x(k)...

请高手指点下这MATLAB程序的内容并帮忙注释下
length:数组长度(即行数或列数中的较大值)reshape把指定的矩阵改变形状,但是元素个数不变 out是矩阵吧,那么out(i,1)就是其中的某一元素 abs()取某数的绝对值 floor:朝负无穷方向舍入 回答不是很完整,因为我也对MATLAB也只是懂个皮毛,用的时候查资料 告诉一个方法吧,那个函数不会用了,...

matlab的程序,帮看看什么意思
代码的解释(供参考,下列是根据经验大概的判断,如不对请谅解)自定义函数 spacemodel()作用是当flag某值,执行相当于的程序命令 function [sys,x0,str,ts] = spacemodel(t,x,u,flag)switch flag,case 0,[sys,x0,str,ts]=mdlInitializeSizes;case 1,sys=mdlDerivatives(t,x,u);case 3,sy...

matlab程序求注释
function [ITSE] = SS(B)%定义函数名称,输入的是矩阵,在本方程代号是B,输出 [ITSE][H,L]=size(B);%读取矩阵的行列数 for i=1:H %逐行操作 for j=1:L%行内逐个操作 a(j)=B(i,j);end 上面小循环的意思是将第i行写入向量a for k=1:(L+2)if k==1 A(k)=1;elseif k=...

相似回答