6

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

barzos
  • 837
  • 3
  • 16
  • 25

5 Answers5

3

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

Matthias Odisio
  • 2,038
  • 12
  • 19
0

Hope this helps...

Bitmap bitmapObtained =//get your bitmap
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapObtained.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
ik024
  • 3,566
  • 7
  • 38
  • 61
0

You can use the bitmap convert function and write it to an output stream and then use the output stream to get for yourself the byte array I hope that helps

vivek
  • 284
  • 3
  • 8
0

you can look this link converting Java bitmap to byte array, it can convert bitmap to binary, can then you should look at display image from byteArray

Community
  • 1
  • 1
pengwang
  • 19,536
  • 34
  • 119
  • 168
-1

perhaps this is your code

imageID = cursor.getString(columnIndex);
              //  uri = Uri.withAppendedPath(Media.EXTERNAL_CONTENT_URI, "" + imageID);
                Log.v("dklfdlk",imageID);
                bitmap = BitmapFactory.decodeFile(imageID);
if (bitmap != null) {
                    newBitmap = Bitmap.createScaledBitmap(bitmap, 78, 78, true);
                    bitmap.recycle();
                    if (newBitmap != null) {
                        publishProgress(new LoadedImage(newBitmap));
}

try this

Siddiqui
  • 7,662
  • 17
  • 81
  • 129
Maidul
  • 1,289
  • 16
  • 30