public static int getRectangleCount(byte[][] a) {
        int countQuad = 0;
        int posXstart = 0;
        int posYstart = 0;
        int posXend = 0;
        int posYend = 0;

        for (int y = 0; y < a.length; y++) {
            for (int x = 0; x < a[0].length; x++) {
                if (a[y][x] == 1) {
                    posXstart = x;
                    posYstart = y;
                    posXend = posXstart;
                    posYend = posYstart;

                    while (posXend < a[0].length) {
                        if (a[posYend][posXend] == 0) {
                            break;
                        }
                        posXend++;
                    }
                    posXend = posXend - 1;

                    while (posYend < a.length) {
                        if (a[posYend][posXend] == 0) {
                            break;
                        }
                        posYend++;
                    }
                    posYend = posYend - 1;

                    for (int YY = posYstart; YY <= posYend; YY++) {
                        for (int XX = posXstart; XX <= posXend; XX++) {
                            a[YY][XX] = 0;
                        }
                    }
                    countQuad++;
                }
            }
        }
        return countQuad;
    }
}