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

The following examples show how to use ij.process.ImageProcessor#convertToFloat() . 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: SquareStrelTiming.java    From MorphoLibJ with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void timingLeafImage_Float() {
	ImageProcessor image = getLeafImage();
	assertNotNull(image);
	
	int[] sizeArray = new int[]{3, 5, 7, 9, 11, 15, 21, 31, 51, 71, 101};
	double[] timingArray = new double[sizeArray.length];

	image = image.convertToFloat();
	
	System.out.println("Dilation using float image");
	
	for (int i = 0; i < sizeArray.length; i++)
	{
		Strel strel = SquareStrel.fromDiameter(sizeArray[i]);
		long t0 = System.currentTimeMillis();
		strel.dilation(image);
		long t1 = System.currentTimeMillis();
		timingArray[i] = (t1 - t0) / 1000.0;
		
		System.out.println(String.format("size = %d: %7.5f s", sizeArray[i], timingArray[i]));
	}
}
 
Example 2
Source File: Utils.java    From TrakEM2 with GNU General Public License v3.0 6 votes vote down vote up
/** Converts the ImageProcessor to an ImageProcessor of the given type, or the same if of equal type. */
static final public ImageProcessor convertTo(final ImageProcessor ip, final int type, final boolean scaling) {
	switch (type) {
		case ImagePlus.GRAY8:
			return ip.convertToByte(scaling);
		case ImagePlus.GRAY16:
			return ip.convertToShort(scaling);
		case ImagePlus.GRAY32:
			return ip.convertToFloat();
		case ImagePlus.COLOR_RGB:
			return ip.convertToRGB();
		case ImagePlus.COLOR_256:
			final ImagePlus imp = new ImagePlus("", ip.convertToRGB());
			new ImageConverter(imp).convertRGBtoIndexedColor(256);
			return imp.getProcessor();
		default:
			return null;
	}
}
 
Example 3
Source File: Utils.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
/** A method that circumvents the findMinAndMax when creating a float processor from an existing processor.  Ignores color calibrations and does no scaling at all. */
static public final FloatProcessor fastConvertToFloat(final ImageProcessor ip, final int type) {
	switch (type) {
		case ImagePlus.GRAY16: return fastConvertToFloat((ShortProcessor)ip);
		case ImagePlus.GRAY32: return (FloatProcessor)ip;
		case ImagePlus.GRAY8:
		case ImagePlus.COLOR_256: return fastConvertToFloat((ByteProcessor)ip);
		case ImagePlus.COLOR_RGB: return (FloatProcessor)ip.convertToFloat(); // SLOW
	}
	return null;
}
 
Example 4
Source File: Utils.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static public final FloatProcessor fastConvertToFloat(final ImageProcessor ip) {
	if (ip instanceof ByteProcessor) return fastConvertToFloat((ByteProcessor)ip);
	if (ip instanceof ShortProcessor) return fastConvertToFloat((ShortProcessor)ip);
	return (FloatProcessor)ip.convertToFloat();
}
 
Example 5
Source File: Distortion_Correction.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
static	double getXcorrBlackOut(ImageProcessor ip1, ImageProcessor ip2){

		ip1 = ip1.convertToFloat();
		ip2 = ip2.convertToFloat();

		//If this is not done, the black area from the transformed image influences xcorr result
		//better alternative would be to use mask images and only calculate xcorr of
		//the region present in both images.
		for (int i=0; i<ip1.getWidth(); i++){
			for (int j=0; j<ip1.getHeight(); j++){
				if (ip1.get(i,j) == 0)
					ip2.set(i,j,0);
				if (ip2.get(i,j) == 0)
					ip1.set(i,j,0);
			}
		}

		//		FloatProcessor ip1f = (FloatProcessor)ip1.convertToFloat();
		//		FloatProcessor ip2f = (FloatProcessor)ip2.convertToFloat();

		final float[] data1 = ( float[] )ip1.getPixels();
		final float[] data2 = ( float[] )ip2.getPixels();

		final double[] data1b = new double[data1.length];
		final double[] data2b = new double[data2.length];

		int count = 0;
		double mean1 = 0.0, mean2 = 0.0;

		for (int i=0; i < data1.length; i++){
			//if ((data1[i] == 0) || (data2[i] == 0))
			//continue;
			data1b[i] = data1[i];
			data2b[i] = data2[i];
			mean1 += data1b[i];
			mean2 += data2b[i];
			count++;
		}

		mean1 /= (double) count;
		mean2 /= (double) count;

		double L2_1 = 0.0, L2_2 = 0.0;
		for (int i=0; i < count; i++){
			L2_1 += (data1b[i] - mean1) * (data1b[i] - mean1);
			L2_2 += (data2b[i] - mean2) * (data2b[i] - mean2);
		}

		L2_1 = Math.sqrt(L2_1);
		L2_2 = Math.sqrt(L2_2);

		double xcorr = 0.0;
		for (int i=0; i < count; i++){
			xcorr += ((data1b[i]-mean1) / L2_1) * ((data2b[i]-mean2) / L2_2);
		}

		//System.out.println("XcorrVal: " + xcorr);
		return xcorr;
	}