Ask Your Question
0

How to do multi level thresholding

asked 2020-04-30 00:19:09 -0600

Hi,

I have a greyscale image that has approximately 3 colors, white, grey and black.

white has value of >200. grey has a value of between 100 and 200. black has a value of <100. I want to classify the regions in the image whether they are black, grey or white.

I want to use open cv threshold function to output: white color when region is white, grey color when region is grey, black color when region is black.

however the threshold function can only set to two values.

is there a trick to make it set 3 values?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-04-30 01:43:41 -0600

berak gravatar image

you can do 2 passes, one for white, and one for black.

the grey mask then is the inverse of the or'ed black and white mask. example:

Mat_<uchar> m(1,5); m << 30,110,170,220,240;

Mat b = m < 100;
Mat w = m > 200;
Mat g = ~ (b|w);


cout << b << endl;
cout << g << endl;
cout << w << endl;

.

[255,   0,   0,   0,   0]
[  0, 255, 255,   0,   0]
[  0,   0,   0, 255, 255]
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-04-30 00:19:09 -0600

Seen: 879 times

Last updated: Apr 30 '20