I need to convert bitmap to binary image for my hw.Do u know anything about that?
bitmap, method by which a display space (such as a graphics image file) is defined, including the colour of each of its pixels (or bits). In effect, a bitmap is an array of binary data representing the values of pixels in an image or display. A GIF is an example of a graphics image file that has a bitmap.
A bitmap (or raster graphic) is a digital image composed of a matrix of dots. When viewed at 100%, each dot corresponds to an individual pixel on a display. In a standard bitmap image, each dot can be assigned a different color. In this instance we will simply create a Bitmap directly: Bitmap b = Bitmap.
To create a bitmap from a resource, you use the BitmapFactory method decodeResource(): Bitmap bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.
Are you looking for an algorithm to perform the conversion?
The easiest way is to compare each pixel value with a fixed threshold: if the pixel value is less than the threshold, the corresponding output pixel is black (0), else it is white (1).
If you wish to determine the threshold automatically, you may want to implement Otsu's method. That method does a correct job overall when you can't make too many assumptions about the pixels distribution in your image.
http://en.wikipedia.org/wiki/Otsu%27s_Method
As a reference, that's how it looks like in Mathematica:
Binarize[image, threshold]
, and Binarize[img]
for Otsu's method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With