
Это изображение после первого уровня обнаружение края. Когда я передаю его через метод PerformThinning, он возвращает совершенно белое пустое изображение.
Это метод PerformThinning, над которым я работал до сих пор:
Код: Выделить всё
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;
}
Код: Выделить всё
int[][] structuringFactor = {
{0, 1, 0},
{0, 0, 1},
{1, 1, 1}
};
Подробнее здесь: https://stackoverflow.com/questions/774 ... form-in-th
Мобильная версия