BoofCV on Android - threshold() returns black image

53 Views Asked by At
 Bitmap blurredBitmap = GaussianBlur.with(sApp.getApplicationContext()).radius(5).render(R.drawable.test_img_divider);
        GrayU8 imageGray = ConvertBitmap.bitmapToGray(blurredBitmap,(GrayU8) null, null);
        GrayU8 imageThreshold = GThresholdImageOps.threshold(imageGray, null, GThresholdImageOps.computeEntropy(imageGray, 0, 255), true);

        Bitmap output = Bitmap.createBitmap(imageThreshold.width, imageThreshold.height, Bitmap.Config.ARGB_8888);
        ConvertBitmap.grayToBitmap(imageThreshold, output, null); // output is totally black.

R.drawable.test_img_divider: enter image description here

blurredBitmap: enter image description here

imageGray(after it was converted to bitmap): enter image description here

output: enter image description here

1

There are 1 best solutions below

0
On

I ran into this too. The image is actually not black. The pixels all have a value of either 0 or 1. But 1 looks pretty much the same as 0 if you treat the image as something that could have pixel values anywhere up to 255.

One way to deal with this is to use forEachPixel() to multiply each pixel value by 255.