0

I have been trying to apply laplacian filter in java.

int  red = 8 * red - imageOne.getRed(i - 1, j - 1)
                    - imageOne.getRed(i, j - 1)
                    - imageOne.getRed(i + 1, j - 1)
                    - imageOne.getRed(i - 1, j) - imageOne.getRed(i, j)
                    - imageOne.getRed(i + 1, j)
                    - imageOne.getRed(i - 1, j + 1)
                    - imageOne.getRed(i, j + 1)
                    - imageOne.getRed(i + 1, j + 1);

green and blue values are calculated in the same way.

After calculating RGB values, there are some very large values or negative values. the range being [- 255*8 ... 255*8]

I tried to scale it using

     red = (int) (red / 16) + 128;
 green = (int) (green / 16) + 128;
 blue = (int) (blue / 16) + 128;

I also have tried restrcting it between [0 - 255] with following code

        red = Math.min(255, Math.max(0, red));

but the image is still not displayed properly.

How do i handle the RGB values properly ???

Thanks

Ken
  • 287
  • 3
  • 5
  • 15
  • 1
    http://stackoverflow.com/questions/7449596/implement-laplacian-3x3?rq=1 might help –  Nov 19 '13 at 06:26
  • hello RC.. the question you directed me uses the same scaling thing as I did... I changed my scaling thing to the provided one and I am still getting the same picutre.. – Ken Nov 19 '13 at 07:50
  • 1
    Your scaling should be `red = (red + 8 * 255) / 16`, etc. – Roger Rowland Nov 19 '13 at 08:16
  • Thanks Roger and RC, got it now.. it was a stupid mistake.. i was multiplying wrong pixel... btw, what's the difference between red = (red + 8 * 255) / 16; & red = (int) (red / 16) + 128; Because they both are giving the same value as far as I tested :O Thanks – Ken Nov 19 '13 at 08:17
  • 1
    Try `red = -2040` and you get `0` with the correct scaling and `0.5` with your scaling - they are not the same, possibly due to some integer arithmetic. – Roger Rowland Nov 19 '13 at 08:18

0 Answers0