Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert bitmap image to binary image in android?

I need to convert bitmap to binary image for my hw.Do u know anything about that?

like image 775
barzos Avatar asked Apr 14 '11 23:04

barzos


People also ask

Does bitmap use binary?

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.

What is bitmap image in Android?

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.

How to Create bitmap in android?

To create a bitmap from a resource, you use the BitmapFactory method decodeResource(): Bitmap bitmap = BitmapFactory. decodeResource(getResources(), R. drawable.


1 Answers

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.

enter image description here

like image 64
Matthias Odisio Avatar answered Sep 22 '22 18:09

Matthias Odisio