paper 57 :颜色直方图的代码
clc
close all
Image = imread('29.jpg');
[M,N,O] = size(Image);
[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) = 1;
end
if s(i,j)<=0.4&&s(i,j)>0.15
S(i,j) = 2;
end
if s(i,j)<=0.75&&s(i,j)>0.4
S(i,j) = 3;
end
if s(i,j)<=1&&s(i,j)>0.75
S(i,j) = 4;
end
end
end
for i = 1:M
for j = 1:N
if v(i,j)<=0.15&&v(i,j)>0
V(i,j) = 1;
end
if v(i,j)<=0.4&&v(i,j)>0.15
V(i,j) = 2;
end
if v(i,j)<=0.75&&v(i,j)>0.4
V(i,j) = 3;
end
if v(i,j)<=1&&v(i,j)>0.75
V(i,j) = 4;
end
end
end
% 构建4*16二维数组存放H-S数据
Hist = zeros(16,4);
for i = 1:M
for j = 1:N
for k = 1:16
for l = 1:4
if l==S(i,j)&& k==H(i,j)+1
Hist(k,l) = Hist(k,l)+1;
end
end
end
end
end
for k = 1:16
for l =1:4
His((k-1)*4+l) = Hist(k,l);%转化为一维数组
end
end
His = His/sum(His)*1000;
% 手工绘制彩色图像直方图
% hist_h
m=0;
for j = 1:300
if rem(j,16)==1 && m<16
for k = 0:15
for i = 1:200
hist_h(i,j+k) = m;
end
end
m = m+1;
end
end
% hist_s
m=0;
for j = 1:300
if rem(j,4) == 1 && m<64
n = rem(m,4);
for k = 0:3
for i =1:200
hist_s(i,j+k) = n+1;
end
end
m = m+1;
end
end
% hist_v
for j = 1:256
for i = 1:200
hist_v(i,j) = 0.98;
end
end
% 把His赋值给hist_v
for k = 1:64
for j = 1:256
if floor((j-1)/4) == k
for i = 1:200
if i<200-His(k+1)%i>His(k+1)%
hist_v(i,j) = 0;
end
end
end
end
end
% 将h、s、v分量图合并转化为RGB模式
I_H = hsv2rgb(hist_h/16,hist_s/4,hist_v);
% % 画图显示
figure;
subplot(3,2,1),imshow(Image),title('原图');axis on;
subplot(3,2,2),imshow(H,[]),title('H分量图');axis on;
subplot(3,2,3),imshow(S,[]),title('S分量图');axis on;
subplot(3,2,4),imshow(V,[]),title('V分量图');axis on;
subplot(3,2,5),imshow(I_H,[]),title('H-S直方图');axis on;
% subplot(3,2,6),imshow(I_rgb,[]),title('色彩量化后的RGB图像');axis on %I_rgb怎么给出?
%%=======================================
score=average(h);
% score=average(hist_v);
paper 57 :颜色直方图的代码的更多相关文章
- paper 55:图像分割代码汇总
matlab 图像分割算法源码 1.图像反转 MATLAB程序实现如下:I=imread('xian.bmp');J=double(I);J=-J+(256-1); %图像反转线性变换H=uint8( ...
- .net在当前日期的基础上加一天
比如今天是:2015-11-10 18:57:01,在这个基础上加一天,那么就是2015-11-11 18:57:01,代码如下: DateTime now_dt = DateTime.Now; ). ...
- java 13-2 Arrays工具类
1.Arrays:针对数组进行操作的工具类.比如说排序和查找. 1:public static String toString(int[] a) 把数组转成字符串 2:public static v ...
- html5 Canvas API
详细内容请点击 1.HTML Canvas API有两方面优势可以弥补:首先,不需要将所绘制图像中的每个图元当做对象存储,因此执行性能非常好:其次,在其他编程语言现有的优秀二维绘图API的基础上实现C ...
- (转).net程序员转战android第三篇---登录模块之静态登录
这一篇我将分2个部分记录登录界面,第一部分是静态登录, 这部分将如何从界面布局.控件使用.文件关系.数据验证.登陆实现等5小块记录. 第二部分是动态登录,这块会基于上面的4小块,在数据验证不是静态数据 ...
- Java入门基础总结(二)
判断语句 if else 如下: 1 /* 2 语法: 3 if(条件) 4 { 5 ...
- sed正则表达式
sed的正则匹配如何实现非贪婪? sed的正则用的是BREs/EREs,不支持非贪婪模式.当然有一些方法可以实现非贪婪,比如: $ echo abcOabcdOabc | sed 's/.*O//' ...
- Linux正则表达式grep与egrep
grep -io "http:/=[A-Z0-9]\{16\}" ./wsxf.txt >wsxf_urls.txt Linux正则表达式grep与egrep 正则表达式:它 ...
- Android开发新手教程--Android应用程序结构
一.新HelloWorld工程: 1.打开Eclipse.点击"File"->"New"->"Project"-Android ...
随机推荐
- xcode8继续愉快的使用插件
https://github.com/inket/update_xcode_plugins https://github.com/fpg1503/MakeXcodeGr8Again xcode8增加了 ...
- 【Android测试】【随笔】获得App的包名和启动页Activity
◆版权声明:本文出自胖喵~的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/5157308.html 前言 经常看到一些刚刚接触Andro ...
- C code 字符串与整数的相互转化
#include<stdio.h> int str_to_int(const char *str,int *num); void int_to_str(char str[],const i ...
- 执行动态sql返回参数
ref: https://support.microsoft.com/en-us/kb/262499 ) ) DECLARE @IntVariable INT ) SET @SQLString = N ...
- gridcontrol中使用右健菜单popupMenu1
private void gridView1_ShowGridMenu(object sender, DevExpress.XtraGrid.Views.Grid.GridMenuEventArgs ...
- Gulp自动化工具之图片压缩
一.安装node https://nodejs.org/download/ 根据需要选择对应的版本 安装好了之后可以通过node -v参看一下版本 node -v 二.安装gulp npm insta ...
- mac下安装使用svn
mac自带了svn服务端和客户端,所以只需要简单配置一下就可以使用 转自 http://blog.sina.com.cn/s/blog_677fb16e01011i6l.html 1.创建svn ...
- mysql tinyint smallint mediumint int bigint
类型 存储所占空间 (无论显示多少位) (单位 字节/bytes) 存储数据范围 最大显示长度 tinyint 1 -128 ~ 127 signed 0 ...
- How to read the HTML DTD
Contents How to read the HTML DTD 1. DTD Comments 2. Parameter Entity definitions 3. Element declara ...
- WPF基础知识、界面布局及控件Binding
WPF是和WinForm对应的,而其核心是数据驱动事件,在开发中显示的是UI界面和逻辑关系相分离的一种开放语言.UI界面是在XAML语言环境下开发人员可以进行一些自主设计的前台界面,逻辑关系还是基于c ...