Ⅰ 請問怎麼得到一幅彩色圖像(.jpg格式)的直方圖
用PHOTOSHOP打開圖像就能得到圖像的直方圖
Ⅱ 請教顯示彩色圖像的RGB直方圖
僅供參考
#include <cv.h>
#include <highgui.h>
#include <iostream>
using namespace std;
int main( int argc, char** argv )
{
IplImage * src;
// char *filename = argc==3?argv[2]: (char*)"1.jpg";
// src = cvLoadImage(filename, 1);
if(argc==2 &&(src = cvLoadImage(argv[1], 1)) != 0)
{
IplImage* rgb_r = cvCreateImage(cvGetSize(src), 8, 1);
IplImage* rgb_g = cvCreateImage(cvGetSize(src), 8, 1);
IplImage* rgb_b = cvCreateImage(cvGetSize(src), 8, 1);
IplImage* planes[] = {rgb_r, rgb_g, rgb_b};
int r_bin = 32, g_bin = 32, b_bin = 32;
int hist_size[] = {r_bin, g_bin, b_bin};
float r_ranges[] = {0, 255};
float g_ranges[] = {0, 255};
float b_ranges[] = {0, 255};
float* ranges[] = {r_ranges, g_ranges, b_ranges};
cvCvtPixToPlane(src, rgb_r, rgb_g, rgb_b, 0);
/* cvNamedWindow( "rgb_r", 0);
cvResizeWindow("rgb_r", 400, 350);
cvShowImage( "rgb_r", rgb_r );
cvNamedWindow( "rgb_b", 0);
cvResizeWindow("rgb_b", 400, 350);
cvShowImage( "rgb_b", rgb_b );
cvNamedWindow( "rgb_g", 0);
cvResizeWindow("rgb_g", 400, 350);
cvShowImage( "rgb_g", rgb_g);
*/
CvHistogram *hist;
hist = cvCreateHist(3, hist_size, CV_HIST_ARRAY, ranges, 1);
cvCalcHist(planes, hist, 0, 0);
float max_value;
cvGetMinMaxHistValue(hist, 0, &max_value, 0, 0);
int height = 260;
int width = (r_bin*g_bin*b_bin*6);
IplImage* hist_img = cvCreateImage(cvGetSize(src), 8, 3);
cvZero(hist_img);
int bin_w = width/(r_bin*g_bin*b_bin);
for(int r_c=0; r_c<r_bin; r_c++)
{
for(int g_c=0; g_c<g_bin; g_c++)
{
for(int b_c=0; b_c<b_bin; b_c++)
{
int i = r_c*g_bin + g_c*b_bin + b_c;
float bin_val = cvQueryHistValue_3D(hist, r_c, g_c, b_c);
int intensity = cvRound(bin_val*height/max_value);
CvScalar color= CV_RGB(r_c*255/r_bin, g_c*255/g_bin, b_c*255/b_bin);
if(intensity > 50)
{
printf("(r_c=%d, g_c=%d, b_c=%d) : (r=%d, g=%d, b=%d) intensity = %d\n", r_c, g_c, b_c,
color.val[2], color.val[1], color.val[0], intensity);
}
cvRectangle(hist_img, cvPoint(i*bin_w, height), cvPoint((i+1)*bin_w, height-intensity),
color, -1, 8, 0);
}
}
}
cvNamedWindow( "Source", 0);
cvResizeWindow("Source", 400, 350);
cvShowImage( "Source", src );
cvNamedWindow( "RGB Histogram", 0 );
cvResizeWindow("RGB Histogram", 1024, 350);
cvShowImage( "RGB Histogram", hist_img );
cvWaitKey(0);
}
return 0;
}
Ⅲ 如何使用MATLAB計算彩色圖像的顏色直方圖
從別人那裡學來的:
1.將RGB圖象轉為HSV
2. 將H分量量化16級,將S分量和V分量分別量化為4級.
3.將三個顏色分量合成為一維特徵向量:L = H*Qs*Qv+S*Qv+v;Qs,Qv分別是S和V的量化級數, L取值范圍[0,255].
4.計算L的直方圖分布
但願合你胃口,呵呵!
Ⅳ 高分在線求C#做直方圖源碼
網路一下,你就知道
Ⅳ 求matlab彩色圖片的顏色特徵提取演算法的代碼,和紋理特徵提取的代碼。傳統方法即可。
其實學數字圖像處理,關鍵的不是源代碼(和一般編程還是有區別的,這個是經驗之談,其實一般博導未必會編程,但是你和他說說你的方法,他一般都能切中要害),而是你能理解基於概念及適用場所。
基於顏色、紋理、形狀都屬於低層特徵,這些你理解就夠了,關鍵是對你的課題適合哪種方法來映射到高層語義上面,例如:識別物體輪廓,那可能形狀就比較適合等。
我之所以寫上面那段話,主要是我感覺你索取代碼也不說明具體要求,也就是方向不明確。
如今顏色特徵提取演算法有很多,諸如顏色直方圖、顏色矩、顏色集、顏色聚合向量、顏色相關圖等,既然你沒說,我就給個IEEE CSVT 2001的一篇關於顏色直方圖法的論文(源碼版權歸作者所有):
function colorhist = colorhist(rgb)
% CBIR_colorhist() --- color histogram calculation
% input: MxNx3 image data, in RGB
% output: 1x256 colorhistogram == (HxSxV = 16x4x4)
% as the MPEG-7 generic color histogram descriptor
% [Ref] Manjunath, B.S.; Ohm, J.-R.; Vasudevan, V.V.; Yamada, A., "Color and texture descriptors"
% IEEE Trans. CSVT, Volume: 11 Issue: 6 , Page(s): 703 -715, June 2001 (section III.B)
% check input
if size(rgb,3)~=3
error('3 components is needed for histogram');
end
% globals
H_BITS = 4; S_BITS = 2; V_BITS = 2;
%rgb2hsv可用rgb2hsi代替,見你以前的提問。
hsv = uint8(255*rgb2hsv(rgb));
imgsize = size(hsv);
% get rid of irrelevant boundaries
i0=round(0.05*imgsize(1)); i1=round(0.95*imgsize(1));
j0=round(0.05*imgsize(2)); j1=round(0.95*imgsize(2));
hsv = hsv(i0:i1, j0:j1, :);
% histogram
for i = 1 : 2^H_BITS
for j = 1 : 2^S_BITS
for k = 1 : 2^V_BITS
colorhist(i,j,k) = sum(sum( ...
bitshift(hsv(:,:,1),-(8-H_BITS))==i-1 &...
bitshift(hsv(:,:,2),-(8-S_BITS))==j-1 &...
bitshift(hsv(:,:,3),-(8-V_BITS))==k-1 ));
end
end
end
colorhist = reshape(colorhist, 1, 2^(H_BITS+S_BITS+V_BITS));
% normalize
colorhist = colorhist/sum(colorhist);
%基於紋理特徵提取灰度共生矩陣用於紋理判斷
% Calculates cooccurrence matrix
% for a given direction and distance
%
% out = cooccurrence (input, dir, dist, symmetric);
%
% INPUT:
% input: input matrix of any size
%
% dir: direction of evaluation
% "dir" value Angle
% 0 0
% 1 -45
% 2 -90
% 3 -135
% 4 -180
% 5 +135
% 6 +90
% 7 +45
%
% dist: distance between pixels
%
% symmetric: 1 for symmetric version
% 0 for non-symmetric version
%
% eg: out = cooccurrence (input, 0, 1, 1);
% Author: Baran Aydogan (15.07.2006)
% RGI, Tampere University of Technology
% [email protected]
function out = cooccurrence (input, dir, dist, symmetric);
input = round(input);
[r c] = size(input);
min_intensity = min(min(input));
max_intensity = max(max(input));
out = zeros(max_intensity-min_intensity+1);
if (dir == 0)
dir_x = 0; dir_y = 1;
end
if (dir == 1)
dir_x = 1; dir_y = 1;
end
if (dir == 2)
dir_x = 1; dir_y = 0;
end
if (dir == 3)
dir_x = 1; dir_y = -1;
end
if (dir == 4)
dir_x = 0; dir_y = -1;
end
if (dir == 5)
dir_x = -1; dir_y = -1;
end
if (dir == 6)
dir_x = -1; dir_y = 0;
end
if (dir == 7)
dir_x = -1; dir_y = 1;
end
dir_x = dir_x*dist;
dir_y = dir_y*dist;
out_ind_x = 0;
out_ind_y = 0;
for intensity1 = min_intensity:max_intensity
out_ind_x = out_ind_x + 1;
out_ind_y = 0;
[ind_x1 ind_y1] = find (input == intensity1);
ind_x1 = ind_x1 + dir_x;
ind_y1 = ind_y1 + dir_y;
for intensity2 = min_intensity:max_intensity
out_ind_y = out_ind_y + 1;
[ind_x2 ind_y2] = find (input == intensity2);
count = 0;
for i = 1:size(ind_x1,1)
for j = 1:size(ind_x2,1)
if ( (ind_x1(i) == ind_x2(j)) && (ind_y1(i) == ind_y2(j)) )
count = count + 1;
end
end
end
out(out_ind_x, out_ind_y) = count;
end
end
if (symmetric)
if (dir < 4)
dir = dir + 4;
else
dir = mod(dir,4);
end
out = out + cooccurrence (input, dir, dist, 0);
end
Ⅵ MATLAB編程,知道得到灰度直方圖的畫法,但不知怎麼得到一幅圖的彩色圖像的直方圖
不是彩色圖像