在matlab中对hsv进行均匀量化和非均匀量化
MATLAB 进行 量化 均匀
2023-09-11 14:17:15 时间
首先,进行非均匀量化,H,S,V三通道分别量化为16,4,4级,返回一个向量。量化依据如下表:
function vec = getHsvHist(Image) [M,N,O] = size(Image); if O~= 3 error('3 components are needed for histogram'); end [h,s,v] = rgb2hsv(Image); H = h; S = s; V = v; h = h*360; %将hsv空间非等间隔量化: % h量化成16级; % s量化成4级; % v量化成4级; for i = 1:M for j = 1:N if h(i,j)<=15||h(i,j)>345 H(i,j) = 0; end if h(i,j)<=25&&h(i,j)>15 H(i,j) = 1; end if h(i,j)<=45&&h(i,j)>25 H(i,j) = 2; end if h(i,j)<=55&&h(i,j)>45 H(i,j) = 3; end if h(i,j)<=80&&h(i,j)>55 H(i,j) = 4; end if h(i,j)<=108&&h(i,j)>80 H(i,j) = 5; end if h(i,j)<=140&&h(i,j)>108 H(i,j) = 6; end if h(i,j)<=165&&h(i,j)>140 H(i,j) = 7; end if h(i,j)<=190&&h(i,j)>165 H(i,j) = 8; end if h(i,j)<=220&&h(i,j)>190 H(i,j) = 9; end if h(i,j)<=255&&h(i,j)>220 H(i,j) = 10; end if h(i,j)<=275&&h(i,j)>255 H(i,j) = 11; end if h(i,j)<=290&&h(i,j)>275 H(i,j) = 12; end if h(i,j)<=316&&h(i,j)>290 H(i,j) = 13; end if h(i,j)<=330&&h(i,j)>316 H(i,j) = 14; end if h(i,j)<=345&&h(i,j)>330 H(i,j) = 15; end end end for i = 1:M for j = 1:N if s(i,j)<=0.15&&s(i,j)>0 S(i,j) = 0; end if s(i,j)<=0.4&&s(i,j)>0.15 S(i,j) = 1; end if s(i,j)<=0.75&&s(i,j)>0.4 S(i,j) = 2; end if s(i,j)<=1&&s(i,j)>0.75 S(i,j) = 3; end end end for i = 1:M for j = 1:N if v(i,j)<=0.15&&v(i,j)>0 V(i,j) = 0; end if v(i,j)<=0.4&&v(i,j)>0.15 V(i,j) = 1; end if v(i,j)<=0.75&&v(i,j)>0.4 V(i,j) = 2; end if v(i,j)<=1&&v(i,j)>0.75 V(i,j) = 3; end end end %将三个颜色分量合成为一维特征向量:L = H*Qs*Qv+S*Qv+v;Qs,Qv分别是S和V的量化级数, L取值范围[0,255] %取Qs = 4; Qv = 4 L=zeros(M,N); for i = 1:M for j = 1:N L(i,j) = H(i,j)*16+S(i,j)*4+V(i,j); end end %计算L的直方图 Hist=zeros(1,256); for i = 0:255 Hist(i+1) = size(find(L==i),1); end vec=Hist';
接着,进行均匀量化,H,S,V三通道分别量化为16,4,4级,返回一个向量。
function vec= hsvHist(Image) [M,N,O] = size(Image); if O~= 3 error('3 components are needed for histogram'); end H_BITS = 4; S_BITS =2; V_BITS = 2; hsv = uint8(255*rgb2hsv(Image)); %均匀量化 % bitshift(24,-3) 表示24除以2的3次方 H=bitshift(hsv(:,:,1),-(8-H_BITS)); S=bitshift(hsv(:,:,2),-(8-S_BITS)); V=bitshift(hsv(:,:,3),-(8-V_BITS)); %% %先进行合成,然后再统计 L=zeros(M,N); for i=1:M for j=1:N L(i,j)=16*H(i,j)+4*S(i,j)+V(i,j); end end %计算L的直方图 Hist=zeros(1,256); for i = 0:255 Hist(i+1) = size(find(L==i),1); end vec=Hist'; end
以lena图像进行比较:
clc;clear;close all; rgb=imread('d:/pic/lena.jpg'); h1=getHsvHist(rgb); h2=hsvHist(rgb); figure, subplot(211),bar(h1),title('hsv非均匀量化直方图'); subplot(212),bar(h2),title('hsv均匀量化直方图');
相关文章
- matlab 使用OPENCV
- MATLAB文本文件操作总结
- MATLAB学习笔记 对椒盐噪声进行中值滤波
- 数学建模暑期集训10:拟合/matlab工具箱Curve Fitting Tool的使用
- Matlab之Kalman:用线性系统状态方程,通过系统输入输出观测数据,对系统状态进行最优估计的算法
- 【智能优化算法】NSGA-III优化算法算法(Matlab代码实现)
- 【风电预测】考虑预测误差不确定性的风电预测研究(matlab代码实现)
- 基于有序模式的度量对多变量时间序列进行非线性分析(Matlab代码实现)
- 基于离散、连续、线性和非线性模型进行模型预测(MPC)控制(Matlab代码实现)
- 基于时空RBF-NN进行非线性系统识别(Matlab代码实现)
- 使用BP神经网络进行短期负荷预测回归(Matlab实现)
- 基于双向LSTM模型进行电力需求预测(Matlab代码实现)
- 使用星凸随机超曲面模型对扩展对象和分组目标进行形状跟踪(Matlab代码实现)
- 【无人机】四轴无人机的轨迹进行可视化和动画处理(Matlab代码实现)
- 模拟不同MIMO-OFDM方案的MATLAB代码(Matlab代码实现)
- OFDM图像传输系统matlab仿真,以图片作为数据源进行发送,接收端还原图片,对比MPSK,MQAM等调制方式
- MATLAB学习笔记(七)——MATLAB解方程与函数极值
- 【状态估计】基于LMS类自适应滤波算法、NLMS 和 LMF 进行系统识别比较研究(Matlab代码实现)
- 使用 PMU(相量测量单元)进行电力系统状态估计(Matlab代码实现)
- 【数据分析】大型ADCP数据集的处理和分析(Matlab代码实现)
- m分别使用Dijkstra算法和Astar算法进行刚体机器人最短路径搜索和避障算法的matlab仿真,带GUI界面
- Matlab使用笔记(七):将PreScan连接MATLAB实现仿真 (附录:自动无人驾驶仿真软件PreScan的应用介绍)