diff options
author | Timothee Floure | 2015-10-28 11:15:28 +0100 |
---|---|---|
committer | Timothee Floure | 2015-10-28 11:15:28 +0100 |
commit | 2db512ac95a782f6bb35b7c45475a33f73b6f252 (patch) | |
tree | 60db7743dd492274b9ce59fca662f9f174a74b02 /src/main | |
parent | 93ad72d636c9a4cd433225006dec850c150bdc65 (diff) | |
download | seam-stitcher-2db512ac95a782f6bb35b7c45475a33f73b6f252.tar.gz |
Filter : allow to handle any kernel size (H*N : H and N odd)
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/Filter.java | 35 |
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 | } |