Getting a completely blank image whilst performing a hit or miss transform in the thinning process of a digital image

24 views Asked by At

enter image description here

This is the image after first level edge detection. When I pass it through my performThinning method, it returns a completely white blank picture.

This is the performThinning method I have been working on so far:

public static BufferedImage performThinning(BufferedImage edges, int[][] structuringElement) {
    int width = edges.getWidth();
    int height = edges.getHeight();

    // Create a copy of the input edges image to store the result
    BufferedImage resultImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);

    int structuringWidth = structuringElement.length;
    int structuringHeight = structuringElement[0].length;

    for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
            int hitCount = 0;
            int missCount = 0;

            for (int i = 0; i < structuringWidth; i++) {
                for (int j = 0; j < structuringHeight; j++) {
                    if (structuringElement[i][j] == 1) {
                        int imageX = x + i - structuringWidth / 2;
                        int imageY = y + j - structuringHeight / 2;

                        if (imageX >= 0 && imageX < width && imageY >= 0 && imageY < height) {
                            int edgePixel = edges.getRGB(imageX, imageY);
                            if (edgePixel == -16777216) { // Check for black pixel
                                missCount++;
                            } else if (edgePixel == -1) { // Check for white pixel
                                hitCount++;
                            }
                        }
                    }
                }
            }

            // Check for hit or miss conditions (you can adjust these conditions)
            if (hitCount >= 1 && missCount >= 1) {
                resultImage.setRGB(x, y, -16777216); // Set to black
            } else {
                resultImage.setRGB(x, y, -1); // Set to white
            }
        }
    }

    return resultImage;
}

Note: this is the binary matrix I used as the structuring element for the above color image:

int[][] structuringFactor = {
            {0, 1, 0},
            {0, 0, 1},
            {1, 1, 1}
        };

Anyone knows what sort of silly/basic or fundamental/conceptual mistake I am making here?

0

There are 0 answers