资源简介
基于颜色的图像检索系统
matlab源代码
直方图
欧氏距离
代码片段和文件信息
close all;
clear all;
clc;
[FileNamePathName] = uigetfile(‘*.*‘);%弹出对话框得到打开的路径
Image=imread(strcat(PathNameFileName));%打开得到的路径下的文件
[MNO] = size(Image);
[hsv] = rgb2hsv(Image);
H = h; S = s; V = v;
h = h*360;
%将hsv空间非等间隔量化:
% h量化成8级;
% s量化成3级;
% v量化成3级;
for i = 1:M
for j = 1:N
if h(ij)<=20||h(ij)>315
H(ij) = 0;
end
if h(ij)<=40&&h(ij)>20
H(ij) = 1;
end
if h(ij)<=75&&h(ij)>40
H(ij) = 2;
end
if h(ij)<=155&&h(ij)>75
H(ij) = 3;
end
if h(ij)<=190&&h(ij)>155
H(ij) = 4;
end
if h(ij)<=270&&h(ij)>190
H(ij) = 5;
end
if h(ij)<=295&&h(ij)>270
H(ij) = 6;
end
if h(ij)<=315&&h(ij)>295
H(ij) = 7;
end
end
end
for i = 1:M
for j = 1:N
if s(ij)<=0.2&&s(ij)>0
S(ij) = 0;
end
if s(ij)<=0.7&&s(ij)>0.2
S(ij) = 1;
end
if s(ij)<=1&&s(ij)>0.7
S(ij) = 2;
end
end
end
for i = 1:M
for j = 1:N
if v(ij)<=0.2&&v(ij)>0
V(ij) = 0;
end
if v(ij)<=0.7&&v(ij)>0.2
V(ij) = 1;
end
if v(ij)<=1&&v(ij)>0.7
V(ij) = 2;
end
end
end
%将三个颜色分量合成为一维特征向量:L = H*Qs*Qv+S*Qv+V;QsQv分别是 S和V的量化级数 L取值范围[071]
%取Qs = 3; Qv = 3
for i = 1:M
for j = 1:N
L(ij) = H(ij)*9+S(ij)*3+V(ij);
end
end
%计算L的直方图
for i = 0:71
Hist(i+1) = size(find(L==i)1);
end
T0=Hist;
% 循环读入图像
A=dir(‘D:\graduate design\test_pictures\*.jpg‘);
for k=1:size(A)
B=strcat(‘D:\graduate design\test_pictures\‘A(k).name);
Image=imread(B);
[MNO] = size(Image);
% 计算每一幅图像的颜色直方图
[hsv] = rgb2hsv(Image);
H = h; S = s; V = v;
h = h*360;
%将hsv空间非等间隔量化:
% h量化成8级;
% s量化成3级;
% v量化成3级;
for i = 1:M
for j = 1:N
- 上一篇:SPWM仿真模型
- 下一篇:ID3算法MATLAB实现,机器学习作业
评论
共有 条评论