All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ij.io.TextEncoder Maven / Gradle / Ivy

Go to download

ImageJ is an open source Java image processing program inspired by NIH Image for the Macintosh.

There is a newer version: 1.54m
Show newest version
package ij.io;
import java.io.*;
import ij.*;
import ij.process.*;
import ij.measure.*;

/** Saves an image described by an ImageProcessor object as a tab-delimited text file. */
public class TextEncoder {

	private ImageProcessor ip;
	private Calibration cal;
	private int precision;

	/** Constructs a TextEncoder from an ImageProcessor and optional Calibration. */
	public TextEncoder (ImageProcessor ip, Calibration cal, int precision) {
		this.ip = ip;
		this.cal = cal;
		this.precision = precision;
	}

	/** Saves the image as a tab-delimited text file. */
	public void write(DataOutputStream out) throws IOException {
		PrintWriter pw = new PrintWriter(out);
		boolean calibrated = cal!=null && cal.calibrated();
		if (calibrated)
			ip.setCalibrationTable(cal.getCTable());
		else
			ip.setCalibrationTable(null);
		boolean intData = !calibrated && ((ip instanceof ByteProcessor) || (ip instanceof ShortProcessor));
		int width = ip.getWidth();
		int height = ip.getHeight();
		int inc = height/20;
		if (inc<1) inc = 1;
		//IJ.showStatus("Exporting as text...");
		double value;
		for (int y=0; y




© 2015 - 2025 Weber Informatics LLC | Privacy Policy