Java Code Examples for ij.process.FloatProcessor#setMinAndMax()

The following examples show how to use ij.process.FloatProcessor#setMinAndMax() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DistanceTransform5x5Float.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes the distance map of the distance to the nearest pixel with a different value.
 * The function returns a new short processor the same size as the input,
 * with values greater or equal to zero.
 * 
 * @param labelImage a label image with black pixels (0) as foreground
 * @return a new instance of FloatProcessor containing: <ul>
 * <li> 0 for each background pixel </li>
 * <li> the (strictly positive) distance to the nearest background pixel otherwise</li>
 * </ul>
 */
public FloatProcessor distanceMap(ImageProcessor labelImage) 
{
	FloatProcessor distMap = initializeResult(labelImage);
	
	// Two iterations are enough to compute distance map to boundary
	forwardScan(distMap, labelImage);
	backwardScan(distMap, labelImage);

	// Normalize values by the first weight
	if (this.normalizeMap)
	{
		normalizeResult(distMap, labelImage);
	}

	// Compute max value within the mask for setting min/max of ImageProcessor
	double maxVal = LabelValues.maxValueWithinLabels(distMap, labelImage);
	distMap.setMinAndMax(0, maxVal);

	// Forces the display to non-inverted LUT
	if (distMap.isInvertedLut())
		distMap.invertLut();

	this.fireStatusChanged(new AlgoEvent(this, ""));

	return distMap;
}
 
Example 2
Source File: DistanceTransform3x3Float.java    From MorphoLibJ with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Computes the distance map of the distance to the nearest pixel with a
 * different value. The function returns a new short processor the same size
 * as the input, with values greater or equal to zero.
 * 
 * @param labelImage
 *            a label image with black pixels (0) as foreground
 * @return a new instance of FloatProcessor containing:
 *         <ul>
 *         <li>0 for each background pixel</li>
 *         <li>the (strictly positive) distance to the nearest background
 *         pixel otherwise</li>
 *         </ul>
 */
public FloatProcessor distanceMap(ImageProcessor labelImage) 
{
	// Initialize result
	FloatProcessor distMap = initializeResult(labelImage);
	
	// Two iterations are enough to compute distance map to boundary
	forwardScan(distMap, labelImage);
	backwardScan(distMap, labelImage);

	// Normalize values by the first weight
	if (this.normalizeMap)
	{
		normalizeResult(distMap, labelImage);
	}

	// Compute max value within the mask for setting min/max of ImageProcessor
	double maxVal = LabelValues.maxValueWithinLabels(distMap, labelImage);
	distMap.setMinAndMax(0, maxVal);

	// Forces the display to non-inverted LUT
	if (distMap.isInvertedLut())
		distMap.invertLut();

	this.fireStatusChanged(new AlgoEvent(this, ""));

	return distMap;
}
 
Example 3
Source File: DownsamplerTest.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final private static void testFloat( FloatProcessor ipFloat )
{
	final double min = ipFloat.getMin();
	final double max = ipFloat.getMax();
	
	while( ipFloat.getWidth() > 32 )
	{
		ipFloat = Downsampler.downsampleFloatProcessor( ipFloat );
		ipFloat.setMinAndMax( min, max );
	}
}
 
Example 4
Source File: ImageArrayConverter.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public static ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max)
{
    ImagePlus imp = IJ.createImage(name,"32-Bit Black", image.width, image.height, 1);
    FloatProcessor ip = (FloatProcessor)imp.getProcessor();
    FloatArrayToFloatProcessor(ip, image);

    if (min == max)
        ip.resetMinAndMax();
    else
        ip.setMinAndMax(min, max);

    imp.updateAndDraw();

    return imp;
}
 
Example 5
Source File: RenderRawTileTest.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testRender() throws Exception {

    final ImageAndMask imageWithoutMask = new ImageAndMask("src/test/resources/raw-tile-test/raw-tile.png", null);
    final ImageProcessorCache imageProcessorCache = new ImageProcessorCache();

    final ImageProcessor rawIp = imageProcessorCache.get(imageWithoutMask.getImageUrl(), 0, false, false);
    final FloatProcessor floatRawIp = rawIp.convertToFloatProcessor();
    floatRawIp.setMinAndMax(0, 255);
    final BufferedImage rawImage =
            ArgbRenderer.targetToARGBImage(new TransformMeshMappingWithMasks.ImageProcessorWithMasks(floatRawIp, null, null),
                                           false);

    final ChannelSpec channelSpec = new ChannelSpec();
    channelSpec.putMipmap(0, imageWithoutMask);

    final TileSpec tileSpec = new TileSpec();
    tileSpec.addChannel(channelSpec);

    final RenderParameters tileRenderParameters =
            new RenderParameters(null, 0, 0, rawIp.getWidth(), rawIp.getHeight(), 1.0);

    tileRenderParameters.addTileSpec(tileSpec);
    tileRenderParameters.setSkipInterpolation(true);

    final BufferedImage renderedImage = tileRenderParameters.openTargetImage();

    ArgbRenderer.render(tileRenderParameters,
                        renderedImage,
                        imageProcessorCache);

    Assert.assertEquals("bad rendered image width",
                        rawImage.getWidth(), renderedImage.getWidth());

    Assert.assertEquals("bad rendered image height",
                        rawImage.getHeight(), renderedImage.getHeight());

    for (int x = 0; x < rawImage.getWidth(); x++) {
        for (int y = 0; y < rawImage.getHeight(); y++) {
            Assert.assertEquals("bad rendered pixel at (" + x + ", " + y + ")",
                                rawImage.getRGB(x, y), renderedImage.getRGB(x, y));
        }
    }
}
 
Example 6
Source File: NonLinearTransform.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
public void visualizeSmall(final double lambda){
	final int density = Math.max(width,height)/32;

	final double[][] orig = new double[2][width *  height];
	final double[][] trans = new double[2][height * width];

	final FloatProcessor magnitude = new FloatProcessor(width, height);

	final GeneralPath quiverField = new GeneralPath();

	float minM = 1000, maxM = 0;
	final float minArc = 5, maxArc = -6;
	final int countVert = 0;
	int countHor = 0;
	final int countHorWhole = 0;

	for (int i=0; i < width; i++){
		countHor = 0;
		for (int j=0; j < height; j++){
			final double[] position = {(double) i,(double) j};
			final double[] posExpanded = kernelExpand(position);
			final double[] newPosition = multiply(beta, posExpanded);

			orig[0][i*j] = position[0];
			orig[1][i*j] = position[1];

			trans[0][i*j] = newPosition[0];
			trans[1][i*j] = newPosition[1];

			double m = (position[0] - newPosition[0]) * (position[0] - newPosition[0]);
			m += (position[1] - newPosition[1]) * (position[1] - newPosition[1]);
			m = Math.sqrt(m);
			magnitude.setf(i,j, (float) m);
			minM = Math.min(minM, (float) m);
			maxM = Math.max(maxM, (float) m);

			if (i%density == 0 && j%density == 0)
				drawQuiverField(quiverField, position[0], position[1], newPosition[0], newPosition[1]);
		}
	}

	magnitude.setMinAndMax(minM, maxM);
	final ImagePlus quiverImg = new ImagePlus("Quiver Plot for lambda = "+lambda, magnitude);
	quiverImg.show();
	quiverImg.getCanvas().setDisplayList(quiverField, Color.green, null );
	quiverImg.updateAndDraw();

	System.out.println("FINISHED");
}