Ask Your Question

Revision history [back]

Converting transparent pixels to white after mask proccess

I m working on optical mark recognition. My purpose is extracting the red circles from the image and evaluating black shapes after. There is no problem on detecting red circles and extracting them (picture 2), i successfully obtain the image where red pixels are transparent. The problem is that, when i convert this image to grey, transparent pixels becomes black, so nothing changes after all this effort(picture3). How can i convert transparent pixels to white or i m making somethings very wrong?

    Mat masked = new Mat(src.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
    Mat hsv_image = new Mat();
    Imgproc.cvtColor(src, hsv_image, Imgproc.COLOR_RGB2HSV);

    Mat lower_red_hue_range = new Mat();
    Mat upper_red_hue_range = new Mat();
    Core.inRange(hsv_image, new Scalar(0, 70, 70), new Scalar(10, 255, 255), lower_red_hue_range);
    Core.inRange(hsv_image, new Scalar(160, 70, 70), new Scalar(179, 255, 255), upper_red_hue_range);
    Mat red_hue_mask = new Mat();
    Core.addWeighted(lower_red_hue_range, 1.0, upper_red_hue_range, 1.0, 0.0, red_hue_mask);
    Core.bitwise_not(red_hue_mask, red_hue_mask);
    Utils.saveAsBitmap(red_hue_mask);  // picture1

    src.copyTo(masked, red_hue_mask);
    Utils.saveAsBitmap(masked); // picture2

    Imgproc.cvtColor(masked, mBlacked, Imgproc.COLOR_RGB2GRAY);
    Utils.saveAsBitmap(mBlacked); // picture3

image description image description image description