modify pixel of image with 0.01
hi, i have a image i want to modify it each pixel of image having 0 value with 0.01. below is the code to replace the value 0 with 0.01. but it is not doing any thing.
code -
for (int y=0; y<contrast.rows; y++)
{
for (int x=0; x<contrast.cols; x++)
{
if(contrast.at<uchar>(y, x) ==0)
contrast.at<uchar>(y, x) = 0.01;
}
}
thanks
Google unsigned char.
If your image is of type 8UC1 (thats why I suppose that you are using uchar), its values are integers, not floating point, and is very likely that they are between 0(black) and 255(white). The least value that you can add is 1. Attributing 0.01 to a uchar variable will round it to 0.
It's normal, since uchar is an integer type!!!
i want to replace 0 value from 0.01. how can i do this?
of course,it can not convert,because contrast.at<uchar>(y, x) means at point(x,y) the value type is unsigned char, if you want to replace the value from 0 to 0.01, at first, you should convert contrast to double or float type ,for example contrast.at<float>(y,x)=0.01