How to get pixel values of a binarized image in android studio?
I want to get the pixel value of a binarized image and store it in an integer array. I used openCV to grayscale the image and used adaptivethreshold for the binary: grayBitmap = Bitmap.createBitmap(width,height,Bitmap.Config.ARGB_8888);
Utils.bitmapToMat(imageBitmap,Rgba);//bitmap to Mat
Imgproc.cvtColor(Rgba,grayMat,Imgproc.COLOR_RGB2GRAY);//grayscale
//binary
Imgproc.adaptiveThreshold(grayMat,imageBW,255,Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY,5,4);
//mat to bitmap
Utils.matToBitmap(imageBW,grayBitmap);
and I want to get pixel value of imageBW to see the value of each pixels and possibly convert them into 1 and 0 depending o for black and 1 for white if necessary.
wrong assumption here, already. opencv uses 255 for white, and 0 for black.
use:
System.out.println(imageBW.dump());
please try to explain, what you're trying to achieve with the whole thing, else it is yet another XY-problem !
how can i store them? I would like to store the pixel values in an int array.
why do you need that ?
@berak I would like to simply see what value each pixel of a binary image is and store them in an int array. i would use that array to convert it bitmap and display that image i know there are mat to bitmap functions but this code is for experimentation.
so, print it out, then (or save a Mat to disc, using imwrite())
still, here's what you could try: (but opencv keeps binary images as bytes, not integers !:
(but that's an expensive, and silly copy)
@berak I need to save it in a int array. and convert it to bitmap this is an experiment to test if what I'm thinking is possible.
i doubt you need any bitmap conversion here.
@berak. last question what kind of value would be stored in every element of the array? I really dont know anything about Byte array.
all i'm saying is: use opencv methods to save the bwImage, don't convert to bitmap, or try to get arrays from it.
255 for white, 0 for black, as i've said before already