基于PCNN的图像增强matlab代码
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                基于PCNN的图像增强matlab代码
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.                        
                                
                            
                            
                            function grayenhancement
%名稱:PCNN灰度圖像增強
%功能:對圖像進行增強處理,使之輪廓、紋理清楚,細節(jié)清晰
%%
clc
close all
%%
[filename,pathname]=uigetfile('*.*','選擇要處理的圖片');
I=im2double(imread(fullfile(pathname,filename)));  
figure,imshow(I);
title('原始圖像');
if size(I,3)==3I=rgb2gray(I);
end
I=double(I);
figure,imshow(I);
title('灰度圖像');
I=I/255;%轉(zhuǎn)化為[0,1]之間處理
%%
[p,q]=size(I);
%初始化相關(guān)參數(shù)
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);
%突觸聯(lián)接權(quán)系數(shù)矩陣W
W=[0.1091 0.1409 0.1091;...0.1409 0 0.1409;...0.1091 0.1409 0.1091];
%實現(xiàn)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:npK=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(:))==0fprintf('第%d次迭代后沒有火點了.\n',n);break;end    
end%格式轉(zhuǎn)換
image=Data_Normalized(Y0,0);
figure,imshow(image);
title('增強圖像')image1=Data_Normalized(Y0,1);
figure,imshow(image1);
title('反方式增強圖像')imwrite(image,strcat(filename,'_grayenhance.bmp'));
endfunction Y_Normalized=Data_Normalized(Y,method)
%將Y的元素線性標準化到[0,1]之間
%可以有兩種方式:1.min-0,max-1;2.min-1,max-0,因為Y的值一般都為負,不知其意義是值越大效果越大還是絕對值越大效果越大
%應(yīng)該為第一種,但第二種效果也挺好看,因為HSI模型中I反映的是亮度,與顏色無關(guān)
if nargin==1method=0;
endY_min=min(min(Y));
Y_max=max(max(Y));
if method==0Y_Normalized=(Y-Y_min)/(Y_max-Y_min);
elseY_Normalized=(Y-Y_max)/(Y_min-Y_max);
end
end
                            
                        
                        
                        總結(jié)
以上是生活随笔為你收集整理的基于PCNN的图像增强matlab代码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 能发邮件的临时邮箱
- 下一篇: 商务邮箱有哪些?常见邮箱对比
