⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rgb-hsi.m

📁 在matlab中实现从rgb到hsi色彩模式的转换
💻 M
字号:
clc;
close all;
clear all;

[O,map]=imread('model.jpg','jpg');
imshow(O),colormap(map);title('original image');

rgb_r=O(:,:,1);
rgb_g=O(:,:,2);
rgb_b=O(:,:,3);
[M,N]=size(rgb_r);
hsi=zeros(M,N,3);
hsi_h=hsi(:,:,1);
hsi_s=hsi(:,:,2);
hsi_i=hsi(:,:,3);
for i=1:M
    for j=1:N
        R=double(rgb_r(i,j));G=double(rgb_g(i,j));B=double(rgb_b(i,j));
        min=R;
        if(G<min)
          min=G;
        end
        if(B<min)
          min=B;
        end
        I=(R+G+B)/3;
        S=1-min/I; 
        if(S==0)
          H=0;
        else
        H=acos(((R-G)+(R-B))/(2*sqrt((R-G)*(R-G)+(R-B)*(G-B))));
        if(B>G)
          H=2*pi-H;
        end
        end
        hsi_h(i,j)=H;
        hsi_s(i,j)=S;
        hsi_i(i,j)=I/255;
end
end
hsi(:,:,1)=hsi_h;
hsi(:,:,2)=hsi_s;
hsi(:,:,3)=hsi_i;
figure;
imshow(hsi);title('HSI image');colormap(map);
figure;
imshow(hsi_h),colormap(gray);title('image with Hue as the gray scale');
figure;
imshow(hsi_s),colormap(gray);title('image with Saturation as the gray scale');
figure;
imshow(hsi_i),colormap(gray);title('image with Intensity as the gray scale');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -