Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.image.BufferedImage;
- @SuppressWarnings("unused")
- public class Sharpen implements BaseFilter {
- float[][] matrix =
- {
- {0f, -0.67f, 0f},
- {-0.67f, 3.67f, -0.67f},
- {0f, -0.67f, 0f}
- };
- /*
- * (2, 1): (0, 0) = (1, 0)
- * (2, 1): (1, 0) = (2, 0)
- * (2, 1): (2, 0) = (3, 0)
- * (2, 1): (0, 0) = (1, 0)
- * */
- @Override
- public BufferedImage process(BufferedImage source) {
- // TODO : implementacija
- int width = source.getWidth();
- int height = source.getHeight();
- BufferedImage result = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
- for (int i = 0; i < width; i++) {
- result.setRGB(i, 0, source.getRGB(i, 0));
- result.setRGB(i, height - 1, source.getRGB(i, height - 1));
- }
- for (int j = 0; j < height; j++) {
- result.setRGB(0, j, source.getRGB(0, j));
- result.setRGB(width-1, j, source.getRGB(width-1, j));
- }
- for (int x = 1; x < width - 1; x++)
- for (int y = 1; y < height - 1; y++) {
- int redValue = 0;
- int blueValue = 0;
- int greenValue = 0;
- for (int xm = 0; xm < 3; xm++)
- for (int ym = 0; ym < 3; ym++) {
- int newX = x + xm - 1;
- int newY = y + ym -1;
- Color color = new Color(source.getRGB(newX, newY));
- float factor = matrix[xm][ym];
- int red = (int)(color.getRed() * factor);
- int green = (int)(color.getGreen() * factor);
- int blue = (int)(color.getBlue() * factor);
- redValue += red;
- blueValue += blue;
- greenValue += green;
- }
- redValue = Math.min(255, Math.max(0, redValue));
- blueValue = Math.min(255, Math.max(0, blueValue));
- greenValue = Math.min(255, Math.max(0, greenValue));
- int newRGB = new Color(redValue, greenValue, blueValue).getRGB();
- result.setRGB(x, y, newRGB);
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement