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 result = clone(source);
- int width = source.getWidth();
- int height = source.getHeight();
- for (int i= 0; i < ITERATIONS; i++) {
- for (int x = 0; x < width; x++)
- for (int y = 0; y < height; y++) {
- int xDelta = rnd.nextInt(DEGREE + 1) - 2;
- int yDelta = rnd.nextInt(DEGREE + 1) - 2;
- if (x + xDelta >= 0 && x + xDelta < width && y + yDelta >= 0 && y + yDelta <height){
- result.setRGB(x + xDelta, y + yDelta, source.getRGB(x, y));
- }
- }
- }
- return result;
- }
- private BufferedImage clone(BufferedImage source) {
- 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++)
- for (int j = 0; j < height; j++) {
- result.setRGB(i, j, source.getRGB(i, j));
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement