javax.media.jai.Histogram.getNumBins()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(109)

本文整理了Java中javax.media.jai.Histogram.getNumBins()方法的一些代码示例,展示了Histogram.getNumBins()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Histogram.getNumBins()方法的具体详情如下:
包路径:javax.media.jai.Histogram
类名称:Histogram
方法名:getNumBins

Histogram.getNumBins介绍

暂无

代码示例

代码示例来源:origin: geotools/geotools

@Override
  LookupTable createByteLookupTable(Map<String, Object> params) {
    Utilities.ensureNonNull("params", params);
    Histogram h = (Histogram) params.get(KEY_HISTOGRAM);
    final byte[] cumulative = new byte[h.getNumBins(0)];
    // sum of bins (we might have excluded 0 hence we cannot really optimise)
    float totalBinSum = 0;
    for (int i = 0; i < cumulative.length; i++) {
      totalBinSum += h.getBinSize(0, i);
    }
    // this is the scale factor for the histogram equalization process
    final float scale = (float) (h.getHighValue(0) - 1 - h.getLowValue(0)) / totalBinSum;
    float sum = 0;
    for (int i = 1; i < cumulative.length; i++) {
      sum += h.getBinSize(0, i - 1);
      cumulative[i] = (byte) ((sum * scale + h.getLowValue(0)) + .5F);
    }
    return generateLookupTableByte(cumulative);
  }
},

代码示例来源:origin: geosolutions-it/jai-ext

/**
 * Override the default bin width (for plotting)
 */
public void setBinWidth(int newWidth)
{
  binWidth = newWidth;
  width = histogram.getNumBins(0) * binWidth;
}

代码示例来源:origin: bcdev/beam

/**
 * @return The number of bins.
 */
public int getHistogramBinCount() {
  return histogram.getNumBins(0);
}

代码示例来源:origin: it.geosolutions.jaiext.utilities/jt-utilities

/**
 * Override the default bin width (for plotting)
 */
public void setBinWidth(int newWidth)
{
  binWidth = newWidth;
  width = histogram.getNumBins(0) * binWidth;
}

代码示例来源:origin: it.geosolutions.jaiext.utilities/jt-utilities

private void setHistogram(Histogram histogram)
{
  this.histogram = histogram;
  if(histogram != null) {
    // Calculate the components dimensions.
    width = histogram.getNumBins(0) * binWidth;
    // Get the histogram data.
    counts = histogram.getBins(0);
    // Get the max and min counts.
    maxCount = Integer.MIN_VALUE;
    for (int c = 0; c < counts.length; c++)
    {
      maxCount = Math.max(maxCount, counts[c]);
    }
  }
  repaint();
}

代码示例来源:origin: bcdev/beam

/**
 * Returns the width of the bin cells in the given histogram.
 *
 * @param histogram The histogram to inquire the bin cell width of.
 * @return The width of the bin cells in the histogram.
 */
public static double getBinWidth(Histogram histogram) {
  return (histogram.getHighValue(0) - histogram.getLowValue(0)) / histogram.getNumBins(0);
}

代码示例来源:origin: senbox-org/snap-desktop

static double getBinSize(Histogram histogram) {
  return (histogram.getHighValue(0) - histogram.getLowValue(0)) / histogram.getNumBins(0);
}

代码示例来源:origin: bcdev/beam

static double getBinSize(Histogram histogram) {
  return (histogram.getHighValue(0) - histogram.getLowValue(0)) / histogram.getNumBins(0);
}

代码示例来源:origin: geosolutions-it/jai-ext

private void setHistogram(Histogram histogram)
{
  this.histogram = histogram;
  if(histogram != null) {
    // Calculate the components dimensions.
    width = histogram.getNumBins(0) * binWidth;
    // Get the histogram data.
    counts = histogram.getBins(0);
    // Get the max and min counts.
    maxCount = Integer.MIN_VALUE;
    for (int c = 0; c < counts.length; c++)
    {
      maxCount = Math.max(maxCount, counts[c]);
    }
  }
  repaint();
}

代码示例来源:origin: bcdev/beam

/**
 * Gets the (exclusive) maximum value of the histogram bin given by the bin index.
 * <p/>
 * The value returned is in units of the image samples,
 * {@link #getHistogramScaling() histogram scaling} is already applied
 *
 * @param binIndex The bin index.
 * @return The (exclusive) maximum value of the bin given by the bin index.
 */
public double getHistogramBinMaximum(int binIndex) {
  double value = binIndex < histogram.getNumBins(0) ? histogram.getBinLowValue(0, binIndex + 1) : histogram.getHighValue(0);
  return histogramScaling.scaleInverse(value);
}

代码示例来源:origin: bcdev/beam

private static Histogram getBeamHistogram(RenderedOp histogramImage) {
  javax.media.jai.Histogram jaiHistogram = JAIUtils.getHistogramOf(histogramImage);
    int[] bins = jaiHistogram.getBins(0);
  int minIndex = 0;
  int maxIndex = bins.length - 1;
  for (int i = 0; i < bins.length; i++) {
    if (bins[i] > 0) {
      minIndex = i;
      break;
    }
  }
  for (int i = bins.length - 1; i >= 0; i--) {
    if (bins[i] > 0) {
      maxIndex = i;
      break;
    }
  }
  double lowValue = jaiHistogram.getLowValue(0);
  double highValue = jaiHistogram.getHighValue(0);
  int numBins = jaiHistogram.getNumBins(0);
  double binWidth = (highValue - lowValue) / numBins;
  int[] croppedBins = new int[maxIndex - minIndex + 1];
  System.arraycopy(bins, minIndex, croppedBins, 0, croppedBins.length);
  return new Histogram(croppedBins, lowValue + minIndex * binWidth, lowValue
      + (maxIndex + 1.0) * binWidth);
}

代码示例来源:origin: bcdev/beam

/**
 * Creates an equalization CDF image.
 */
public static RenderedOp createHistogramEqualizedImage(PlanarImage sourceImage) {
  int numBands = sourceImage.getSampleModel().getNumBands();
  Histogram histogram = getHistogramOf(sourceImage);
  if (histogram == null) {
    sourceImage = createHistogramImage(sourceImage, 256);
    histogram = getHistogramOf(sourceImage);
  }
  // Create an equalization CDF.
  float[][] eqCDF = new float[numBands][];
  for (int b = 0; b < numBands; b++) {
    int binCount = histogram.getNumBins(b);
    eqCDF[b] = new float[binCount];
    for (int i = 0; i < binCount; i++) {
      eqCDF[b][i] = (float) (i + 1) / (float) binCount;
    }
  }
  // Create a histogram-equalized image.
  return JAI.create("matchcdf", sourceImage, eqCDF);
}

代码示例来源:origin: bcdev/beam

private static PlanarImage createMatchCdfEqualizeImage(PlanarImage sourceImage, Stx[] stxs) {
  Assert.notNull(sourceImage, "sourceImage");
  Assert.notNull(stxs, "stxs");
  int numBands = sourceImage.getSampleModel().getNumBands();
  Assert.argument(stxs.length == numBands, "stxs");
  final Histogram histogram = createHistogram(sourceImage, stxs);
  // Create an equalization CDF.
  float[][] eqCDF = new float[numBands][];
  for (int b = 0; b < numBands; b++) {
    int binCount = histogram.getNumBins(b);
    eqCDF[b] = new float[binCount];
    for (int i = 0; i < binCount; i++) {
      eqCDF[b][i] = (float) (i + 1) / (float) binCount;
    }
  }
  return MatchCDFDescriptor.create(sourceImage, eqCDF, createDefaultRenderingHints(sourceImage, null));
}

代码示例来源:origin: bcdev/beam

@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());
}

代码示例来源:origin: bcdev/beam

@Test
public void testMinMaxBinsLogHistogramWithNegativeMinimum() throws Exception {
  StxFactory factory = new StxFactory();
  factory
      .withMinimum(-10)
      .withMaximum(+10)
      .withLogHistogram(true)
      .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1});
  Stx stx = factory.create();
  assertEquals(-10, stx.getMinimum(), 1e-10);
  assertEquals(+10, stx.getMaximum(), 1e-10);
  assertEquals(0.0, stx.getMean(), 1e-3);
  assertEquals(0.0, stx.getMedian(), 1e-3);
  assertNotNull(stx.getHistogram());
  assertEquals(1, stx.getHistogram().getNumBands());
  assertEquals(8, stx.getHistogram().getNumBins()[0]);
  assertEquals(-9.0, stx.getHistogram().getLowValue(0), 1e-10); // 1E-9 is the max value we handle
  assertEquals(1.0, stx.getHistogram().getHighValue(0), 1e-10);
  assertArrayEquals(new int[]{1, 2, 3, 6, 6, 3, 2, 1}, stx.getHistogramBins());
}

代码示例来源:origin: bcdev/beam

@Test
public void testMinMaxBins() throws Exception {
  StxFactory factory = new StxFactory();
  factory
      .withMinimum(-1.0)
      .withMaximum(1.0)
      .withHistogramBins(new int[]{1, 2, 3, 6, 6, 3, 2, 1});
  Stx stx = factory.create();
  assertEquals(-1.0, stx.getMinimum(), 1e-10);
  assertEquals(1.0, stx.getMaximum(), 1e-10);
  assertEquals(-0.125, stx.getMean(), 1e-10);
  assertEquals(0.0, stx.getMedian(), 1e-10);
  assertNotNull(stx.getHistogram());
  assertEquals(1, stx.getHistogram().getNumBands());
  assertEquals(8, stx.getHistogram().getNumBins()[0]);
  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());
}

代码示例来源:origin: bcdev/beam

@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());
}

代码示例来源:origin: bcdev/beam

@Test
public void testMinIsMax() throws Exception {
  StxFactory factory = new StxFactory();
  factory
      .withMinimum(0)
      .withMaximum(0)
      .withHistogramBins(new int[]{1000, 0, 0, 0, 0, 0, 0, 0});
  Stx stx = factory.create();
  assertEquals(0, stx.getMinimum(), 1e-10);
  assertEquals(0, stx.getMaximum(), 1e-10);
  assertEquals(0, stx.getMean(), 1e-10);
  assertEquals(0, stx.getMedian(), 1e-10);
  assertNotNull(stx.getHistogram());
  assertEquals(1, stx.getHistogram().getNumBands());
  assertEquals(8, stx.getHistogram().getNumBins()[0]);
  assertEquals(0, stx.getHistogram().getLowValue(0), 1E-10);
  assertEquals(1.0E-10, stx.getHistogram().getHighValue(0), 1E-10);
  assertTrue(stx.getHistogram().getLowValue(0) < stx.getHistogram().getHighValue(0));
  assertArrayEquals(new int[]{1000, 0, 0, 0, 0, 0, 0, 0}, stx.getHistogramBins());
}

代码示例来源:origin: bcdev/beam

@Test
public void testMinAndMaxAreTheSameVeryLargeNegativeValue() throws Exception {
  double aLargeNegativeValue = -Double.MAX_VALUE;
  double aSlightlyLargerValue = Math.nextUp(aLargeNegativeValue);
  StxFactory factory = new StxFactory();
  factory
      .withMinimum(aLargeNegativeValue)
      .withMaximum(aLargeNegativeValue)
      .withHistogramBins(new int[]{1000, 0, 0, 0, 0, 0, 0, 0});
  Stx stx = factory.create();
  assertEquals(aLargeNegativeValue, stx.getMinimum(), 1e-10);
  assertEquals(aLargeNegativeValue, stx.getMaximum(), 1e-10);
  assertEquals(aLargeNegativeValue, stx.getMean(), 1e-10);
  assertEquals(aLargeNegativeValue, stx.getMedian(), 1e-10);
  assertNotNull(stx.getHistogram());
  assertEquals(1, stx.getHistogram().getNumBands());
  assertEquals(8, stx.getHistogram().getNumBins()[0]);
  assertEquals(aLargeNegativeValue, stx.getHistogram().getLowValue(0), 1E-10);
  assertEquals(aSlightlyLargerValue, stx.getHistogram().getHighValue(0), 1E-10);
  assertTrue(stx.getHistogram().getLowValue(0) < stx.getHistogram().getHighValue(0));
  assertArrayEquals(new int[]{1000, 0, 0, 0, 0, 0, 0, 0}, stx.getHistogramBins());
}

代码示例来源:origin: bcdev/beam

@Test
public void testMinAndMaxAreTheSameVeryLargePositiveValue() throws Exception {
  double aLargePositiveValue = Double.MAX_VALUE;
  double aSlightlySmallerValue = Math.nextAfter(aLargePositiveValue, Double.NEGATIVE_INFINITY);
  StxFactory factory = new StxFactory();
  factory
      .withMinimum(aLargePositiveValue)
      .withMaximum(aLargePositiveValue)
      .withHistogramBins(new int[]{1000, 0, 0, 0, 0, 0, 0, 0});
  Stx stx = factory.create();
  assertEquals(aLargePositiveValue, stx.getMinimum(), 1e-10);
  assertEquals(aLargePositiveValue, stx.getMaximum(), 1e-10);
  assertEquals(aLargePositiveValue, stx.getMean(), 1e-10);
  assertEquals(aLargePositiveValue, stx.getMedian(), 1e-10);
  assertNotNull(stx.getHistogram());
  assertEquals(1, stx.getHistogram().getNumBands());
  assertEquals(8, stx.getHistogram().getNumBins()[0]);
  assertEquals(aSlightlySmallerValue, stx.getHistogram().getLowValue(0), 1E-10);
  assertEquals(aLargePositiveValue, stx.getHistogram().getHighValue(0), 1E-10);
  assertTrue(stx.getHistogram().getLowValue(0) < stx.getHistogram().getHighValue(0));
  assertArrayEquals(new int[]{1000, 0, 0, 0, 0, 0, 0, 0}, stx.getHistogramBins());
}

相关文章