【发布时间】:2011-12-01 20:00:24
【问题描述】:
我正在尝试在 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() );
您能建议我应该在哪里进行更改
【问题讨论】:
-
2小时内没有回复。请大家帮帮我
-
为什么要改?什么地方出了错?我可以建议的一件事是
0:17:255意味着您的range[]应该是{0,17,34,51,...}(即添加17 直到达到255)。
标签: matlab image-processing opencv histogram