コード例 #1
0
 public AbstractSortedGrayLevelIterator(final Image<T> image) {
   this.image = image;
   this.position = image.createPositionArray();
   this.n = image.getNumPixels();
   this.maxIdx = this.n - 1;
   this.dimensions = image.getDimensions();
   createInternalCursor();
   this.sortedLinIdx = getLinearIndexArraySortedByGrayLevel();
   reset();
 }
コード例 #2
0
  /**
   * Return a difference of gaussian image that measures the gradient at a scale defined by the two
   * sigmas of the gaussians.
   *
   * @param image
   * @param sigma1
   * @param sigma2
   * @return
   */
  public Image<FloatType> getGradientImage() {
    /*
     * Create the DoG kernel.
     */
    double[][] kernels1d1 = new double[input.getNumDimensions()][];
    double[][] kernels1d2 = new double[input.getNumDimensions()][];
    int[] kernelDimensions = input.createPositionArray();
    int[] offset = input.createPositionArray();
    for (int i = 0; i < kernels1d1.length; i++) {
      kernels1d1[i] = Util.createGaussianKernel1DDouble(sigma1[i], true);
      kernels1d2[i] = Util.createGaussianKernel1DDouble(sigma2[i], true);
      kernelDimensions[i] = kernels1d1[i].length;
      offset[i] = (kernels1d1[i].length - kernels1d2[i].length) / 2;
    }
    Image<FloatType> kernel = getFloatFactory().createImage(kernelDimensions);
    LocalizableCursor<FloatType> kc = kernel.createLocalizableCursor();
    int[] position = input.createPositionArray();
    for (FloatType t : kc) {
      kc.getPosition(position);
      double value1 = 1;
      double value2 = 1;
      for (int i = 0; i < kernels1d1.length; i++) {
        value1 *= kernels1d1[i][position[i]];
        int position2 = position[i] - offset[i];
        if ((position2 >= 0) && (position2 < kernels1d2[i].length)) {
          value2 *= kernels1d2[i][position2];
        } else {
          value2 = 0;
        }
      }
      t.setReal(value1 - value2);
    }
    kc.close();
    /*
     * Apply the kernel to the image.
     */
    FourierConvolution<FloatType, FloatType> convolution =
        new FourierConvolution<FloatType, FloatType>(getFloatImage(), kernel);
    if (!convolution.process()) return null;
    Image<FloatType> result = convolution.getResult();
    /*
     * Quantize the image.
     */
    ComputeMinMax<FloatType> computeMinMax = new ComputeMinMax<FloatType>(result);
    computeMinMax.process();
    final float min = computeMinMax.getMin().get();
    final float max = computeMinMax.getMax().get();
    if (max == min) return result;

    ImageConverter<FloatType, FloatType> quantizer =
        new ImageConverter<FloatType, FloatType>(
            result,
            result.getImageFactory(),
            new Converter<FloatType, FloatType>() {

              @Override
              public void convert(FloatType input, FloatType output) {
                float value = (input.get() - min) / (max - min);
                value = Math.round(value * 100);
                output.set(value);
              }
            });
    quantizer.process();
    return quantizer.getResult();
  }
コード例 #3
0
 @Override
 public int[] getPosition() {
   int[] position = image.createPositionArray();
   getPosition(position);
   return position;
 }
コード例 #4
0
 @Override
 public int[] createPositionArray() {
   return image.createPositionArray();
 }