Region with different brightness

I have an image divided into different areas similar to each other, but one of them has different brightness, and I have to find out which of these areas has different brightness.

I use the OpenCV library in my C ++ program. I converted my image from RGB to HSV space color. Then I measured the global value for each region, but it doesn't seem to be as great as I thought.

The following figure shows an example:

Any suggestion?

+4
source share
2 answers

Sorry, the answer uses Matlab, but this approach should be easily implemented in C ++.

0 1, , HSV , :

L = mat2gray(mean(image, 3));

Luminance channel

:

L_blur = medfilt2(L, [10 10]);

Filter median

Otsu Thresholding . , :

mask = L_blur > graythresh(L_blur);

Binary mask

:

output = uint8(repmat(mask, [1 1 3])) .* image;

Final result

.

+4

OpenCV @Eliezer, .

#include <opencv2/opencv.hpp>
using namespace cv;

int main()
{
    Mat3b img = imread("path_to_image");

    // Estimate Luminance Channel

    Mat1b L(img.rows, img.cols, uchar(0));
    for (int r = 0; r < img.rows; ++r)
    {
        for (int c = 0; c < img.cols; ++c)
        {
            Vec3b v = img(r,c);
            L(r, c) = saturate_cast<uchar>((float(v[0]) + float(v[1]) + float(v[2])) / 3.f);
        }
    }

    // Apply a Median Filter
    Mat1b L_blur;
    medianBlur(L, L_blur, 11);

    // Use OTSU threshold
    Mat1b mask;
    threshold(L_blur, mask, 0, 255, THRESH_BINARY | THRESH_OTSU);

    // Segment image
    Mat3b output(img.rows, img.cols, Vec3b(0,0,0));
    img.copyTo(output, mask);


    imshow("Result", output);
    waitKey();

    return 0;
}

:

enter image description here

+3

Source: https://habr.com/ru/post/1624079/


All Articles