0

Is there a way to reduce the grayscales of an gray-image in openCv?

Normaly i have grayvalues from 0 to 256 for an

Image<Gray, byte> inputImage.

In my case i just need grayvalues from 0-10. Is there i good way to do that with OpenCV, especially for C# ?

JavaNullPointer
  • 1,199
  • 5
  • 21
  • 43

1 Answers1

1

There's nothing built-in on OpenCV that allows this sort of thing.

Nevertheless, you can write something yourself. Take a look at this C++ implementation and just translate it to C#:

void colorReduce(cv::Mat& image, int div=64)
{    
    int nl = image.rows;                    // number of lines
    int nc = image.cols * image.channels(); // number of elements per line

    for (int j = 0; j < nl; j++)
    {
        // get the address of row j
        uchar* data = image.ptr<uchar>(j);

        for (int i = 0; i < nc; i++)
        {
            // process each pixel
            data[i] = data[i] / div * div + div / 2;
        }
    }
}

Just send a grayscale Mat to this function and play with the div parameter.

Community
  • 1
  • 1
karlphillip
  • 92,053
  • 36
  • 243
  • 426