@Override public boolean checkInput() { if (errorMessage.length() > 0) { return false; } else if (image == null) { errorMessage = "ImageCalculator: [Image<S> image1] is null."; return false; } else if (output == null) { errorMessage = "ImageCalculator: [Image<T> output] is null."; return false; } else if (converter == null) { errorMessage = "ImageCalculator: [Converter<S,T>] is null."; return false; } else if (!image.getContainer().compareStorageContainerDimensions(output.getContainer())) { errorMessage = "ImageCalculator: Images have different dimensions, not supported:" + " Image: " + Util.printCoordinates(image.getDimensions()) + " Output: " + Util.printCoordinates(output.getDimensions()); return false; } else return true; }
/** * 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(); }
@Override public String getPositionAsString() { return Util.printCoordinates(getPosition()); }