Search in sources :

Example 6 with Histogram

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);
}
Also used : Histogram(qupath.lib.analysis.stats.Histogram) HistogramData(qupath.lib.gui.charts.HistogramPanelFX.HistogramData) NumberAxis(javafx.scene.chart.NumberAxis) GridPane(javafx.scene.layout.GridPane) Color(javafx.scene.paint.Color) Label(javafx.scene.control.Label) ChannelDisplayInfo(qupath.lib.display.ChannelDisplayInfo)

Aggregations

Histogram (qupath.lib.analysis.stats.Histogram)6 GridPane (javafx.scene.layout.GridPane)4 Color (javafx.scene.paint.Color)4 NumberAxis (javafx.scene.chart.NumberAxis)3 Label (javafx.scene.control.Label)3 HistogramPanelFX (qupath.lib.gui.charts.HistogramPanelFX)3 HistogramData (qupath.lib.gui.charts.HistogramPanelFX.HistogramData)3 ThresholdedChartWrapper (qupath.lib.gui.charts.HistogramPanelFX.ThresholdedChartWrapper)3 DecimalFormat (java.text.DecimalFormat)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)2 ObservableValue (javafx.beans.value.ObservableValue)2 Insets (javafx.geometry.Insets)2 ButtonType (javafx.scene.control.ButtonType)2 CheckBox (javafx.scene.control.CheckBox)2 ContextMenu (javafx.scene.control.ContextMenu)2 Dialog (javafx.scene.control.Dialog)2