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

The following examples show how to use ij.process.ImageProcessor#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: ThresholderOrbit.java    From orbit-image-analysis with GNU General Public License v3.0 6 votes vote down vote up
void convertToByte(ImagePlus imp) {
	ImageProcessor ip;
	int currentSlice =  imp.getCurrentSlice();
	ImageStack stack1 = imp.getStack();
	ImageStack stack2 = imp.createEmptyStack();
	int nSlices = imp.getStackSize();
	String label;
	for(int i=1; i<=nSlices; i++) {
		label = stack1.getSliceLabel(i);
		ip = stack1.getProcessor(i);
		ip.setMinAndMax(0, 255);
		stack2.addSlice(label, ip.convertToByte(true));
	}
	imp.setStack(null, stack2);
	imp.setSlice(currentSlice);
	imp.setCalibration(imp.getCalibration()); //update calibration
}
 
Example 2
Source File: Stitching_2D.java    From Stitching with GNU General Public License v2.0 6 votes vote down vote up
private ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max)
{
	int width = image.width;
	int height = image.height;

	ImagePlus impResult = IJ.createImage(name, "32-Bit Black", width, height, 1);
	ImageProcessor ipResult = impResult.getProcessor();
	float[] sliceImg = new float[width * height];

	for (int x = 0; x < width; x++)
		for (int y = 0; y < height; y++)
			sliceImg[y * width + x] = image.get(x, y);

	ipResult.setPixels(sliceImg);

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

	impResult.updateAndDraw();

	return impResult;
}
 
Example 3
Source File: Patch.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
final public Image createImage(final double min, final double max) {
	final ImageProcessor ip = target;
	ip.setMinAndMax(min, max);
	ByteProcessor alpha_mask = mask; // can be null;
	final ByteProcessor outside_mask = outside; // can be null
	if (null == alpha_mask) {
		alpha_mask = outside_mask;
	}
	if (null != alpha_mask) {
		return ImageSaver.createARGBImagePre(
				Loader.embedAlphaPre((int[])ip.convertToRGB().getPixels(),
						(byte[])alpha_mask.getPixels(),
						null == outside_mask ? null : (byte[])outside_mask.getPixels()),
						ip.getWidth(), ip.getHeight());
	} else {
		return ip.createImage();
	}
}
 
Example 4
Source File: ContrastEnhancerWrapper.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param stats_mode can be 0==stack histogram, 1==each image's histogram, and 2==reference Patch histogram.
 *
 **/
public void set(double saturated, boolean normalize, boolean equalize, int stats_mode, boolean use_full_stack, boolean from_existing_min_and_max, boolean visible_only) throws Exception {
	if (null == reference && 2 == stats_mode) throw new IllegalArgumentException("Need a non-null reference Patch to use 2==stats_mode !");

	this.saturated = saturated;
	set("saturated", saturated);
	this.normalize = normalize;
	set("normalize", normalize);
	this.equalize = equalize;
	set("equalize", equalize);

	this.stats_mode = stats_mode;
	this.use_full_stack = use_full_stack;
	if (from_existing_min_and_max && null != reference) {
		// recreate reference_stats
		ImageProcessor ip = reference.getImageProcessor();
		ip.setMinAndMax(reference.getMin(), reference.getMax());
		reference_stats = ImageStatistics.getStatistics(ip, Measurements.MIN_MAX, reference.getLayer().getParent().getCalibrationCopy());
	}
	this.from_existing_min_and_max = from_existing_min_and_max;
	this.visible_only = visible_only;
}
 
Example 5
Source File: ImageArrayConverter.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
public static ImagePlus DoubleArrayToStack(double[] image, int width, int height, int nstacks, String name, float min, float max)
{
    ImageStack stack = new ImageStack(width, height);

    for (int slice = 0; slice < nstacks; slice++)
    {
        ImagePlus impResult = IJ.createImage("Result", "32-Bit Black", width, height, 1);
        ImageProcessor ipResult = impResult.getProcessor();
        float[] sliceImg = new float[width * height];

        for (int x = 0; x < width; x++)
            for (int y = 0; y < height; y++)
                sliceImg[y * width + x] = (float)image[x + width * (y + slice * height)];

        ipResult.setPixels(sliceImg);

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

        stack.addSlice("Slice " + slice, ipResult);
    }

     return new ImagePlus(name, stack);
}
 
Example 6
Source File: Stitching_3D.java    From Stitching with GNU General Public License v2.0 5 votes vote down vote up
private ImagePlus FloatArrayToStack(FloatArray3D image, String name, float min, float max)
{
	int width = image.width;
	int height = image.height;
	int nstacks = image.depth;

	ImageStack stack = new ImageStack(width, height);

	for (int slice = 0; slice < nstacks; slice++)
	{
		ImagePlus impResult = IJ.createImage("Result", "32-Bit Black", width, height, 1);
		ImageProcessor ipResult = impResult.getProcessor();
		float[] sliceImg = new float[width * height];

		for (int x = 0; x < width; x++)
			for (int y = 0; y < height; y++)
				sliceImg[y * width + x] = image.get(x, y, slice);

		ipResult.setPixels(sliceImg);

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

		stack.addSlice("Slice " + slice, ipResult);
	}

	return new ImagePlus(name, stack);
}
 
Example 7
Source File: ImageArrayConverter.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
public static ImagePlus FloatArrayToStack(FloatArray3D image, String name, float min, float max)
{
    int width = image.width;
    int height = image.height;
    int nstacks = image.depth;

    ImageStack stack = new ImageStack(width, height);

    for (int slice = 0; slice < nstacks; slice++)
    {
        ImagePlus impResult = IJ.createImage("Result", "32-Bit Black", width, height, 1);
        ImageProcessor ipResult = impResult.getProcessor();
        float[] sliceImg = new float[width * height];

        for (int x = 0; x < width; x++)
            for (int y = 0; y < height; y++)
                sliceImg[y * width + x] = image.get(x,y,slice);

        ipResult.setPixels(sliceImg);

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

        stack.addSlice("Slice " + slice, ipResult);
    }

     return new ImagePlus(name, stack);
}
 
Example 8
Source File: ExportUnsignedShort.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
PatchIntensityRange( final Patch patch )
{
	this.patch = patch;
	a = patch.getMax() - patch.getMin();
	final ImageProcessor ip = patch.getImageProcessor();
	ip.resetMinAndMax();
	min = ( ip.getMin() - patch.getMin() ) / a;
	max = ( ip.getMax() - patch.getMin() ) / a;
	ip.setMinAndMax( patch.getMin(), patch.getMax() );
}
 
Example 9
Source File: ShollAnalysisDialog.java    From SNT with GNU General Public License v3.0 4 votes vote down vote up
public ImagePlus makeShollCrossingsImagePlus(final ImagePlus original) {
	final int width = original.getWidth();
	final int height = original.getHeight();
	final int depth = original.getStackSize();
	final Calibration c = original.getCalibration();
	double x_spacing = 1;
	double y_spacing = 1;
	double z_spacing = 1;
	if (c != null) {
		x_spacing = c.pixelWidth;
		y_spacing = c.pixelHeight;
		z_spacing = c.pixelDepth;
	}
	final ImageStack stack = new ImageStack(width, height);
	for (int z = 0; z < depth; ++z) {
		final short[] pixels = new short[width * height];
		for (int y = 0; y < height; ++y) {
			for (int x = 0; x < width; ++x) {
				final double xdiff = x_spacing * x - x_start;
				final double ydiff = y_spacing * y - y_start;
				final double zdiff = z_spacing * z - z_start;
				final double distanceSquared = xdiff * xdiff + ydiff * ydiff + zdiff * zdiff;
				pixels[y * width + x] = (short) crossingsAtDistanceSquared(distanceSquared);
			}
		}
		final ShortProcessor sp = new ShortProcessor(width, height);
		sp.setPixels(pixels);
		stack.addSlice("", sp);
	}
	final ImagePlus result = new ImagePlus(description, stack);
	result.show();
	final IndexColorModel icm = FindConnectedRegions.backgroundAndSpectrum(255);
	stack.setColorModel(icm);
	final ImageProcessor ip = result.getProcessor();
	if (ip != null) {
		ip.setColorModel(icm);
		ip.setMinAndMax(0, maxCrossings);
	}
	result.updateAndDraw();

	if (c != null)
		result.setCalibration(c);
	return result;
}
 
Example 10
Source File: UrlMipmapSource.java    From render with GNU General Public License v2.0 4 votes vote down vote up
private void setMinAndMaxIntensity(final ImageProcessor imageProcessor,
                                   final ChannelSpec channelSpec) {
    final double minChannelIntensity = (renderMinIntensity == null) ? channelSpec.getMinIntensity() : renderMinIntensity;
    final double maxChannelIntensity = (renderMaxIntensity == null) ? channelSpec.getMaxIntensity() : renderMaxIntensity;
    imageProcessor.setMinAndMax(minChannelIntensity, maxChannelIntensity);
}
 
Example 11
Source File: DefaultMinAndMax.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ImageProcessor process(final ImageProcessor ip) {
	ip.setMinAndMax(0, ShortProcessor.class == ip.getClass() ? 65535 : 255);
	return ip;
}