Example #1
0
  protected void computeAdvanced(final long startPos, final long loopSize) {
    final LocalizableByDimCursor<S> cursorIn = image.createLocalizableByDimCursor();
    final LocalizableCursor<T> cursorOut = output.createLocalizableCursor();

    // move to the starting position of the current thread
    cursorOut.fwd(startPos);

    // do as many pixels as wanted by this thread
    for (long j = 0; j < loopSize; ++j) {
      cursorOut.fwd();
      cursorIn.setPosition(cursorOut);

      converter.convert(cursorIn.getType(), cursorOut.getType());
    }

    cursorIn.close();
    cursorOut.close();
  }
Example #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();
  }
Example #3
0
  @Override
  public boolean process() {

    // 0. Prepare new dimensions

    int downSamplingFactor = settings.downSamplingFactor;
    int[] dimensions = new int[img.getNumDimensions()];
    int[] dsarr = new int[img.getNumDimensions()];
    float[] dwnCalibration = new float[img.getNumDimensions()];
    for (int i = 0; i < 2; i++) {
      dimensions[i] = img.getDimension(i) / downSamplingFactor;
      dsarr[i] = downSamplingFactor;
      dwnCalibration[i] = calibration[i] * downSamplingFactor;
    }
    if (img.getNumDimensions() > 2) {
      // 3D
      float zratio = calibration[2] / calibration[0]; // Z spacing is how much bigger
      int zdownsampling = (int) (downSamplingFactor / zratio); // temper z downsampling
      zdownsampling = Math.max(1, zdownsampling); // but at least 1
      dimensions[2] = img.getDimension(2) / zdownsampling;
      dsarr[2] = zdownsampling;
      dwnCalibration[2] = calibration[2] * zdownsampling;
    }

    // 1. Downsample the image

    Image<T> downsampled = img.createNewImage(dimensions);
    LocalizableCursor<T> dwnCursor = downsampled.createLocalizableCursor();
    LocalizableByDimCursor<T> srcCursor = img.createLocalizableByDimCursor();
    int[] pos = dwnCursor.createPositionArray();

    while (dwnCursor.hasNext()) {
      dwnCursor.fwd();
      dwnCursor.getPosition(pos);

      // Scale up position
      for (int i = 0; i < pos.length; i++) {
        pos[i] = pos[i] * dsarr[i];
      }

      // Pass it to source cursor
      srcCursor.setPosition(pos);

      // Copy pixel data
      dwnCursor.getType().set(srcCursor.getType());
    }
    dwnCursor.close();
    srcCursor.close();

    // 2. Segment downsampled image

    // 2.1. Create settings object
    LogSegmenterSettings logSettings = new LogSegmenterSettings();
    logSettings.expectedRadius = settings.expectedRadius;
    logSettings.threshold = settings.threshold;
    logSettings.doSubPixelLocalization = true;
    ;
    logSettings.useMedianFilter = settings.useMedianFilter;

    // 2.2 Instantiate segmenter
    LogSegmenter<T> segmenter = new LogSegmenter<T>();
    segmenter.setTarget(downsampled, dwnCalibration, logSettings);

    // 2.3 Execute segmentation
    if (!segmenter.checkInput() || !segmenter.process()) {
      errorMessage = BASE_ERROR_MESSAGE + segmenter.getErrorMessage();
      return false;
    }

    // 3. Benefits
    spots = segmenter.getResult();

    return true;
  }