matlab绘制HSI颜色空间,matlab绘制hsi颜色空间,matlab绘制HSI颜色空间,matlab绘制hsi颜色空间,
方法
使用RGB,然后转换成HSI
代码如下:
R = [ 120 20 30;
170 20 70;
120 140 70];
G = [ 40 150 20;
20 110 20;
25 20 20];
B = [20 60 150;
190 20 250;
20 30 40];
rgb = uint8(cat(3,R,G,B));
hsi = rgb2hsi(rgb);
hsl = rgb2hsl(rgb);
hsv = rgb2hsv(rgb);
% 感兴趣的向量
hsi(1,:,2)
直接可以根据转换公式,将RGB图像转换为HSI图像,代码如下
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%功能:绘制图像RGB与HSI颜色空间
%环境:Win7,Matlab2015b
%Modi: C.S
%时间:2022-05-09
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all;
clear all
clc
tic
[filename,pathname]=uigetfile('*.jpg;*.png;*.bmp','select the file');
im=[pathname,filename];
%% RGB
I=imread(im);
figure(1);imshow(I);%显示原始彩色图像
title('原始图像');
r = I(:,:,1); %通道R
g = I(:,:,2); %通道G
b = I(:,:,3); %通道B
figure(2);subplot(131);imshow(r);title('R');
subplot(132);imshow(g);title('G');
subplot(133);imshow(b);title('B');
%% HSI颜色空间
iHsi=rgb2hsi(I);
hsi_H=iHsi(:,:,1); %色调
hsi_S=iHsi(:,:,2); %饱和度
hsi_I=iHsi(:,:,3); %亮度
figure(2);subplot(131);imshow(hsi_H);title('H(色调)');
subplot(132);imshow(hsi_S);title('S(饱和度)');
subplot(133);imshow(hsi_I);title('I(亮度)');
function [hsi] = rgb2hsi(rgb)
%UNTITLED3 此处显示有关此函数的摘要
% 此处显示详细说明
rgb=im2double(rgb);
r=rgb(:,:,1);
g=rgb(:,:,2);
b=rgb(:,:,3);
% H 单位弧度
num=0.5*((r-g)+(r-b));
den=sqrt( (r-g).^2 + (r-b).*(g-b) );
theta=acos(num./(den+eps)); %分母+eps防止为0 acos得到的是弧度
H0=theta.*(g>=b); %G>=B
H1=(2*pi-theta).*(g<b); %G<B
H=H0+H1;
% %转成角度
% H=H.*360./(2*pi);
% S
num=3.*min(min(r,g),b);
S=1-num./(r+g+b+eps);
% I
I=(r+g+b)/3;
H=(H-min(min(H)))./(max(max(H))-min(min(H)));
S=(S-min(min(S)))./(max(max(S))-min(min(S)));
hsi=cat(3,H,S,I);
end
运行结果
有解决的话,希望可以采纳
clear;clc;
h-linspace(0,1,31);
s linspace(0,1 ,9);
v=linspace(0,1,11);
h=h([1:end 5])*2 *pi;
[H,S]=meshgrid(h,s);
surf(S. cos(H),S. sin(H),H H+ 1 ,hsv2rgb(cat(3,H/2 pi,S,H H+1)));
hold on
[H,V]=meshgrid(h,v);
surf(V." cos(H),V. sin(H),V ,hsv2rgb(cat(3,H/2 pi,H-H+1,V));
[S,V]=meshgrid(s,v);
surf(S. °V. cos(h(1)),S. *V. sin(h(1)),V ,hsv2rgb(cat(3,S S+h(1)/2 /pi,S,V));
surf(S.*V. cos(h(end),S. *V. sin(h(end)),V hsv2rgb(cat(3,S S+h(end)/2/pi,S,V));
shading flat;axis off equal
view(60,1 5);camzoom(2);
在MATLAB中建模HSV颜色空间
https://qa.1r1g.com/sf/ask/233778471/