matlab hsi图像分割,提取图像的HSI图像分量
function [] = rgbHsi()
f = imread('C:\Users\GM\Desktop\LBJ.jpg');
R = f(:,:,1);
G = f(:,:,2);
B = f(:,:,3);
%將圖像數(shù)據(jù)轉(zhuǎn)換為double類型
Rs = double(R(1:end,1:end)) ;
Gs = double(G(1:end,1:end));
Bs = double(B(1:end,1:end));
%這里用到了量化
%各個分量取1/3后會出現(xiàn)非整數(shù)的情況
%因此要用fix函數(shù)取整
I = fix((1/3)*(Rs + Bs + Gs));
%取整后將數(shù)據(jù)轉(zhuǎn)換為圖像類型uint8
I = uint8(I);
figure,imshow(I)
title('HSI中的I')
%求取HSI中的S
tempMin = [];
%取得圖像大小
[sizeOfImageM,sizeOfImageN] = size(I);
%得到三個分量矩陣中由最小元素組成的矩陣
for i = 1:sizeOfImageM
for j =
1:sizeOfImageN
tempMin(i,j) = R(i,j);
if tempMin(i,j)>G(i,j)
tempMin(i,j) = G(i,j);
if
tempMin(i,j)>B(i,j)
tempMin(i,j) =
B(i,j);
end
end
end
end
%定義一通臨時變量
t = []
divArray = []
divArray2 = []
tempMin = 3*tempMin;
t = Rs + Gs + Bs;
%定義圖像中像素點間的觸發(fā)
for i = 1:sizeOfImageM
for j =
1:sizeOfImageN
divArray(i,j) =
tempMin(i,j)/t(i,j);
end
end
S = 1 - divArray;
%將數(shù)據(jù)轉(zhuǎn)換為圖像的類型uint8
S = uint8(S)*255;
figure,imshow(S)
title('HSI中的S')
%求取H
%定義一通臨時變量
tt = []
tt2 = []
tt3 = []
tt = Rs - Gs;
tt2 = Rs - Bs;
tt3 = Gs - Bs;
rMinusG = ((Rs - Gs) + (Rs - Bs))/2;
tempNum = []
tempNum = tt*tt + tt2*tt3;
rAddG = sqrt(tempNum);
%自定義圖像除法
for i = 1:sizeOfImageM
for j =
1:sizeOfImageN
divArray2(i,j) =
rMinusG(i,j)/rAddG(i,j);
end
end
H = acos(divArray2)/pi;
figure,imshow(H)
title('HSI中的H')
end
總結(jié)
以上是生活随笔為你收集整理的matlab hsi图像分割,提取图像的HSI图像分量的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php程序yii是什么意思,Yii框架啥
- 下一篇: matlab微分的语句格式,偏微分差分四