Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.image.BufferedImage;
- import java.util.Random;
- @SuppressWarnings("unused")
- public class RandomJitter implements BaseFilter {
- private static final int DEGREE = 4;
- private static final int ITERATIONS = 3;
- private Random rnd;
- public RandomJitter() {
- rnd = new Random();
- }
- @Override
- public BufferedImage process(BufferedImage source) {
- BufferedImage slika = new BufferedImage(source.getWidth(), source.getHeight(), BufferedImage.TYPE_INT_RGB);
- for (int x = 0; x < source.getWidth(); x++)
- {
- for (int y = 0; y < source.getHeight(); y++)
- {
- slika.setRGB(x, y, source.getRGB(x, y));
- }
- }
- int c = 0;
- Random rnd = new Random();
- while (c++ < ITERATIONS)
- {
- for (int x = 0; x < source.getWidth(); x++)
- {
- for (int y = 0; y < source.getHeight(); y++)
- {
- int degree = rnd.nextInt(DEGREE)-2;
- int noviX = x + degree;
- int noviY = y + degree;
- if (noviX < 0)
- {
- noviX = 0;
- }
- else if (noviX >= source.getWidth())
- {
- noviX = source.getWidth() - 1;
- }
- if (noviY < 0)
- {
- noviY = 0;
- }
- else if (noviY >= source.getHeight())
- {
- noviY = source.getHeight() - 1;
- }
- slika.setRGB(noviX, noviY, source.getRGB(x, y));
- }
- }
- }
- return slika;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement