我正在尝试在MATLAB中将此特定命令实现为opencv。我正在Linux Ubuntu中工作。您可以帮我找出opencv中的代码。
out_vector = HIST(G_vector,0:17:255); G_vector是一个大小为1X100的数组,表示图像的1个分量。
我正在使用以下代码
vector<Mat> rgb_planes;
split(image,rgb_planes);
int histSize = 255;
/// Set the ranges ( for R,G,B) )
float range[] = { 0,17, 255 } ;
const float* histRange = { range };
bool uniform = true; bool accumulate = false;
Mat r_hist, g_hist, b_hist,g_hist1;
/// Compute the histograms:
calcHist( &rgb_planes[0], 1, 0, Mat(), r_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &rgb_planes[1], 1, 0, Mat(), g_hist, 1, &histSize, &histRange, uniform, accumulate );
calcHist( &rgb_planes[2], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );
// Draw the histograms for R, G and B
int hist_w = 400; int hist_h = 400;
int bin_w = cvRound( (double) hist_w/histSize );
Mat histImage( hist_w, hist_h, CV_8UC3, Scalar( 0,0,0) );
/// Normalize the result to [ 0, histImage.rows ]
normalize(r_hist, r_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
normalize(g_hist, g_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
normalize(b_hist, b_hist, 0, histImage.rows, NORM_MINMAX, -1, Mat() );
您能否建议我应该在哪里进行更改
答案 0 :(得分:2)
histSize
控制每个维度中的分档数量。如果您想在这些一维直方图中使用16个分档,请使用:
int histSize[] = { 16 };
或者我猜只是int histSize = 16;会工作的。
将bin边界设置为0到255,如下所示:
float intensity_range = { 0, 256 }; //upper bound is exclusive
const float * histRange[] = { intensity_range };
OpenCV的calcHist提供了一种可配置性,很少有人需要。 Check out the method description and example code here