Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Color;
- import java.awt.image.BufferedImage;
- public class Sharpen implements BaseFilter {
- @Override
- public BufferedImage process(BufferedImage source) {
- BufferedImage img = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x < img.getWidth(); x++)
- for (int y = 0; y < img.getHeight(); y++){
- img.setRGB(x, y, source.getRGB(x, y));
- }
- double[][] table = {
- {0.0, -0.67, 0.0},
- {-0.67, 3.67, -0.67},
- {0.0, -0.67, 0.0}
- };
- double sumRed = 0, sumGreen = 0, sumBlue = 0;
- for (int x = 1; x < source.getWidth() - 1; x++)
- for (int y = 1; y < source.getHeight() - 1; y++) {
- for (int nx = -1; nx <= 1; nx++)
- for (int ny = -1; ny <= 1; ny++) {
- double t = table[nx + 1][ny + 1];
- Color c = new Color(source.getRGB(x + nx, y + ny));
- sumRed += t * c.getRed();
- sumGreen += t * c.getGreen();
- sumBlue += t * c.getBlue();
- }
- int red = norm((int) sumRed);
- int green = norm((int) sumGreen);
- int blue = norm((int) sumBlue);
- Color boja = new Color(red, green, blue);
- img.setRGB(x, y, boja.getRGB());
- }
- return img;
- }
- public int norm(int x) {
- if (x > 255)
- return 255;
- if (x < 0)
- return 0;
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement