Java Code Examples for net.imagej.axis.CalibratedAxis#type()

The following examples show how to use net.imagej.axis.CalibratedAxis#type() . 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: ImgOpener.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Returns a list of all AxisTypes that should be split out. This is a list of
 * all non-X,Y planar axes. Always tries to split {@link Axes#CHANNEL}.
 */
private AxisType[] axesToSplit(final ReaderFilter r) {
	final Set<AxisType> axes = new HashSet<>();
	final Metadata meta = r.getTail().getMetadata();
	// Split any non-X,Y axis
	for (final CalibratedAxis t : meta.get(0).getAxesPlanar()) {
		final AxisType type = t.type();
		if (!(type == Axes.X || type == Axes.Y)) {
			axes.add(type);
		}
	}
	// Ensure channel is attempted to be split
	axes.add(Axes.CHANNEL);
	return axes.toArray(new AxisType[axes.size()]);
}
 
Example 2
Source File: ICSFormat.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void setDest(final DataHandle<Location> out, final int imageIndex,
	final SCIFIOConfig config) throws FormatException, IOException
{
	final String currentId = getMetadata().idsId != null ? getMetadata().idsId
		: getMetadata().icsId;

	super.setDest(out, imageIndex, config);

	if (out.length() == 0) {
		out.writeBytes("\t\n");
		if (FormatTools.checkSuffix(currentId, "ids")) {
			out.writeBytes("ics_version\t1.0\n");
		}
		else {
			out.writeBytes("ics_version\t2.0\n");
		}
		out.writeBytes("filename\t" + currentId + "\n");
		out.writeBytes("layout\tparameters\t6\n");

		final Metadata meta = getMetadata();
		// SCIFIOMetadataTools.verifyMinimumPopulated(meta, pixels);

		final int pixelType = meta.get(imageIndex).getPixelType();

		dimensionOffset = out.offset();
		final int[] sizes = overwriteDimensions(meta, imageIndex);
		dimensionLength = (int) (out.offset() - dimensionOffset);

		if (getValidBits() != 0) {
			out.writeBytes("layout\tsignificant_bits\t" + getValidBits() + "\n");
		}

		final boolean signed = FormatTools.isSigned(pixelType);
		final boolean littleEndian = meta.get(imageIndex).isLittleEndian();

		out.writeBytes("representation\tformat\t" +
			(pixelType == FormatTools.FLOAT ? "real\n" : "integer\n"));
		out.writeBytes("representation\tsign\t" + (signed ? "signed\n"
			: "unsigned\n"));
		out.writeBytes("representation\tcompression\tuncompressed\n");
		out.writeBytes("representation\tbyte_order\t");
		for (int i = 0; i < sizes[0] / 8; i++) {
			if ((littleEndian && (sizes[0] < 32 ||
				pixelType == FormatTools.FLOAT)) || (!littleEndian &&
					sizes[0] >= 32 && pixelType != FormatTools.FLOAT))
			{
				out.writeBytes((i + 1) + "\t");
			}
			else {
				out.writeBytes(((sizes[0] / 8) - i) + "\t");
			}
		}

		out.writeBytes("\nparameter\tscale\t1.000000\t");

		final StringBuilder units = new StringBuilder();

		for (final CalibratedAxis axis : meta.get(imageIndex).getAxes()) {
			Number value = 1.0;
			if (axis.type() == Axes.X) {
				value = axis.averageScale(0, 1);
			}
			else if (axis.type() == Axes.Y) {
				value = axis.averageScale(0, 1);
			}
			else if (axis.type() == Axes.Z) {
				value = axis.averageScale(0, 1);
			}
			else if (axis.type() == Axes.TIME) {
				value = axis.averageScale(0, 1);
			}
			units.append(axis.unit() + "\t");
			out.writeBytes(value + "\t");
		}

		out.writeBytes("\nparameter\tunits\tbits\t" + units.toString() + "\n");
		out.writeBytes("\nend\n");
		pixelOffset = out.offset();
	}
	else if (FormatTools.checkSuffix(currentId, "ics")) {
		try (DataHandle<Location> tmpin = dataHandleService.create(out.get())) {
			tmpin.findString("\nend\n");
			pixelOffset = tmpin.offset();
		}
	}

	if (FormatTools.checkSuffix(currentId, "ids")) {
		pixelOffset = 0;
	}

	if (pixels == null) {
		pixels = dataHandleService.create(out.get());
	}
}
 
Example 3
Source File: ICSFormat.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private int[] overwriteDimensions(final Metadata meta, final int imageIndex)
	throws IOException
{
	getHandle().seek(dimensionOffset);
	// final int sizeX = (int) meta.getAxisLength(imageIndex, Axes.X);
	// final int sizeY = (int) meta.getAxisLength(imageIndex, Axes.Y);
	// final int z = (int) meta.getAxisLength(imageIndex, Axes.Z);
	// final int c = (int) meta.getAxisLength(imageIndex, Axes.SPECTRA);
	// final int t = (int) meta.getAxisLength(imageIndex, Axes.TIME);
	final int pixelType = meta.get(imageIndex).getPixelType();
	final int bytesPerPixel = FormatTools.getBytesPerPixel(pixelType);

	final StringBuilder dimOrder = new StringBuilder();
	final int[] sizes = new int[6];
	int nextSize = 0;
	sizes[nextSize++] = 8 * bytesPerPixel;

	if (meta.get(imageIndex).isMultichannel()) {
		dimOrder.append("ch\t");
		sizes[nextSize++] = (int) (meta.get(imageIndex).getAxisLength(
			Axes.CHANNEL));
	}

	for (final CalibratedAxis axis : meta.get(imageIndex).getAxes()) {
		if (axis.type() == Axes.CHANNEL) {
			if (dimOrder.indexOf("ch") == -1) {
				sizes[nextSize++] = (int) meta.get(imageIndex).getAxisLength(
					Axes.CHANNEL);
				dimOrder.append("ch");
			}
			else {
				continue;
			}
		}
		else {
			sizes[nextSize++] = (int) meta.get(imageIndex).getAxisLength(axis
				.type());
			dimOrder.append(String.valueOf(axis.type().getLabel().charAt(0))
				.toLowerCase());
		}
		dimOrder.append("\t");
	}
	getHandle().writeBytes("layout\torder\tbits\t" + dimOrder.toString() +
		"\n");
	getHandle().writeBytes("layout\tsizes\t");
	for (final int size : sizes) {
		getHandle().writeBytes(size + "\t");
	}
	while ((getHandle().offset() - dimensionOffset) < dimensionLength - 1) {
		getHandle().writeBytes(" ");
	}
	getHandle().writeBytes("\n");

	return sizes;
}