Android Bitmap Color Change erosion(Bitmap bitmap, int[][] se)

Here you can find the source of erosion(Bitmap bitmap, int[][] se)

Description

erosion

Declaration

public static void erosion(Bitmap bitmap, int[][] se) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

public class Main {
    public static void erosion(Bitmap bitmap, int[][] se) {

        int hlen = bitmap.getWidth(), vlen = bitmap.getHeight();
        for (int i = 0; i < vlen; i++) {
            for (int j = 0; j < hlen; j++) {
                bitmap.setPixel(/*from w  w w.  j  a  va  2 s .c  om*/
                        j,
                        i,
                        kernelMatch(j, i, hlen, vlen, bitmap, se) ? 0xffffffff
                                : 0xff000000);
            }
        }
    }

    private static boolean kernelMatch(int x, int y, int w, int h,
            Bitmap bitmap, int[][] se) {
        int lenh = se[0].length, lenv = se.length;
        for (int i = 0; i < lenv; i++) {
            for (int j = 0; j < lenh; j++) {
                int pVal = ((bitmap.getPixel((x + j) % w, (y + i) % h) & 0xff) > 0 ? 1
                        : 0);
                if (se[i][j] != pVal) {
                    return false;
                }
            }
        }

        return true;
    }
}

Related

  1. createAnaglyphBitmap(Bitmap bitmap)
  2. createSaturatedBitmap(final Bitmap bitmap)
  3. dilate(Bitmap bitmap, int[][] se)
  4. dilate(Bitmap source, Bitmap target, int[][] se)
  5. doBrightness(Bitmap src, int value)
  6. getGrayscaleHistogram(Bitmap bm)
  7. increaseGreen(Bitmap src, int value)
  8. initAlphaChannel( BitmapFactory.Options bitmapOptions)
  9. initBitmapFactoryOptions( BitmapFactory.Options bitmapOptions, int maxWidth, int maxHeight)