基于内容的图像检索的直方图比较。不同的色彩空间(RGB、HSV 等)
我正在使用 OpenCv 进行基于内容的图像检索的最终学位项目。我开始比较直方图。问题是,我看过很多帖子说 RGB 是最难操作的色彩空间,并且 最好使用HSV或YCrCb。然而,当我将图像与 RGB 进行比较时,结果总是比使用其他色彩空间时要好。
这是 YCrCb 颜色的代码:
void Histogram::calculateYCCHist(const cv::Mat3b& img_base, const cv::Mat1b& mask)
{
cv::Mat3f ycbcr;
cvtColor( Mat3f(img_base), ycbcr, CV_BGR2YCrCb);
int hist_size[] = {100, 100, 100};
float y_range[] = { 0, 1 }; // luma (Y) value have a nominal range from 0 to 1
float chr_range[] = { -0.5, 0.5 }; // chroma (CB and CR) values will have a nominal range from -0.5 to +0.5
const float* ranges_Y[] = {y_range};
const float* ranges_Cb[] = {chr_range};
const float* ranges_Cr[] = {chr_range};
int channel_y[] = {0};
int channel_cb[] = {1};
int channel_cr[] = {2};
// Compute histogram
calcHist(&ycbcr, 1, channel_y, mask, m_histogram_b, 1, hist_size, ranges_Y, true, false);
normalize( m_histogram_b, m_histogram_b, 0, m_histogram_b.rows, NORM_MINMAX, -1, Mat() );
calcHist(&ycbcr, 1, channel_cb, mask, m_histogram_g, 1, hist_size, ranges_Cb, true, false);
normalize( m_histogram_g, m_histogram_g, 0, m_histogram_g.rows, NORM_MINMAX, -1, Mat() );
calcHist(&ycbcr, 1, channel_cr, mask, m_histogram_r, 1, hist_size, ranges_Cr, true, false);
normalize( m_histogram_r, m_histogram_r, 0, m_histogram_r.rows, NORM_MINMAX, -1, Mat() );
}
范围正确吗?
我对图像进行了标准化,但它根本没有改变任何东西。
您认为我应该尝试使用其他方法吗?
我还注意到,垃圾箱的数量非常重要,如果更改此值,我会得到非常不同的结果,有什么方法可以控制它吗?
问候
I'm doing a final degree proyect in Content Based Image Retrieval using OpenCv. I have started comparing histograms. The thing is that I have seen a lot of post saying that RGB is the worst color space to operate, and it's better to use HSV or YCrCb . However, when I compare images with RGB, the results are always better than when I use other color spaces.
This is the code for the YCrCb color:
void Histogram::calculateYCCHist(const cv::Mat3b& img_base, const cv::Mat1b& mask)
{
cv::Mat3f ycbcr;
cvtColor( Mat3f(img_base), ycbcr, CV_BGR2YCrCb);
int hist_size[] = {100, 100, 100};
float y_range[] = { 0, 1 }; // luma (Y) value have a nominal range from 0 to 1
float chr_range[] = { -0.5, 0.5 }; // chroma (CB and CR) values will have a nominal range from -0.5 to +0.5
const float* ranges_Y[] = {y_range};
const float* ranges_Cb[] = {chr_range};
const float* ranges_Cr[] = {chr_range};
int channel_y[] = {0};
int channel_cb[] = {1};
int channel_cr[] = {2};
// Compute histogram
calcHist(&ycbcr, 1, channel_y, mask, m_histogram_b, 1, hist_size, ranges_Y, true, false);
normalize( m_histogram_b, m_histogram_b, 0, m_histogram_b.rows, NORM_MINMAX, -1, Mat() );
calcHist(&ycbcr, 1, channel_cb, mask, m_histogram_g, 1, hist_size, ranges_Cb, true, false);
normalize( m_histogram_g, m_histogram_g, 0, m_histogram_g.rows, NORM_MINMAX, -1, Mat() );
calcHist(&ycbcr, 1, channel_cr, mask, m_histogram_r, 1, hist_size, ranges_Cr, true, false);
normalize( m_histogram_r, m_histogram_r, 0, m_histogram_r.rows, NORM_MINMAX, -1, Mat() );
}
Are the ranges right?
I normalize the image but it doesn't change anything at all.
Do you think that I should try to use other methods?
I have also noticed that the number of bins is of great importance and I get very different results if I change this value, is there any way to control this?
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到这可能无法回答您的具体问题,而是回答您更一般的问题......
老实说,每个色彩空间彼此之间都有很大不同。根据我的经验,在算法中使用不同的颜色空间通常需要更改算法的工作方式才能获得有用的结果。例如,在 HSV 空间中,H 通道是圆形的,即值 100 = 0,而 RGB 则不是这种情况。例如,在 YCbCr 中,如果您处理的是照明强度很重要的一种类型的图像,则 Y 通道可能比 Cr 和 Cb 通道具有更多的强调/重要性,或者如果您处理的是颜色(无论照明如何),则相反。力量。
其次,当你说一种色彩空间比另一种色彩空间差时,你对每个色彩空间都是不公平的。它们各有其用途和局限性。
您链接到的关于哪个空间更好的文章是主观的“稳定性”。选择某种色彩空间而不是其他色彩空间的原因有很多。
关于你关于 YCbCr 范围的具体问题......对不起,我不知道......我对此有点生疏。
:)
I realise that this may not answer your specific question but rather your more general one....
To be honest each colour space is very different from each other. In my experience using a different colour space in your algorithm usually requires changes to how the algorithm works in order to get useful results. An example of this would be how in the HSV space the H channel is circular i.e. a value of 100 = 0, which isnt the case for RGB. For example is that in YCbCr the Y channel might have more emphasis/importance than the Cr adn Cb channels if you are dealing with one type of images where illumination strength is of importance or the opposite way round if you are dealing with colours regardless of illumination strength.
Secondly when you say that one colour space is worse than another you are being unfair to each. They each have their uses and their limitations.
The article that you link to on which space is better is subjective to "stability". There are many many reasons why you might choose a colour space over another.
On your specific question on YCbCr ranges...Im sorry I dont know... Im a bit rusty on this.
:)