Ask Your Question
0

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

asked 2018-11-13 04:25:42 -0600

Janrex gravatar image

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);
}
edit retag flag offensive close merge delete

Comments

can it be, the lines are already gone before any processing ?

maybe you could try to imread() your image directly from disc, instead of getting a (scaled ?) bitmap from your View

try to imwrite() your Mat before doing anything to it, just for debugging !

berak gravatar imageberak ( 2018-11-13 04:30:33 -0600 )edit

Have you tried using something else than THRESH_BINARY? Like:

th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv.THRESH_BINARY,11,2)

Hatmpatn gravatar imageHatmpatn ( 2018-11-13 06:16:03 -0600 )edit

@Hatmpatn That s the answer that I went for. I haven't posted the answer here because it needs 2 days before answering your own question. The only difference in our answer is that i used this Imgproc.adaptiveThreshold(grayMat,imageBW,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY,5,4); which i dont really know the meaning of THRESH_MEAN_C 5 and 4. I got it from stack overflow. Can you explain the meaning of this fields including your answer?

Janrex gravatar imageJanrex ( 2018-11-13 08:46:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-11-13 08:44:52 -0600

Hatmpatn gravatar image

Have you tried using something else than THRESH_BINARY? Like:

th3 = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\ cv.THRESH_BINARY,11,2)

edit flag offensive delete link more

Comments

this solved it! thanks can i ask what 11 and 2 is?

Janrex gravatar imageJanrex ( 2018-11-13 10:23:54 -0600 )edit
eshirima gravatar imageeshirima ( 2018-11-13 11:54:30 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-11-13 04:25:42 -0600

Seen: 721 times

Last updated: Nov 13 '18