private static Stx createStx(Band band, Element bandStatisticsElem) { final Double minSample = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MIN); final Double maxSample = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MAX); final Double mean = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_MEAN); final Double stdDev = getElemDouble(bandStatisticsElem, DimapProductConstants.TAG_STX_STDDEV); final Integer level = getElemInt(bandStatisticsElem, DimapProductConstants.TAG_STX_LEVEL); final int[] bins = getHistogramBins(bandStatisticsElem); boolean intHistogram = !ProductData.isFloatingPointType(band.getGeophysicalDataType()); if (minSample != null && maxSample != null) { return new StxFactory() .withMinimum(minSample) .withMaximum(maxSample) .withMean(mean) .withStandardDeviation(stdDev) .withIntHistogram(intHistogram) .withHistogramBins(bins == null ? new int[0] : bins) .withResolutionLevel(level).create(); } return null; }
private void computeStatistic(String regionName, StxOpMapping stxOpsMapping, Band band, Shape roiShape, MultiLevelImage roiImage) { final SummaryStxOp summaryStxOp = stxOpsMapping.getSummaryOp(regionName); StxFactory.accumulate(band, 0, roiImage, roiShape, summaryStxOp, SubProgressMonitor.create(pm, 50)); final double minimum = summaryStxOp.getMinimum(); final double maximum = summaryStxOp.getMaximum(); final HistogramStxOp histogramStxOp = stxOpsMapping.getHistogramOp(regionName, minimum, maximum, band); StxFactory.accumulate(band, 0, roiImage, roiShape, histogramStxOp, SubProgressMonitor.create(pm, 50)); }
@Override protected Stx computeStxImpl(int level, ProgressMonitor pm) { final IndexCoding indexCoding = getIndexCoding(); if (indexCoding == null) { return super.computeStxImpl(level, pm); } final int sampleCount = indexCoding.getSampleCount(); int minSample = Integer.MAX_VALUE; int maxSample = Integer.MIN_VALUE; for (int i = 0; i < sampleCount; i++) { final int sample = indexCoding.getSampleValue(i); minSample = Math.min(minSample, sample); maxSample = Math.max(maxSample, sample); } final int binCount = maxSample - minSample + 1; final double min = minSample; final double max = maxSample; return new StxFactory() .withResolutionLevel(level) .withHistogramBinCount(binCount) .withMinimum(min) .withMaximum(max).create(this, pm); }
/** * Computes the statistics. May be overridden. * This method belongs to preliminary API and may be removed or changed in the future. * * @param level The resolution level. * @param pm A progress monitor. * @return The statistics. * @since BEAM 4.5 */ protected Stx computeStxImpl(int level, ProgressMonitor pm) { return new StxFactory().withResolutionLevel(level).create(this, pm); }
private Stx createStx() { return new StxFactory() .withMinimum(-0.2) .withMaximum(3) .withMean(5.5) .withStandardDeviation(3.67) .withHistogramBins(new int[]{4, 5, 4, 7, 5, 8}) .create(); }
@Test public void testMinMaxBinsLogHistogram() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(0.1) .withMaximum(10) .withLogHistogram(true) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(0.1, stx.getMinimum(), 1e-10); assertEquals(10, stx.getMaximum(), 1e-10); assertEquals(Math.pow(10.0, stx.getHistogram().getMean()[0]), stx.getMean(), 1e-3); assertEquals(Math.pow(10.0, 0), stx.getMedian(), 1e-3); assertEquals(-1.0, stx.getHistogram().getLowValue(0), 1e-10); assertEquals(1.0, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
final StxFactory factory = new StxFactory(); if (histogramPlotConfig.useRoiMask) { factory.withRoiMask(histogramPlotConfig.roiMask); factory.withHistogramBinCount(histogramPlotConfig.numBins); factory.withLogHistogram(histogramPlotConfig.histogramLogScaled); if (min != null) { if (histogramPlotConfig.histogramLogScaled) { factory.withMinimum(Stx.LOG10_SCALING.scaleInverse(min)); } else { factory.withMinimum(min); factory.withMaximum(Stx.LOG10_SCALING.scaleInverse(max)); } else { factory.withMaximum(max); stx = factory.create(getRaster(), pm); } else { stx = getRaster().getStx(true, pm);
@Test public void testCreateStxForNullBands() throws Exception { final Band testBand1 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -100); final Band testBand2 = null; Stx stx = new StxFactory().withHistogramBinCount(524288).create(null, new RasterDataNode[]{testBand1, testBand2}, ProgressMonitor.NULL); assertEquals(100, stx.getMinimum(), 1E-3); assertEquals(199, stx.getMaximum(), 1E-3); assertEquals(149.5, stx.getMean(), 1E-3); assertEquals(149.5, stx.getMedian(), 1E-3); assertEquals(189, stx.getHistogram().getPTileThreshold(0.9)[0], 1E-3); assertEquals(149, stx.getHistogram().getPTileThreshold(0.5)[0], 1E-3); assertEquals(109, stx.getHistogram().getPTileThreshold(0.1)[0], 1E-3); }
private static double computeStxOnce(Band band) { final long t0 = System.nanoTime(); new StxFactory().create(band, ProgressMonitor.NULL); final long t1 = System.nanoTime(); return (t1 - t0) / 1e6; } }
private void setLogarithmicDisplay(final RasterDataNode raster, final boolean logarithmicDisplay) { final ImageInfoEditorModel model = imageInfoEditor.getModel(); if (logarithmicDisplay) { final StxFactory stxFactory = new StxFactory(); final Stx stx = stxFactory .withHistogramBinCount(raster.getStx().getHistogramBinCount()) .withLogHistogram(logarithmicDisplay) .withResolutionLevel(raster.getSourceImage().getModel().getLevelCount() - 1) .create(raster, ProgressMonitor.NULL); model.setDisplayProperties(raster.getName(), raster.getUnit(), stx, POW10_SCALING); } else { model.setDisplayProperties(raster.getName(), raster.getUnit(), raster.getStx(), Scaling.IDENTITY); } model.getImageInfo().setLogScaled(logarithmicDisplay); }
@Override protected Object doInBackground(ProgressMonitor pm) { pm.beginTask(title, selectedMasks.length); try { final int binCount = Util.computeBinCount(accuracyModel.accuracy); for (int i = 0; i < selectedMasks.length; i++) { final Mask mask = selectedMasks[i]; final Stx stx; ProgressMonitor subPm = SubProgressMonitor.create(pm, 1); if (mask == null) { stx = new StxFactory() .withHistogramBinCount(binCount) .create(getRaster(), subPm); getRaster().setStx(stx); } else { stx = new StxFactory() .withHistogramBinCount(binCount) .withRoiMask(mask) .create(getRaster(), subPm); } histograms[i] = stx.getHistogram(); publish(new ComputeResult(stx, mask)); } } finally { pm.done(); } return null; }
private void setRange(int varIndex, RasterDataNode raster, Mask mask, ProgressMonitor pm) throws IOException { final AxisRangeControl axisRangeControl = axisRangeControls[varIndex]; if (axisRangeControl.isAutoMinMax()) { Stx stx; if (mask == null) { stx = raster.getStx(false, pm); } else { stx = new StxFactory().withRoiMask(mask).create(raster, pm); } axisRangeControl.adjustComponents(stx.getMinimum(), stx.getMaximum(), NUM_DECIMALS); } }
@Test public void testFloatBandStatisticsWithNoDataValueSet() throws Exception { final Band band = createTestBand(ProductData.TYPE_FLOAT32, 100, 120); band.setNoDataValueUsed(true); band.setNoDataValue(-0.5); Stx stx = new StxFactory().withRoiImage(band.getValidMaskImage()).create(band, ProgressMonitor.NULL); assertEquals(5.0e-1, stx.getMedian(), 0.1e-1); assertEquals(4.1e-5, stx.getMean(), 0.1e-5); assertEquals(3464.4, stx.getStandardDeviation(), 1.0e-1); band.setNoDataValue(0.5); stx = new StxFactory().withRoiImage(band.getValidMaskImage()).create(band, ProgressMonitor.NULL); assertEquals(-5.0e-1, stx.getMedian(), 0.1e-1); assertEquals(-4.1e-5, stx.getMean(), 0.1e-5); assertEquals(3464.4, stx.getStandardDeviation(), 1.0e-1); }
/** * Creates an {@code Stx} instance. * * @return The statistics. */ public Stx create() { return create(null, ProgressMonitor.NULL); }
public static void accumulate(RasterDataNode rasterDataNode, int level, RenderedImage roiImage, Shape roiShape, StxOp op, ProgressMonitor pm) { Assert.notNull(rasterDataNode, "raster"); Assert.argument(level >= 0, "level"); Assert.argument(roiImage == null || level == 0, "level"); Assert.notNull(pm, "pm"); final PlanarImage dataImage = ImageManager.getInstance().getGeophysicalImage(rasterDataNode, level); if (dataImage.getSampleModel().getNumBands() != 1) { throw new IllegalStateException("dataImage.sampleModel.numBands != 1"); } PlanarImage maskImage = getEffectiveMaskImage(rasterDataNode, level, roiImage); Shape maskShape = getEffectiveShape(rasterDataNode, roiShape); accumulate(op, dataImage, maskImage, maskShape, pm); }
for (int i = 0; i < filteredRasters.length; i++) { final RasterDataNode rasterDataNode = filteredRasters[i]; accumulate(rasterDataNode, level, roiImages[i], roiShapes[i], meanOp, SubProgressMonitor.create(pm, 50)); for (int i = 0; i < filteredRasters.length; i++) { final RasterDataNode rasterDataNode = filteredRasters[i]; accumulate(rasterDataNode, level, roiImages[i], roiShapes[i], histogramOp, SubProgressMonitor.create(pm, 50)); histogram = createHistogram(minimum, maximum, logHistogram, intHistogram, this.histogramBins); } else { throw new IllegalStateException("Failed to derive histogram");
@Test public void testMinMaxBinsIntHistogram() throws Exception { StxFactory factory = new StxFactory(); factory .withMinimum(1) .withMaximum(100) .withIntHistogram(true) .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1}); Stx stx = factory.create(); assertEquals(1, stx.getMinimum(), 1e-10); assertEquals(100, stx.getMaximum(), 1e-10); assertEquals(44.75, stx.getMean(), 1e-10); assertEquals(51.0, stx.getMedian(), 1e-10); assertNotNull(stx.getHistogram()); assertEquals(1, stx.getHistogram().getNumBands()); assertEquals(8, stx.getHistogram().getNumBins()[0]); assertEquals(1, stx.getHistogram().getLowValue(0), 1e-10); assertEquals(101, stx.getHistogram().getHighValue(0), 1e-10); assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins()); }
@Test public void testCreateStxForMultipleBands() throws Exception { final Band testBand1 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -100); final Band testBand2 = createTestBand(ProductData.TYPE_FLOAT64, 10, 10, -200); Stx stx = new StxFactory().withHistogramBinCount(2097152).create(null, new RasterDataNode[]{testBand1, testBand2}, ProgressMonitor.NULL); assertEquals(100, stx.getMinimum(), 1E-3); assertEquals(299, stx.getMaximum(), 1E-3); assertEquals(199.5, stx.getMean(), 1E-3); assertEquals(199.5, stx.getMedian(), 1E-3); assertEquals(279, stx.getHistogram().getPTileThreshold(0.9)[0], 1E-3); assertEquals(199, stx.getHistogram().getPTileThreshold(0.5)[0], 1E-3); assertEquals(119, stx.getHistogram().getPTileThreshold(0.1)[0], 1E-3); }
@Test public void testSignedByteBandStatistics() throws Exception { final Band band = createTestBand(ProductData.TYPE_INT8, 11, 13); final Stx stx = new StxFactory().create(band, ProgressMonitor.NULL); assertEquals(0.0, stx.getMedian(), 1.0e-1); assertEquals(0.0, stx.getMean(), 0.0); assertEquals(41.4, stx.getStandardDeviation(), 1.0e-1); }
/** * Computes statistics for the given raster data node. * * @param raster The raster data node. * @param pm A progress monitor. * @return The statistics. */ public Stx create(RasterDataNode raster, ProgressMonitor pm) { if (roiMask != null) { return create(new Mask[]{roiMask}, new RasterDataNode[]{raster}, pm); } return create(null, new RasterDataNode[]{raster}, pm); }