use of qupath.lib.analysis.stats.Histogram in project qupath by qupath.
the class BrightnessContrastCommand method updateHistogram.
private void updateHistogram() {
if (table == null || !isInitialized())
return;
ChannelDisplayInfo infoSelected = getCurrentInfo();
Histogram histogram = (imageDisplay == null || infoSelected == null) ? null : imageDisplay.getHistogram(infoSelected);
// histogram = histogramMap.get(infoSelected);
if (histogram == null) {
histogramPanel.getHistogramData().clear();
} else {
// Any animation is slightly nicer if we can modify the current data, rather than creating a new one
if (histogramPanel.getHistogramData().size() == 1) {
Color color = infoSelected.getColor() == null ? ColorToolsFX.TRANSLUCENT_BLACK_FX : ColorToolsFX.getCachedColor(infoSelected.getColor());
histogramPanel.getHistogramData().get(0).setHistogram(histogram, color);
} else {
HistogramData histogramData = HistogramPanelFX.createHistogramData(histogram, true, infoSelected.getColor());
histogramData.setNormalizeCounts(true);
histogramPanel.getHistogramData().setAll(histogramData);
}
}
NumberAxis xAxis = (NumberAxis) histogramPanel.getChart().getXAxis();
if (infoSelected != null && infoSelected.getMaxAllowed() == 255 && infoSelected.getMinAllowed() == 0) {
xAxis.setAutoRanging(false);
xAxis.setLowerBound(0);
xAxis.setUpperBound(255);
} else if (infoSelected != null) {
xAxis.setAutoRanging(false);
xAxis.setLowerBound(infoSelected.getMinAllowed());
xAxis.setUpperBound(infoSelected.getMaxAllowed());
// xAxis.setAutoRanging(true);
}
if (infoSelected != null)
xAxis.setTickUnit(infoSelected.getMaxAllowed() - infoSelected.getMinAllowed());
// Don't use the first of last count if it's an outlier
NumberAxis yAxis = (NumberAxis) histogramPanel.getChart().getYAxis();
if (infoSelected != null && histogram != null) {
long maxCount = 0L;
for (int i = 1; i < histogram.nBins() - 1; i++) maxCount = Math.max(maxCount, histogram.getCountsForBin(i));
if (maxCount == 0)
maxCount = histogram.getMaxCount();
yAxis.setAutoRanging(false);
yAxis.setLowerBound(0);
yAxis.setUpperBound((double) maxCount / histogram.getCountSum());
}
histogramPanel.getChart().getXAxis().setTickLabelsVisible(true);
histogramPanel.getChart().getXAxis().setLabel("Pixel value");
histogramPanel.getChart().getYAxis().setTickLabelsVisible(true);
// histogramPanel.getChart().getYAxis().setLabel("Frequency");
GridPane pane = new GridPane();
pane.setHgap(4);
pane.setVgap(2);
int r = 0;
if (histogram != null) {
pane.add(new Label("Min"), 0, r);
pane.add(new Label(df.format(histogram.getMinValue())), 1, r);
r++;
pane.add(new Label("Max"), 0, r);
pane.add(new Label(df.format(histogram.getMaxValue())), 1, r);
r++;
pane.add(new Label("Mean"), 0, r);
pane.add(new Label(df.format(histogram.getMeanValue())), 1, r);
r++;
pane.add(new Label("Std.dev"), 0, r);
pane.add(new Label(df.format(histogram.getStdDev())), 1, r);
r++;
}
chartTooltip.setGraphic(pane);
if (r == 0)
Tooltip.uninstall(histogramPanel.getChart(), chartTooltip);
else
Tooltip.install(histogramPanel.getChart(), chartTooltip);
}
Aggregations