aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/Filter.java35
1 files changed, 27 insertions, 8 deletions
diff --git a/src/main/java/Filter.java b/src/main/java/Filter.java
index 4e06800..7e55f04 100644
--- a/src/main/java/Filter.java
+++ b/src/main/java/Filter.java
@@ -51,17 +51,36 @@ public final class Filter {
51 public static float[][] filter(float[][] gray, float[][] kernel) { 51 public static float[][] filter(float[][] gray, float[][] kernel) {
52 int width = gray[0].length; 52 int width = gray[0].length;
53 int height = gray.length; 53 int height = gray.length;
54
55 int kernelWidth = kernel[0].length;
56 int kernelHeight = kernel.length;
57
58 float pixelNeighbors[][] = new float[kernelHeight][kernelWidth];
54 float[][] filteredImage = new float[height][width]; 59 float[][] filteredImage = new float[height][width];
60
55 for (int row = 0; row < height; ++row) { 61 for (int row = 0; row < height; ++row) {
56 for (int col = 0; col < width; ++col) { 62 for (int col = 0; col < width; ++col) {
57 float pixelNeighbors[][] = { 63
58 {Filter.at(gray, row - 1, col - 1), Filter.at(gray, row - 1, col), Filter.at(gray, row - 1, col + 1)}, 64 int pixelRow = -kernelHeight / 2;
59 {Filter.at(gray, row, col - 1), Filter.at(gray, row, col), Filter.at(gray, row, col + 1)}, 65 int pixelCol = -kernelWidth / 2;
60 {Filter.at(gray, row + 1, col - 1), Filter.at(gray, row + 1, col), Filter.at(gray, row + 1, col + 1)} 66
61 }; 67 for (int kernelRow = 0; kernelRow < kernelWidth; kernelRow++) {
62 68 for (int kernelCol = 0; kernelCol < kernelHeight; kernelCol++) {
63 for (int i = 0; i < kernel[0].length; i++) { 69 pixelNeighbors[kernelRow][kernelCol] = Filter.at(gray, row + pixelRow, col + pixelCol);
64 for (int j = 0; j < kernel.length; j++) { 70
71 pixelCol += 1;
72 if (pixelCol > kernelWidth / 2) {
73 pixelCol = -kernelWidth / 2;
74 }
75 }
76 pixelRow += 1;
77 if (pixelRow > kernelHeight / 2) {
78 pixelRow = -kernelHeight / 2;
79 }
80 }
81
82 for (int i = 0; i < kernelWidth; i++) {
83 for (int j = 0; j < kernelHeight; j++) {
65 filteredImage[row][col] += kernel[i][j] * pixelNeighbors[i][j]; 84 filteredImage[row][col] += kernel[i][j] * pixelNeighbors[i][j];
66 } 85 }
67 } 86 }