Android Bitmap Color Get countSE(Bitmap bitmap, int[][] se)

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

Description

count SE

Declaration

public static int countSE(Bitmap bitmap, int[][] se) 

Method Source Code

//package com.java2s;

import android.graphics.Bitmap;

public class Main {
    public static int countSE(Bitmap bitmap, int[][] se) {
        int hlen = bitmap.getWidth(), vlen = bitmap.getHeight();
        int toReturn = 0;
        for (int i = vlen - 1; i >= 0; i--) {
            for (int j = hlen - 1; j >= 0; j--) {
                if (kernelMatch(j, i, hlen, vlen, bitmap, se)) {
                    toReturn++;// ww w  .j av  a 2  s.c o  m
                }
            }
        }

        return toReturn;
    }

    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. getContactCount(Bitmap bitmap)
  2. getPixelsCount(Bitmap bitmap)
  3. kernelMatch(int x, int y, int w, int h, Bitmap bitmap, int[][] se)
  4. getColorHistogram(Bitmap bitmap)