-1

How to Threshold image between certain range? i have done this but it doesn't work.

for (int i=0;i<s.size().height;i++)
{
    for(int j=0;j<s.size().width;j++)
    {
        int k=int (s.at<uchar>(j,i));
        if (k>6 &&  k<10)
            k=255;
        else k=0;
            s.at<uchar>(j,i)=k;
    }
}
JJJ
  • 31,545
  • 20
  • 84
  • 99

1 Answers1

1

You get an uchar value, and convert it to integer. Try this :

    uchar k= s.at<uchar>(j,i);
    if (k>6 &&  k<10) {
        k=255;
     }else {
        k=0;
     }
     s.at<uchar>(j,i)=k;

I think it may work.

Dimitri Mockelyn
  • 1,505
  • 2
  • 11
  • 17