Returns an 8-bit power spectrum, log-scaled to 1-254. The image in this FHT is assumed to be in the frequency domain.
()
| 401 | /** Returns an 8-bit power spectrum, log-scaled to 1-254. The image in this |
| 402 | FHT is assumed to be in the frequency domain. */ |
| 403 | public ImageProcessor getPowerSpectrum () { |
| 404 | if (!isFrequencyDomain) |
| 405 | throw new IllegalArgumentException("Frequency domain image required"); |
| 406 | int base; |
| 407 | float r, scale; |
| 408 | float min = Float.MAX_VALUE; |
| 409 | float max = Float.MIN_VALUE; |
| 410 | float[] fps = new float[maxN*maxN]; |
| 411 | byte[] ps = new byte[maxN*maxN]; |
| 412 | float[] fht = (float[])getPixels(); |
| 413 | |
| 414 | for (int row=0; row<maxN; row++) { |
| 415 | fht2ps(row, maxN, fht, fps); |
| 416 | base = row * maxN; |
| 417 | for (int col=0; col<maxN; col++) { |
| 418 | r = fps[base+col]; |
| 419 | if (r<min) |
| 420 | min = r; |
| 421 | if (r>max) |
| 422 | max = r; |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | max = (float)Math.log(max); |
| 427 | min = (float)Math.log(min); |
| 428 | if (Float.isNaN(min) || max-min>50) |
| 429 | min = max - 50; //display range not more than approx e^50 |
| 430 | scale = (float)(253.999/(max-min)); |
| 431 | |
| 432 | //long t0 = System.currentTimeMillis(); |
| 433 | for (int row=0; row<maxN; row++) { |
| 434 | base = row*maxN; |
| 435 | for (int col=0; col<maxN; col++) { |
| 436 | r = fps[base+col]; |
| 437 | r = ((float)Math.log(r)-min)*scale; |
| 438 | if (Float.isNaN(r) || r<0) |
| 439 | r = 0f; |
| 440 | ps[base+col] = (byte)(r+1f); // 1 is min value |
| 441 | } |
| 442 | } |
| 443 | //long t1 = System.currentTimeMillis(); |
| 444 | //IJ.log(""+(t1-t0)); |
| 445 | ImageProcessor ip = new ByteProcessor(maxN, maxN, ps); |
| 446 | swapQuadrants(ip); |
| 447 | return ip; |
| 448 | } |
| 449 | |
| 450 | /** Returns the unscaled 32-bit power spectrum. */ |
| 451 | public FloatProcessor getRawPowerSpectrum() { |
no test coverage detected