声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1154|回复: 0

[图像处理] 求大神解救啊!!!

[复制链接]
发表于 2012-5-23 13:05 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
求每句语言是意思~
clear all;
close all;
Img = imread('twocells.bmp');  % 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
mu=0.04;  % coefficient of the internal (penalizing) energy term P(\phi)
          % Note: The product timestep*mu must be less than 0.25 for stable evolution

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.


% define initial level set function (LSF) as -c0, c0 at points outside and inside of a region R, respectively.
[nrow, ncol]=size(Img);  
c0=2;    % The constant value used to define binary level set function as initial LSF;
         % Using larger value of c0 usually slow down the evolution.
         
initialLSF=c0*ones(nrow,ncol);
w=8;
initialLSF(w+1:end-w, w+1:end-w)=-c0;  

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:200
    u=EVOLUTION_LSD(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
imagesc(Img, [0, 255]);colormap(gray);hold on;
[c,h] = contour(u,[0 0],'r');
totalIterNum=[num2str(n), ' iterations'];  
title(['Final contour, ', totalIterNum]);

figure;
mesh(u);
title('Final level set function');
回复
分享到:

使用道具 举报

您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-9-30 03:34 , Processed in 0.047385 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表