Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How can I improve the binarization of image in my sample app

I'a practicing in proprocessingiages in android studio and I want to improve the binarihiszation of images in my program, for example i have this image: image description

and my program is binarizing it to this:image description I would like to be able to maintain the horizontal lines(staff lines) for a horizontal line detection.

here is the piece of my code for the grayscale and binary: public void convGray(View view) { Mat Rgba = new Mat(); Mat grayMat = new Mat(); Mat imageBW = new Mat();

    BitmapFactory.Options o = new BitmapFactory.Options();
    o.inDither=false;
    o.inSampleSize=4;

    int width =   imageBitmap.getWidth();
    int height = imageBitmap.getHeight();

    grayBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.RGB_565);

    //bitmap to Mat

    Utils.bitmapToMat(imageBitmap,Rgba);
    Imgproc.cvtColor(Rgba,grayMat,Imgproc.COLOR_RGB2GRAY);
    Imgproc.threshold(grayMat,imageBW,100,255,Imgproc.THRESH_BINARY);
    Utils.matToBitmap(imageBW,grayBitmap);
    imageView.setImageBitmap(grayBitmap);
}