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:
and my program is binarizing it to this: 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);
}
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 yourView
try to
imwrite()
your Mat before doing anything to it, just for debugging !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 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?