how to set hue value of some pixel with opencv

六月ゝ 毕业季﹏ 提交于 2019-12-11 03:35:57

问题


I need to change the hue of some pixels of my image, but i don't know how to set them!

I converted the image in HSV with CV_BGR2HSV and now i'm cycling with a for by rows and cols...

how can I access each pixel's hue?

for setting RGB i'm using this code...

CvScalar s;
s=cvGet2D(imgRGB,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);
s.val[0]=240;
s.val[1]=100;
s.val[2]=100;
cvSet2D(imgRGB,i,j,s); // set the (i,j) pixel value

回答1:


You already converted your image to HSV, so the 3 layers of the image now correspond to Hue, Saturation and Value:

  • s.val[0] is the hue.
  • s.val[1] is the saturation.
  • s.val[2] is the value.

So go ahead and use exactly the same method as for your RGB images to get and set the pixel values.




回答2:


Yes, openCV uses 180° i.e., (0°-179°) cylinder of HSV; while normally its (0°-240°) in MS paint and ideally (0°-360°). So, openCV gives you result of hue from (0°-179°).



来源:https://stackoverflow.com/questions/5642097/how-to-set-hue-value-of-some-pixel-with-opencv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!