目錄
一、理論基礎
二、核心程式
三、仿真測試結果
作者ID :fpga和matlab
擅長技術:
1.無線基帶,無線圖傳,編解碼
2.機器視覺,圖像處理,三維重建
3.人工智能,深度學習
4.智能控制,智能優化
5.其他
一、理論基礎
第一步:圖像預處理。濾波,光照不均勻處理等等。
一般對于光澤處理我們采用同态濾波的方法來實作,這裡圖像預處理主要就是光照不均勻的處理。現實中我們得到的圖檔,其動态範圍很大,而我們感興趣的部分的灰階又很暗,圖像細節沒有辦法辨認,采用一般的灰階級線性變換法是不行的。圖像的同态濾波屬于圖像頻率域處理範疇,其作用是對圖像灰階範圍進行調整,通過消除圖像上照明不均的問題,增強暗區的圖像細節,同時又不損失亮區的圖像細節.分辨不清的圖像用同态濾波器處理後,圖像畫面亮度比較均勻,細節得以增強。
第二步:去本底。提取紅色液體,排除背景的影響。建議:從色度方面考慮,色度的原理大緻要說明。
這裡我們采用HSV提取色度。其代碼更為簡單。
phsv = rgb2hsv(I1);
ph = phsv(:,:,1); % 取H分量
ps = phsv(:,:,2); % 取S分量
pv = phsv(:,:,3); % 取V分量
%=====================================================================
figure;
subplot(221);subimage(I1); colorbar; %顯示原rgb圖像
Xlabel('(a) rgb圖像','FontSize',14,'FontName','隸書','color','b');
subplot(222);subimage(ph); colorbar; %顯示色調分量圖像
Xlabel('(b) 色調分量圖像','FontSize',14,'FontName','隸書','color','b');
subplot(223);subimage(ps); colorbar; %顯示飽和度分量圖像
Xlabel('(c) 飽和度分量圖像','FontSize',14,'FontName','隸書','color','b');
subplot(224);subimage(pv); colorbar; %顯示亮度分量圖像
Xlabel('(d) 亮度分量圖像','FontSize',14,'FontName','隸書','color','b');
第三步:等濃度線圖,填充顔色,根據等濃度線得出我給的EZ,EY值,用相同情況下的圖檔驗證EZ,EY值的正确性。
二、核心程式
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
[R,C,K]= size(I);
if R == 1080
R2 = 900;
end
if R < 1080
R2 = R;
end
step = 5;%大的圖檔設定為5;
%第一步
%第一步
%第一步:圖像預處理。濾波,光照不均勻處理等等。(用均值和中值濾波之外的方法,
% 至少兩種濾波方法和兩種光照不均勻處理的方法)。
%采用同态濾波
I1=tongtai(I,1,0.4,R2,C);
% pause(2)%暫停3秒鐘後關閉第一步的處理圖檔;
% close all;
% % 順序統計濾波
% Ri=I(:,:,1);
% Gi=I(:,:,2);
% Bi=I(:,:,3);
%
% Rpstatistic=mystatistic(Ri);
% Gpstatistic=mystatistic(Gi);
% Bpstatistic=mystatistic(Bi);
%
% I1(:,:,1)=Rpstatistic(:,:);
% I1(:,:,2)=Gpstatistic(:,:);
% I1(:,:,3)=Bpstatistic(:,:);
% imshow(I1)
%第二步
%第二步
%第二步:去本底。提取紅色液體,排除背景的影響。
%通過對比,可以看到G圖像對應的液體的視覺效果比較明顯,是以我們通過對G圖像進行處理得到液體的範圍;
%這裡有兩種方法供使用,我們采用的是HSV法。
%這裡有兩種方法供使用,我們采用的是HSV法。
%這裡有兩種方法供使用,我們采用的是HSV法。
%第一種方法,采用的是腐蝕的方法提起圖檔;
% % % I2=im2double(I1);%将A轉換成double型
% % % R=I2(:,:,1);
% % % G=I2(:,:,2);
% % % B=I2(:,:,3);
% % % fuzhuo(I1,G);
%==========================================================================
%第二種方法是采用HSV提取液體所在的圖檔
phsv = rgb2hsv(I1);
ph = phsv(:,:,1); % 取H分量
ps = phsv(:,:,2); % 取S分量
pv = phsv(:,:,3); % 取V分量
%==========================================================================
figure;
subplot(221);subimage(I1); colorbar; %顯示原rgb圖像
Xlabel('(a) rgb圖像','FontSize',14,'FontName','隸書','color','b');
subplot(222);subimage(ph); colorbar; %顯示色調分量圖像
Xlabel('(b) 色調分量圖像','FontSize',14,'FontName','隸書','color','b');
subplot(223);subimage(ps); colorbar; %顯示飽和度分量圖像
Xlabel('(c) 飽和度分量圖像','FontSize',14,'FontName','隸書','color','b');
subplot(224);subimage(pv); colorbar; %顯示亮度分量圖像
Xlabel('(d) 亮度分量圖像','FontSize',14,'FontName','隸書','color','b');
%液體的提取
%途中白色部分為液體的濃度變化
for i = 1:R2
for j = 1:C
if ps(i,j)<0.4
ps_tmp(i,j) = 0;
end
if ps(i,j)>0.4
ps_tmp(i,j) = ps(i,j);
end
end
end
figure
imshow(ps_tmp)
for i = 1:R2
for j = 1:C
ps_tmp2(i,j) = ps_tmp(i,j);
end
end
figure
imshow(ps_tmp2)
p1 = fushi2(ps_tmp2);%液體的濃度變換灰階圖的腐蝕處理
% pause(2)%暫停3秒鐘後關閉第一步的處理圖檔;
% close all;
% 第三步:等濃度線
% 第三步:等濃度線
% 第三步:等濃度線
for i = 1:R2
for j = 1:C
if p1(i,j)>0
if p1(i,j)<=0.2
nongdu(i,j,1) = 0;
nongdu(i,j,2) = 0;
nongdu(i,j,3) = 0;
end
end
if p1(i,j)>0.2
if p1(i,j)<=0.4
nongdu(i,j,1) = 255;
nongdu(i,j,2) = 255;
nongdu(i,j,3) = 0;
end
end
if p1(i,j)>0.4
if p1(i,j)<=0.6
nongdu(i,j,1) = 255;
nongdu(i,j,2) = 0;
nongdu(i,j,3) = 0;
end
end
if p1(i,j)>0.6
if p1(i,j)<=0.8
nongdu(i,j,1) = 0;
nongdu(i,j,2) = 0;
nongdu(i,j,3) = 255;
end
end
if p1(i,j)>0.8
if p1(i,j)<=1
nongdu(i,j,1) = 0;
nongdu(i,j,2) = 255;
nongdu(i,j,3) = 0;
end
end
if p1(i,j)==0
nongdu(i,j,1) = 0;
nongdu(i,j,2) = 0;
nongdu(i,j,3) = 0;
end
end
end
figure;
imshow(nongdu);
%第四步:梯度處理。
%第四步:梯度處理。
%第四步:梯度處理。
[Gx,Gy]=gradient(ps_tmp2); % 計算梯度
figure,imshow(Gx);
figure,imshow(Gy);
% G=sqrt(Gx.*Gx+Gy.*Gy); % 注意是矩陣點乘
% J1=G;
% figure,imshow(J1,map); % 第一種圖像增強
%為了節約計算速率,這裡每5個點計算一次
u = 1:step:R2;
v = 1:step:C;
for i=1:R2
for j=1:C
Gx2(i,j)=Gx(R2+1-i,j);
Gy2(i,j)=Gy(R2+1-i,j);
end
end
for i=1:R2
for j=1:C
ps_tmp22(i,j)=ps_tmp2(R2+1-i,j);
end
end
figure;quiver ( v,u,Gx2(1:step:R2,1:step:C),Gy2(1:step:R2,1:step:C) );
figure;contour( v,u,ps_tmp22(1:step:R2,1:step:C) );
u = 1:step:R2;
v = 1:step:C;
figure;contour( v,u,ps_tmp22(1:step:R2,1:step:C) );hold on;
quiver ( v,u,Gx2(1:step:R2,1:step:C),Gy2(1:step:R2,1:step:C) );
% pause(3)%暫停3秒鐘後關閉第一步的處理圖檔;
% close all;
%第五步:旋度圖。
[u v] = meshgrid(1:step:C,1:step:R2);
cav = curl(ps_tmp2(1:step:R2,1:step:C),v);
for i=1:R2/step
for j=1:C/step
cav2(i,j)=cav(R2/step-i+1,j);
end
end
figure;contour(v,u,cav2);
pcolor(u,v,cav2); shading interp;
colormap copper;
% hold on;
% quiver(ps_tmp2,ps_tmp2,u,v,'y');
%第六步:散度圖。
figure
k=curvature_central(ps_tmp2);
imshow(k);
u = 1:step:R2;
v = 1:step:C;
for i=1:R2
for j=1:C
k2(i,j)=k(R2+1-i,j);
end
end
% figure;quiver ( v,u,Gx(1:5:900,2:5:1515),Gy(1:5:900,2:5:1515) );
figure;contour( v,u,k2(1:step:R2,1:step:C) );
.............................................................................