Kamal Sharma Kamal Sharma - 5 months ago 56
iOS Question

Unsupported format or combination of formats (Only 8-bit, 3-channel input images are supported) in cvWatershed

Hi I am new to image segmentation, i am trying the given code to get foreground objects, but i got error like "Unsupported format or combination of formats (Only 8-bit, 3-channel input images are supported) in cvWatershed"

cv::Mat img0 = [img toMat];
cv::Mat img1;
cv::cvtColor(img0, img0, CV_RGB2GRAY);
cv::threshold(img0, img0, 100, 255, cv::THRESH_BINARY);

cv::Mat fg;
cv::erode(img0,fg,cv::Mat(),cv::Point(-1,-1),6);

cv::Mat bg;
cv::dilate(img0,bg,cv::Mat(),cv::Point(-1,-1),6);
cv::threshold(bg,bg,1,128,cv::THRESH_BINARY_INV);

cv::Mat markers(img0.size(),CV_8U,cv::Scalar(0));
markers= fg+bg;


// cv::namedWindow("Markers");
// cv::imshow("Markers", markers);

WatershedSegmenter segmenter;
segmenter.setMarkers(markers);
cv::Mat result1 = segmenter.process(img0);


// cv::Mat result1;
result1.convertTo(result1,CV_8U);

UIImage * result = [UIImage imageWithMat:result1 andImageOrientation:[img imageOrientation]];
return result;


And i try by debugging and got error in line

cv::Mat result1 = segmenter.process(img0);


Thanks in advance

Answer

I again analyzed my code and solved the problem. Convert the image to ilpImage and then change it to a 8 bit and 3 channel image using code

WatershedSegmenter segmenter;
segmenter.setMarkers(markers);
markers=cvCreateImage(cvGetSize(my_iplImage), IPL_DEPTH_8U, 3);
cv::Mat result1 = segmenter.process(markers);