Trouble using threshold() function in opencv
I am trying to segment input image using watershed method. In that i am using threshold(), however my program gets aborted with the following error on the terminal unsupported format or combination of formats () in cv::threshold The format of the function used is threshold(bw, bw, 40, 255, THRESH_BINARY); where bw is the binarised image in grayscale form.
"where bw is the binarised image in grayscale form."
the o/p of the above command comes out to be 22 3 [259 x 194]
bw.convertTo(bw, CV_8UC1); gives output 16 3 [259 x 194]. Why is that the channel even now remain 3?
Try to use cvtColor().
convertTo() does not change the channel count, only the depth. (so, yes, cvtColor(src,dst,COLOR_BGR2GRAY))
okk thanks alot. But is there any way i can threshold a 3 channel image? Converting BGR 2 Gray before using threshold() and then converting it back to BGR, will it work?
no, you can't get back color from a grayscale image ..
what are you trying to achieve ?
Thank u so much. Got it now. GRAY2BGR will only convert single channel image to 3 channel. Earlier I thought it wud convert gray to color image!!!
I am basically writing an image segmentation code & my code will work only if i can make the background black objects's color other than black(then i am using watershed()). Can u suggest any way to make background black?