基于matlab的图像分割

项目说明:使用matlab环境对项目中的lena图片进行分割处理,并显示。

环境:matlab2014a

项目目录展示:

基于matlab的图像分割_第1张图片

运行结果显示:

基于matlab的图像分割_第2张图片 

 项目核心代码展示:

 

II=imread('lena256.tif');
I=chazhi(II);
I =double((1/255)*double(I));    %归一化    
F=double(I);  %计算梯度
[M,N]=size(F);
[diffX,diffY] = gradient(F);

diffX=diffX.*diffX;
diffY=diffY.*diffY;
AVEGRAD=sqrt((diffX+diffY)/2);

g=abs(AVEGRAD); 
w=1;
K=1./exp((g./w)^2);
[Height,Width]=size(I);
sei_ta =(genetic(II)/255)*ones(Height,Width);                    %阈值矩阵
Res = zeros(Height,Width);        %save the result with Res matrix
N = 20;                           %叠代次数
dei_ta = 1/N;                     %阈值调节矩阵
bei_ta = 0.05;                     %神经元连接强度
H =0;
for i = 1:N
    Y = zeros(Height,Width);          %神经元输出矩阵,记录点火状况
    L = zeros(Height,Width);          %图像元素对应神经元 L 通道信号(0,1)
    U = zeros(Height,Width);          %内部状态矩阵,记录调制结果
    Inter = zeros(Height,Width);      %临时距阵,存放中间结果
    Bin = zeros(Height,Width);        %临时距阵,存放中间结果
    L = Y+K;
    TL = heastep(L);
    L = TL;
    j =1;
    while(j>0)
        Inter = Y;
        U = F.*(1+bei_ta*L);
        Y = heastep(U - sei_ta);
        if(Y==Inter)
            Yt = ones(Height,Width);
            Bin = Yt.*Y;
            sei_ta = sei_ta - dei_ta;
 %            Ht=cross_entropy
            Ht=maxinfo(Bin);
%            Ht = crosinfo1(I,Bin,1,256,1,256);
            if(Ht>H)
                H = Ht;
                i
                Res = Bin;
            end
            j = -1;
        else
            L =Y+K;
            TL1 = heastep(L);
            L = TL1;
        end
    end
end
re=Res;
figure(1)
imshow(II)
figure(2)
imshow(I)
figure(3)
imshow(re)

项目下载地址:

https://download.csdn.net/download/mzl_18353516147/85930243

你可能感兴趣的:(其它,matlab,开发语言,图像分割,图像处理)