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

The following examples show how to use net.imagej.axis.CalibratedAxis#averageScale() . 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: FormatTools.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Gets the average scale over the specified axis of the given image metadata.
 *
 * @return the average scale over the axis's values, or 1.0 if the desired
 *         axis is null.
 */
public static double getScale(final ImageMetadata imageMeta,
	final AxisType axisType)
{
	final CalibratedAxis axis = imageMeta.getAxis(axisType);
	if (axis == null) return 1.0;
	final long axisLength = imageMeta.getAxisLength(axis);
	return axis.averageScale(0, axisLength - 1);
}
 
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: TestImgFormat.java    From scifio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void translateImageMetadata(final List<ImageMetadata> source,
	final Metadata dest)
{
	final ImageMetadata iMeta = source.get(0);

	String name = dest.getDatasetName();

	final String[] axes = new String[iMeta.getAxes().size()];
	final long[] lengths = new long[axes.length];
	final double[] scales = new double[axes.length];
	final String[] units = new String[axes.length];

	int index = 0;
	for (final CalibratedAxis axis : iMeta.getAxes()) {
		axes[index] = axis.type().getLabel();
		lengths[index] = iMeta.getAxisLength(axis);
		scales[index] = axis.averageScale(0, lengths[index]);
		units[index] = axis.unit();
		index++;
	}

	TestImgLocation.Builder b = new Builder();
	b.axes(axes);
	b.lengths(lengths);
	b.scales(scales);
	b.units(units);
	b.planarDims(iMeta.getPlanarAxisCount());
	b.interleavedDims(iMeta.getInterleavedAxisCount());
	b.thumbSizeX((int) iMeta.getThumbSizeX());
	b.thumbSizeY((int) iMeta.getThumbSizeX());
	b.pixelType(FormatTools.getPixelTypeString(iMeta.getPixelType()));
	b.falseColor(iMeta.isFalseColor());
	b.little(iMeta.isLittleEndian());
	b.metadataComplete(iMeta.isMetadataComplete());
	b.thumbnail(iMeta.isThumbnail());

	b.orderCertain(iMeta.isOrderCertain());
	b.images(source.size());

	if (iMeta.isIndexed()) {
		final int lutLength = ((HasColorTable) source).getColorTable(0, 0)
			.getComponentCount();
		b.indexed(iMeta.isIndexed());
		b.lutLength(lutLength);
	}

	try {
		dest.close();
		dest.setSource(dataHandleService.create(b.build()));
	}
	catch (final IOException e) {
		log().debug("Failed to create RAIS: " + name, e);
	}
}