(ImageProcessor ip)
| 61 | } |
| 62 | |
| 63 | void filter(ImageProcessor ip) { |
| 64 | ImageProcessor ip2 = ip; |
| 65 | if (ip2 instanceof ColorProcessor) { |
| 66 | showStatus("Extracting brightness"); |
| 67 | ip2 = ((ColorProcessor)ip2).getBrightness(); |
| 68 | } |
| 69 | Rectangle roiRect = ip2.getRoi(); |
| 70 | int maxN = Math.max(roiRect.width, roiRect.height); |
| 71 | double sharpness = (100.0 - toleranceDia) / 100.0; |
| 72 | boolean doScaling = doScalingDia; |
| 73 | boolean saturate = saturateDia; |
| 74 | |
| 75 | IJ.showProgress(1,20); |
| 76 | |
| 77 | /* tile mirrored image to power of 2 size |
| 78 | first determine smallest power 2 >= 1.5 * image width/height |
| 79 | factor of 1.5 to avoid wrap-around effects of Fourier Trafo */ |
| 80 | |
| 81 | int i=2; |
| 82 | while(i<1.5 * maxN) i *= 2; |
| 83 | |
| 84 | // Calculate the inverse of the 1/e frequencies for large and small structures. |
| 85 | double filterLarge = 2.0*filterLargeDia / (double)i; |
| 86 | double filterSmall = 2.0*filterSmallDia / (double)i; |
| 87 | |
| 88 | // fit image into power of 2 size |
| 89 | Rectangle fitRect = new Rectangle(); |
| 90 | fitRect.x = (int) Math.round( (i - roiRect.width) / 2.0 ); |
| 91 | fitRect.y = (int) Math.round( (i - roiRect.height) / 2.0 ); |
| 92 | fitRect.width = roiRect.width; |
| 93 | fitRect.height = roiRect.height; |
| 94 | |
| 95 | // put image (ROI) into power 2 size image |
| 96 | // mirroring to avoid wrap around effects |
| 97 | showStatus("Pad to "+i+"x"+i); |
| 98 | ip2 = tileMirror(ip2, i, i, fitRect.x, fitRect.y); |
| 99 | IJ.showProgress(2,20); |
| 100 | |
| 101 | // transform forward |
| 102 | showStatus(i+"x"+i+" forward transform"); |
| 103 | FHT fht = new FHT(ip2); |
| 104 | fht.setShowProgress(false); |
| 105 | fht.transform(); |
| 106 | IJ.showProgress(9,20); |
| 107 | //new ImagePlus("after fht",ip2.crop()).show(); |
| 108 | |
| 109 | // filter out large and small structures |
| 110 | showStatus("Filter in frequency domain"); |
| 111 | filterLargeSmall(fht, filterLarge, filterSmall, choiceIndex, sharpness); |
| 112 | //new ImagePlus("filter",ip2.crop()).show(); |
| 113 | IJ.showProgress(11,20); |
| 114 | |
| 115 | // transform backward |
| 116 | showStatus("Inverse transform"); |
| 117 | fht.inverseTransform(); |
| 118 | IJ.showProgress(19,20); |
| 119 | //new ImagePlus("after inverse",ip2).show(); |
| 120 |
no test coverage detected