use of qupath.lib.gui.charts.HistogramPanelFX.HistogramData in project qupath by qupath.
the class HistogramDisplay method setHistogram.
void setHistogram(final PathTableData<?> model, final String columnName) {
if (model != null && model.getMeasurementNames().contains(columnName)) {
double[] values = model.getDoubleValues(columnName);
int nBins = params.getIntParameterValue("nBins");
if (nBins < 2)
nBins = 2;
else if (nBins > 1000)
nBins = 1000;
// We can have values in the 'wrong' order to facilitate comparison...
Arrays.sort(values);
// Check if we've actually changed anything - if not, then abort
if (nBins == currentBins && currentValues != null && Arrays.equals(currentValues, values))
return;
Histogram histogram = new Histogram(values, nBins);
// histogram.setNormalizeCounts(params.getBooleanParameterValue("normalizeCounts"));
HistogramData histogramData = HistogramPanelFX.createHistogramData(histogram, false, (Integer) null);
histogramData.setNormalizeCounts(params.getBooleanParameterValue("normalizeCounts"));
panelHistogram.getHistogramData().setAll(histogramData);
AreaChart<Number, Number> chart = panelHistogram.getChart();
chart.setVerticalGridLinesVisible(true);
chart.setHorizontalGridLinesVisible(true);
chart.setLegendVisible(false);
// Can't stop them being orange...
chart.setCreateSymbols(false);
chart.getXAxis().setLabel("Values");
chart.getYAxis().setLabel("Counts");
chart.getYAxis().setTickLabelsVisible(true);
chart.getYAxis().setTickMarkVisible(true);
chart.getXAxis().setTickLabelsVisible(true);
chart.getXAxis().setTickMarkVisible(true);
chart.setAnimated(params.getBooleanParameterValue("animate"));
updateTable(histogram);
currentColumn = columnName;
currentBins = nBins;
currentValues = values;
this.model = model;
} else
panelHistogram.getHistogramData().clear();
}
use of qupath.lib.gui.charts.HistogramPanelFX.HistogramData in project qupath by qupath.
the class HistogramDisplay method parameterChanged.
@Override
public void parameterChanged(ParameterList parameterList, String key, boolean isAdjusting) {
if ("normalizeCounts".equals(key)) {
boolean doNormalize = params.getBooleanParameterValue("normalizeCounts");
// This is rather clumsy (compared to just updating the histogram data),
// but the reason is that the animations are poor when the data is updated in-place
List<HistogramData> list = new ArrayList<>();
for (HistogramData histogramData : panelHistogram.getHistogramData()) {
histogramData.setNormalizeCounts(doNormalize);
list.add(new HistogramData(histogramData.getHistogram(), false, histogramData.getStroke()));
// histogramData.update();
}
panelHistogram.getHistogramData().setAll(list);
return;
} else if ("drawGrid".equals(key)) {
panelHistogram.getChart().setHorizontalGridLinesVisible(params.getBooleanParameterValue("drawGrid"));
panelHistogram.getChart().setVerticalGridLinesVisible(params.getBooleanParameterValue("drawGrid"));
return;
} else if ("drawAxes".equals(key)) {
panelHistogram.setShowTickLabels(params.getBooleanParameterValue("drawAxes"));
return;
} else if ("nBins".equals(key)) {
setHistogram(model, comboName.getSelectionModel().getSelectedItem());
return;
} else if ("animate".equals(key)) {
panelHistogram.getChart().setAnimated(params.getBooleanParameterValue("animate"));
}
}
use of qupath.lib.gui.charts.HistogramPanelFX.HistogramData 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