| 424 | // by averaging over 3x3 pixels |
| 425 | // Requires a quadratic 8-bit image. |
| 426 | static void smooth(ImageProcessor ip) { |
| 427 | byte[] pixels = (byte[])ip.getPixels(); |
| 428 | byte[] pixels2 = (byte[])pixels.clone(); |
| 429 | int n = ip.getWidth(); |
| 430 | int[] iMinus = new int[n]; //table of previous index modulo n |
| 431 | int[] iPlus = new int[n]; //table of next index modulo n |
| 432 | for (int i=0; i<n; i++) { //creating the tables in advance is faster calculating each time |
| 433 | iMinus[i] = (i-1+n)%n; |
| 434 | iPlus[i] = (i+1)%n; |
| 435 | } |
| 436 | for (int y=0; y<n; y++) { |
| 437 | int offset1 = n*iMinus[y]; |
| 438 | int offset2 = n*y; |
| 439 | int offset3 = n*iPlus[y]; |
| 440 | for (int x=0; x<n; x++) { |
| 441 | int sum = (pixels2[offset1+iMinus[x]]&255) |
| 442 | + (pixels2[offset1+x]&255) |
| 443 | + (pixels2[offset1+iPlus[x]]&255) |
| 444 | + (pixels2[offset2+iMinus[x]]&255) |
| 445 | + (pixels2[offset2+x]&255) |
| 446 | + (pixels2[offset2+iPlus[x]]&255) |
| 447 | + (pixels2[offset3+iMinus[x]]&255) |
| 448 | + (pixels2[offset3+x]&255) |
| 449 | + (pixels2[offset3+iPlus[x]]&255); |
| 450 | pixels[offset2 + x] = (byte)((sum+4)/9); |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | void redisplayPowerSpectrum() { |
| 456 | FHT fht = (FHT)imp.getProperty("FHT"); |