JavaNullPointer
JavaNullPointer

Reputation: 1211

EmguCv: Reduce the grayscales

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# ?

Upvotes: 0

Views: 498

Answers (1)

karlphillip
karlphillip

Reputation: 93468

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.

Upvotes: 1

Related Questions