基于PCNN的图像增强matlab代码

function grayenhancement
%名称:PCNN灰度图像增强
%功能:对图像进行增强处理,使之轮廓、纹理清楚,细节清晰
%%
clc
close all
%%
[filename,pathname]=uigetfile('*.*','选择要处理的图片');
I=im2double(imread(fullfile(pathname,filename)));  
figure,imshow(I);
title('原始图像');
if size(I,3)==3
    I=rgb2gray(I);
end
I=double(I);
figure,imshow(I);
title('灰度图像');
I=I/255;%转化为[0,1]之间处理
%%
[p,q]=size(I);
%初始化相关参数
alpha_L=0.06931;
alpha_Theta=0.05;
beta=0.2;
vL=1.00;
vTheta=200;%连接幅度因子
np=700000;%阈值幅度因子
%初始化所有用到的矩阵
EnhImage=zeros(p,q);
L=zeros(p,q);
U=zeros(p,q);
Y=zeros(p,q);
Y0=zeros(p,q);
%突触联接权系数矩阵W
W=[0.1091 0.1409 0.1091;...
    0.1409 0 0.1409;...
    0.1091 0.1409 0.1091];
%实现PCNN图像增强
Bri=max(I(:));%灰度图像中最亮的像素的灰度值
La=[-1 -1 -1;-1 8 -1;-1 -1 -1];%;拉普拉斯算子
Theta=Bri-conv2(I,La,'same');
F=I;
for n=1:np
    K=conv2(Y,W,'same');
    L=exp(-alpha_L)*L+vL*K;
    Theta=exp(-alpha_Theta)*Theta+vTheta*Y;
    U=F.*(1+beta*L);
    Y=im2double(U>Theta);
    EnhImage=(log(Bri)-(n-1)*alpha_Theta).*Y;
    Y0=Y0+EnhImage;
    if any(Y(:))==0
        fprintf('第%d次迭代后没有火点了.\n',n);
        break;
    end    
end

%格式转换
image=Data_Normalized(Y0,0);
figure,imshow(image);
title('增强图像')

image1=Data_Normalized(Y0,1);
figure,imshow(image1);
title('反方式增强图像')

imwrite(image,strcat(filename,'_grayenhance.bmp'));
end

function Y_Normalized=Data_Normalized(Y,method)
%将Y的元素线性标准化到[0,1]之间
%可以有两种方式:1.min-0,max-1;2.min-1,max-0,因为Y的值一般都为负,不知其意义是值越大效果越大还是绝对值越大效果越大
%应该为第一种,但第二种效果也挺好看,因为HSI模型中I反映的是亮度,与颜色无关
if nargin==1
    method=0;
end

Y_min=min(min(Y));
Y_max=max(max(Y));
if method==0
    Y_Normalized=(Y-Y_min)/(Y_max-Y_min);
else
    Y_Normalized=(Y-Y_max)/(Y_min-Y_max);
end
end
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值