I try to create an application that is able to take a photo and apply a filter to the image taken in such a way that a binary image is generated. My problem lies in the shadows, the shadows turn black and most of the image is ruined. This is the code that is responsible for applying the define the filter for the image.
private static ColorMatrix getColorMatrix(){
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(0);
float m = 255f;
float t = -255*128f;
ColorMatrix threshold = new ColorMatrix(new float[]{
m, 0, 0, 1, t,
0, m, 0, 1, t,
0, 0, m, 1, t,
0, 0, 0, 1, 0
});
colorMatrix.postConcat(threshold);
return colorMatrix;
}
And the one here applies it
private static Bitmap aplicarFiltro(Bitmap bmp){
int width = bmp.getWidth();
int height = bmp.getHeight();
Bitmap img = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas colox = new Canvas(img);
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(binarizeMatrix()));
colox.drawBitmap(bmp, 0, 0, paint);
return img;
}