I try to convert a RGB image to HSV color space, and get the HSV value of a pixel.
But the result is a little strange, as far as I know, the range of H is between 0 and 360, S and V is between 0 to 255, but the result that I have got is 0~255 for any of HSV value. I doubt that OpenCV have done the transform, is that right? Please help me.
If you're acquaint with the RGB-HSV conversion, OpenCV uses the following formulas to convert B,G,R values, (0~255) to H,S,V:
V=Max(B,G,R)
S=255*[1-min(B,G,R)/Max(B,G,R)]
let d=Max(B,G,R)-min(B,G,R)
H=30*[((G-B)/d)%6] if V=R
=30*[((B-R)/d)+2] if V=G
=30*[((R-G)/d)+4] if V=B
Related
I need to quantize the RGB values to 29 uniform color dictionary. I used rgb2ind(image,29) in Matlab.
So, is there any function or efficient way to quantize the image color in OpenCV?
(I need to quantize the image color because i want to get a 29-sized histogram of color)
You will have to make your own. I can reccomend using HSV instead of RGB (you can convert RGB to HSV with opencv). Once the image is converted, you can then simply use 29 ranges for the H value.
EDIT: I saw this answer might be a bit vague for those who have little experience in computer vision. This question gives a lot more information about the difference between HSV and RGB and why this is usefull.
Can anybody explain to me why the hue value of an HSV image in OpenCV only goes to 180° and not the full 360°?
I have found somewhere that OpenCV uses a 180° cylinder, but I can not really visualize such a cylinder.
Thanks in advance!
J
try to put 360 into a uchar ;)
so, it's just divided by 2 to make it fit..
The ranges that OpenCV manage for HSV format are the following:
For HSV, Hue range is [0,179], Saturation range is [0,255] and Value range is [0,255]. Different softwares use different scales. So if you are comparing OpenCV values with them, you need to normalize these ranges.
Here is the link to the OpenCV documentation that explains it.
http://docs.opencv.org/3.2.0/df/d9d/tutorial_py_colorspaces.html
According to http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor
For the 8-bit images, H is converted to H/2 to fit to the [0,255] range. So the range of hue in the HSV color space of OpenCV is [0,179]
Is it really so?I think for HSV the ranges are as H[0-179], S[0-255], V[0-255].Please see the link and help me understand if I am missing something. http://docs.opencv.org/trunk/doc/py_tutorials/py_imgproc/py_colorspaces/py_colorspaces.html
If you need to convert the range of Hue, see the link below.
http://en.literateprograms.org/RGB_to_HSV_color_space_conversion_%28C%29#
I am a beginner in both Image Processing and Opencv. I am trying to find out the individual pixel intensities of an image, using OPENCV#. There is assistance here: http://docs.opencv.org/doc/user_guide/ug_mat.html?highlight=pixel%20intensity for the same issue. But I am not sure how to use it in OPENCV#.
I know this is a very basic query. Please try to help out. Thanks in advance.
Pixel intensity is the same thing as that pixel's grayscale value. To get a grayscale (pixel intensity) version of an BGR image you can do this:
cv::cvtColor(bgr_mat,gray_mat,CV_BGR2GRAY);
Now the 3 channel BGR image has been converted to a 1 channel GRAYSCALE image. To find the intensity of pixel (x,y) in the gray image you can do this:
//NOTE: in OpenCV pixels are accessed in (row,col) format
int intensity = (int)gray_mat.at<uchar>(y,x);
Since each grayscale pixel is stored as uchar, the value of intensity will range from (0-255) where 255 is maximum intensity (seen as a completely white pixel).
in emgu cv, you can do it like this.
//Color
//Red
byte Red_val = My_Image.Data[y,x,0];
//Green
byte Green_val = My_Image.Data[y,x,1];
//Blue
byte Blue_val = My_Image.Data[y,x,2];
//Greyscale
byte Gray_val = My_Image.Data[y,x,0];
I am reading a book for image processing algorithms and for the contrast
algorithm it says that I can either go RGB->HSL or RGB->HSI first and
than apply a contrast technique for grayscale images, on the lightness component.
Then it gives this formula only, not other formulas for color conversion:
L(x,y) = 0.299*R(x,y) + 0.587*G(x,y) + 0.114*B(x,y)
This formula is neither for the L in HSL, neither for the I in HSI and that is
what confuses me.
Thanks
It's the luma value mentioned in the fourth bullet here: http://en.wikipedia.org/wiki/HSL_and_HSV#Lightness
I'm trying to create an histogram using opencv. I have an image (32 bit) that came out from a blurring operation, so I just know that the values are in the range [-0.5; 0.5] but I don't know anything else about the starting data.
the problem is that I don't understand how to set the parameters to compute such histogram.
the code I wrote is:
int numbins=1000;
float range[]={-0.5, 0.5};
float *ranges[]={range};
CvHistogram *hist=cvCreateHist(1, &numbins, CV_HIST_ARRAY, ranges, 1);
cvCalcHist(&img, hist);
were img is the image I want to get the histogram. if I try to print the histogram I just get a black picture, while with the same function I get a correct histogram if use a grayscale 8bit image.
Have you looked at the calcHist example? Also, the camshiftdemo makes heavy use of histograms.
Are you normalizing the histogram output with normalize before display (camshiftdemo shows how to do this)? Values near 0 will appear black when displayed, but when normalized between say 0 and 255 will show up nicely.