(ImagePlus imp, ImageProcessor ip, String method)
| 1583 | } |
| 1584 | |
| 1585 | private static void setStackThreshold(ImagePlus imp, ImageProcessor ip, String method) { |
| 1586 | boolean darkBackground = method.contains("dark"); |
| 1587 | boolean histo16 = imp.getBitDepth()==16 && method.contains("16"); |
| 1588 | //IJ.log("setStackThreshold: "+histo16+" "+method); |
| 1589 | boolean addOne = !method.contains("16"); |
| 1590 | int measurements = Analyzer.getMeasurements(); |
| 1591 | Analyzer.setMeasurements(Measurements.AREA+Measurements.MIN_MAX); |
| 1592 | ImageStatistics stats = new StackStatistics(imp); |
| 1593 | Analyzer.setMeasurements(measurements); |
| 1594 | AutoThresholder thresholder = new AutoThresholder(); |
| 1595 | double min=0.0, max=255.0; |
| 1596 | if (imp.getBitDepth()!=8) { |
| 1597 | min = stats.min; |
| 1598 | max = stats.max; |
| 1599 | } |
| 1600 | int[] histogram = stats.histogram; |
| 1601 | if (histo16) |
| 1602 | histogram = stats.histogram16; |
| 1603 | int threshold = thresholder.getThreshold(method, histogram); |
| 1604 | double lower, upper; |
| 1605 | double tmax = 255.0; |
| 1606 | if (histogram.length>256) |
| 1607 | tmax = 65535.0; |
| 1608 | if (darkBackground) { |
| 1609 | if (ip.isInvertedLut()) |
| 1610 | {lower=0.0; upper=threshold;} |
| 1611 | else |
| 1612 | {lower=threshold+(addOne?1:0); upper=tmax;} |
| 1613 | } else { |
| 1614 | if (ip.isInvertedLut()) |
| 1615 | {lower=threshold+(addOne?1:0); upper=tmax;} |
| 1616 | else |
| 1617 | {lower=0.0; upper=threshold;} |
| 1618 | } |
| 1619 | if (!histo16) { |
| 1620 | if (lower>255) lower = 255; |
| 1621 | if (max>min) { |
| 1622 | lower = min + (lower/255.0)*(max-min); |
| 1623 | upper = min + (upper/255.0)*(max-min); |
| 1624 | } else |
| 1625 | lower = upper = min; |
| 1626 | ip.setMinAndMax(min, max); |
| 1627 | } |
| 1628 | ip.setThreshold(lower, upper, ImageProcessor.RED_LUT); |
| 1629 | imp.updateAndDraw(); |
| 1630 | } |
| 1631 | |
| 1632 | /** Disables thresholding on the current image. */ |
| 1633 | public static void resetThreshold() { |
no test coverage detected