Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

imwrite in opencv gives a black image

I wrote a code for watershed segmentation in C API. Now I am converting all those into C++. so, cvsaveimage becomes imwrite. But when I use imwrite ,all i get is a black image.

this is the code:-

    Mat img8bit;
    Mat img0;
    img0 = imread("source.png", 1);           
    Mat wshed(img0.size(), CV_32F);
    wshed.setTo(cv::Scalar::all(0));
   ////after performing watershed segmentation and
            // displaying the watershed image from wshed//
    wshed.convertTo(img8bit, CV_32FC3, 255.0);
    imwrite("Watershed.png", img8bit);

The original image that I want to save is in wshed. I saw suggestions from the net that we need to convert it to 16 bit or higher so that the imwrite saves it right. Like you see,I tried that. But the wshed image is being displayed correctly when using imshow.The img0 is grey image/black and white while the wshed image is coloured. any help on this? I used wshed.type() to get what kind of image the output is,it was 16bit.