net.imglib2.converter.Converter Java Examples

The following examples show how to use net.imglib2.converter.Converter. 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: LocalMeanThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final I center,
	final RectangleNeighborhood<Composite<DoubleType>> neighborhood,
	final BitType output)
{

	final DoubleType sum = new DoubleType();
	integralMean.compute(neighborhood, sum);

	// Subtract the contrast
	sum.sub(new DoubleType(c));

	// Set value
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType centerPixelAsDoubleType = new DoubleType();
	conv.convert(center, centerPixelAsDoubleType);

	output.set(centerPixelAsDoubleType.compareTo(sum) > 0);
}
 
Example #2
Source File: ConvertedDataSource.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public ConvertedDataSource(
		final DataSource<D, T> source,
		final Converter<D, U> dataTypeConverter,
		final Converter<T, V> typeConverter,
		final Supplier<U> dataTypeSupplier,
		final Supplier<V> typeSupplier,
		final Function<Interpolation, InterpolatorFactory<U, RandomAccessible<U>>> dataInterpolation,
		final Function<Interpolation, InterpolatorFactory<V, RandomAccessible<V>>> interpolation,
		final String name)
{
	super();
	this.source = source;
	this.dataTypeConverter = dataTypeConverter;
	this.typeConverter = typeConverter;
	this.dataTypeExtensionSupplier = dataTypeSupplier;
	this.typeExtensionSupplier = typeSupplier;
	this.dataInterpolation = dataInterpolation;
	this.interpolation = interpolation;
	this.name = name;
}
 
Example #3
Source File: LocalPhansalkarThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final I center,
	final RectangleNeighborhood<Composite<DoubleType>> neighborhood,
	final BitType output)
{

	final DoubleType mean = new DoubleType();
	integralMean.compute(neighborhood, mean);

	final DoubleType variance = new DoubleType();
	integralVariance.compute(neighborhood, variance);

	final DoubleType stdDev = new DoubleType(Math.sqrt(variance.get()));

	final DoubleType threshold = new DoubleType(mean.getRealDouble() * (1.0d +
		p * Math.exp(-q * mean.getRealDouble()) + k * ((stdDev.getRealDouble() /
			r) - 1.0)));

	// Set value
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType centerPixelAsDoubleType = variance; // NB: Reuse
	// DoubleType
	conv.convert(center, centerPixelAsDoubleType);

	output.set(centerPixelAsDoubleType.compareTo(threshold) > 0);
}
 
Example #4
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static <D extends NativeType<D> & RealType<D>, T extends RealType<T>> RealComposite<T>  createExtension(
		final D d,
		final T t,
		final Converter<D, T> converter,
		final long size,
		IntFunction<D> valueAtIndex
)
{
	LOG.debug("Creating extension with size {}", size);
	final ArrayImg<D, ?> img = new ArrayImgFactory<>(d).create(1, size);
	img.setLinkedType((D) d.getNativeTypeFactory().createLinkedType((NativeImg)img));
	final CompositeIntervalView<D, RealComposite<D>> collapsed = Views.collapseReal(img);
	RealComposite<D> extensionCopy = collapsed.randomAccess().get();
	for (int channel = 0; channel < size; ++channel)
		extensionCopy.get(channel).set(valueAtIndex.apply(channel));
	return Views.collapseReal(Converters.convert((RandomAccessibleInterval<D>)img, converter, t.createVariable())).randomAccess().get();
}
 
Example #5
Source File: LocalSauvolaThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final I center,
	final RectangleNeighborhood<Composite<DoubleType>> neighborhood,
	final BitType output)
{

	final DoubleType mean = new DoubleType();
	integralMean.compute(neighborhood, mean);

	final DoubleType variance = new DoubleType();
	integralVariance.compute(neighborhood, variance);

	final DoubleType stdDev = new DoubleType(Math.sqrt(variance.get()));

	final DoubleType threshold = new DoubleType(mean.getRealDouble() * (1.0d +
		k * ((Math.sqrt(stdDev.getRealDouble()) / r) - 1.0)));

	// Set value
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType centerPixelAsDoubleType = variance; // NB: Reuse
	// DoubleType
	conv.convert(center, centerPixelAsDoubleType);

	output.set(centerPixelAsDoubleType.compareTo(threshold) > 0);
}
 
Example #6
Source File: VolatileHierarchyProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public VolatileHierarchyProjectorPreMultiply(
		final List<? extends RandomAccessible<A>> sources,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final int numThreads,
		final ExecutorService executorService)
{
	this(
			sources,
			converter,
			target,
			ArrayImgs.bytes(Intervals.dimensionsAsLongArray(target)),
			numThreads,
			executorService
	    );
}
 
Example #7
Source File: SegmentMaskGenerators.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public static <T, B extends BooleanType<B>> BiFunction<TLongHashSet, Double, Converter<T, B>> create(
		final DataSource<T, ?> source,
		final int level)
{
	final T t = source.getDataType();

	if (t instanceof LabelMultisetType)
		return new LabelMultisetTypeMaskGenerator(source, level);

	if (t instanceof IntegerType<?>)
	{
		final IntegerTypeMaskGenerator integerTypeMaskGenerator = new IntegerTypeMaskGenerator();
		return (l, minLabelRatio) -> integerTypeMaskGenerator.apply(l);
	}

	return null;
}
 
Example #8
Source File: AbstractMeshCacheLoader.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public AbstractMeshCacheLoader(
		final Supplier<RandomAccessibleInterval<T>> data,
		final BiFunction<K, Double, Converter<T, BoolType>> getMaskGenerator,
		final AffineTransform3D transform)
{
	super();
	LOG.debug("Constructiong {}", getClass().getName());
	this.data = data;
	this.getMaskGenerator = getMaskGenerator;
	this.transform = transform;
}
 
Example #9
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <D extends NativeType<D> & RealType<D>, T extends RealType<T>> RealComposite<T>  createExtension(
		final D d,
		final T t,
		final Converter<D, T> converter,
		final long size
) {
	return createExtension(d, t, converter, size, channel -> d);
}
 
Example #10
Source File: N5ChannelDataSource.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <D extends NativeType<D> & RealType<D>, T extends RealType<T>> RealComposite<T>  copyExtension(
		final RealComposite<D> extension,
		final T t,
		final Converter<D, T> converter,
		final long size
)
{
	return createExtension(extension.get(0).createVariable(), t, converter, size, extension::get);
}
 
Example #11
Source File: SegmentMeshCacheLoader.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public SegmentMeshCacheLoader(
		final Supplier<RandomAccessibleInterval<T>> data,
		final BiFunction<TLongHashSet, Double, Converter<T, BoolType>> getMaskGenerator,
		final AffineTransform3D transform)
{
	super(data, getMaskGenerator, transform);
}
 
Example #12
Source File: SegmentMaskGenerators.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Converter<LabelMultisetType, B> apply(final TLongHashSet validLabels, final Double minLabelRatio)
{
	return minLabelRatio == null || minLabelRatio == 0.0
			? new LabelMultisetTypeMask<>(validLabels)
			: new LabelMultisetTypeMaskWithMinLabelRatio<>(validLabels, minLabelRatio, numFullResPixels);
}
 
Example #13
Source File: HistogramOfOrientedGradients2D.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void initialize() {
	es = ts.getExecutorService();

	createOp = Functions.unary(ops(), CreateImgFromDimsAndType.class, RandomAccessibleInterval.class,
			new FinalInterval(in().dimension(0), in().dimension(1), numOrientations), new FloatType());

	createImgOp = Functions.unary(ops(), CreateImgFromDimsAndType.class, RandomAccessibleInterval.class,
			new FinalInterval(in().dimension(0), in().dimension(1)), new FloatType());

	converterToFloat = new Converter<T, FloatType>() {
		@Override
		public void convert(final T arg0, final FloatType arg1) {
			arg1.setReal(arg0.getRealFloat());
		}
	};

	converterGetMax = new Converter<GenericComposite<FloatType>, FloatType>() {
		@Override
		public void convert(GenericComposite<FloatType> input, FloatType output) {
			int idx = 0;
			float max = 0;
			for (int i = 0; i < in().dimension(2); i++) {
				if (Math.abs(input.get(i).getRealFloat()) > max) {
					max = Math.abs(input.get(i).getRealFloat());
					idx = i;
				}
			}
			output.setReal(input.get(idx).getRealFloat());
		}
	};
}
 
Example #14
Source File: ConvertedRandomAccessibleInterval.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public ConvertedRandomAccessibleInterval(final RandomAccessibleInterval<A> source, final Converter<? super A, ?
		super B> converter, final Supplier<B> b)
{
	super(source);
	this.converter = converter;
	this.supplier = b;
}
 
Example #15
Source File: LocalNiblackThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final I center,
	final RectangleNeighborhood<Composite<DoubleType>> neighborhood,
	final BitType output)
{

	final DoubleType threshold = new DoubleType(0.0d);

	final DoubleType mean = new DoubleType();
	integralMean.compute(neighborhood, mean);

	threshold.add(mean);

	final DoubleType variance = new DoubleType();
	integralVariance.compute(neighborhood, variance);

	final DoubleType stdDev = new DoubleType(Math.sqrt(variance.get()));
	stdDev.mul(k);

	threshold.add(stdDev);

	// Subtract the contrast
	threshold.sub(new DoubleType(c));

	// Set value
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType centerPixelAsDoubleType = variance; // NB: Reuse
	// DoubleType
	conv.convert(center, centerPixelAsDoubleType);

	output.set(centerPixelAsDoubleType.compareTo(threshold) > 0);
}
 
Example #16
Source File: LabelSourceStatePaintHandler.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public LabelSourceStatePaintHandler(
		final MaskedSource<T, ?> source,
		final FragmentSegmentAssignment fragmentSegmentAssignment,
		final BooleanSupplier isVisible,
		final Consumer<FloodFillState> floodFillStateUpdate,
		final SelectedIds selectedIds,
		final LongFunction<Converter<T, BoolType>> maskForLabel) {
	this.source = source;
	this.fragmentSegmentAssignment = fragmentSegmentAssignment;
	this.isVisible = isVisible;
	this.floodFillStateUpdate = floodFillStateUpdate;
	this.selectedIds = selectedIds;
	this.maskForLabel = maskForLabel;
}
 
Example #17
Source File: LabelSourceState.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private static <D> LongFunction<Converter<D, BoolType>> equalsMaskForType(final D d)
{
	if (d instanceof LabelMultisetType) { return (LongFunction) equalMaskForLabelMultisetType(); }

	if (d instanceof IntegerType<?>) { return (LongFunction) equalMaskForIntegerType(); }

	if (d instanceof RealType<?>) { return (LongFunction) equalMaskForRealType(); }

	return null;
}
 
Example #18
Source File: BackgroundCanvasIterable.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Iterator<LabelMultisetType> iterator() {
	return new Iterator<LabelMultisetType>() {

		final Iterator<? extends Pair<LabelMultisetType, UnsignedLongType>> iterator = backgroundAndCanvas.iterator();

		final Converter<UnsignedLongType, LabelMultisetType> conv = new FromIntegerTypeConverter<>();

		final LabelMultisetType type = FromIntegerTypeConverter.getAppropriateType();

		@Override
		public boolean hasNext() {
			return iterator.hasNext();
		}

		@Override
		public LabelMultisetType next() {
			final Pair<LabelMultisetType, UnsignedLongType> p = iterator.next();
			final UnsignedLongType b = p.getB();
			if (Label.regular(b.getIntegerLong())) {
				conv.convert(b, type);
				return type;
			} else
				return p.getA();
		}
	};
}
 
Example #19
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public RestrictPainting(
		final ViewerPanelFX viewer,
		final SourceInfo sourceInfo,
		final Runnable requestRepaint,
		final LongFunction<Converter<?, BoolType>> maskForLabel)
{
	super();
	this.viewer = viewer;
	this.sourceInfo = sourceInfo;
	this.requestRepaint = requestRepaint;
	this.maskForLabel = maskForLabel;
}
 
Example #20
Source File: MinimalSourceStateDeserializer.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
protected MinimalSourceState<?, ?, ?, Converter<?, ARGBType>> makeState(
		final JsonObject map,
		final DataSource<?, ?> source,
		final Composite<ARGBType, ARGBType> composite,
		final Converter<?, ARGBType> converter,
		final String name,
		final SourceState<?, ?>[] dependsOn,
		final JsonDeserializationContext context) throws ClassNotFoundException
{
	return new MinimalSourceState(source, converter, composite, name, dependsOn);
}
 
Example #21
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
SimpleVolatileProjector(
		final RandomAccessible<A> source,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final int numThreads,
		final ExecutorService executorService)
{
	super(source, converter, target, numThreads, executorService);
}
 
Example #22
Source File: VolatileHierarchyProjector.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjector(
		final List< ? extends RandomAccessible< A > > sources,
		final Converter< ? super A, B > converter,
		final RandomAccessibleInterval< B > target,
		final RandomAccessibleInterval< ByteType > mask,
		final int numThreads,
		final ExecutorService executorService )
{
	super( Math.max( 2, sources.get( 0 ).numDimensions() ), converter, target );

	this.sources.addAll( sources );
	numInvalidLevels = sources.size();

	this.mask = mask;

	iterableTarget = Views.iterable( target );

	target.min(min);
	target.max(max);
	sourceInterval = new FinalInterval( min, max );

	width = ( int )target.dimension( 0 );
	height = ( int )target.dimension( 1 );
	cr = -width;

	this.numThreads = numThreads;
	this.executorService = executorService;

	lastFrameRenderNanoTime = -1;
	clearMask();
}
 
Example #23
Source File: VolatileHierarchyProjector.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjector(
		final List< ? extends RandomAccessible< A > > sources,
		final Converter< ? super A, B > converter,
		final RandomAccessibleInterval< B > target,
		final int numThreads,
		final ExecutorService executorService )
{
	this( sources, converter, target, ArrayImgs.bytes( Intervals.dimensionsAsLongArray( target ) ), numThreads, executorService );
}
 
Example #24
Source File: VolatileHierarchyProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjectorPreMultiply(
		final List<? extends RandomAccessible<A>> sources,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final RandomAccessibleInterval<ByteType> mask,
		final int numThreads,
		final ExecutorService executorService)
{
	super(Math.max(2, sources.get(0).numDimensions()), converter, target);

	this.sources.addAll(sources);
	numInvalidLevels = sources.size();

	this.mask = mask;

	iterableTarget = Views.iterable(target);

	target.min(min);
	target.max(max);
	sourceInterval = new FinalInterval(min, max);

	width = (int) target.dimension(0);
	height = (int) target.dimension(1);
	cr = -width;

	this.numThreads = numThreads;
	this.executorService = executorService;

	lastFrameRenderNanoTime = -1;
	clearMask();
}
 
Example #25
Source File: SimpleInterruptibleProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public SimpleInterruptibleProjectorPreMultiply(
		final RandomAccessible<A> source,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final int numThreads,
		final ExecutorService executorService)
{
	super(source.numDimensions(), converter, target);
	this.source = source;
	this.numThreads = numThreads;
	this.executorService = executorService;
	lastFrameRenderNanoTime = -1;
}
 
Example #26
Source File: ConvertedRandomAccess.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public ConvertedRandomAccess(final RandomAccess<A> source, final Converter<? super A, ? super B> converter, final
Supplier<B> b)
{
	super(source);
	this.converter = converter;
	this.supplier = b;
	this.converted = b.get();
}
 
Example #27
Source File: IntegralSum.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final RectangleNeighborhood<I> input,
	final DoubleType output)
{
	// computation according to
	// https://en.wikipedia.org/wiki/Summed_area_table
	final IntegralCursor<I> cursor = new IntegralCursor<>(input);
	final int dimensions = input.numDimensions();

	// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
	final DoubleType sum = new DoubleType();
	sum.setZero();

	// Convert from input to return type
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType valueAsDoubleType = new DoubleType();

	while (cursor.hasNext()) {
		final I value = cursor.next().copy();
		conv.convert(value, valueAsDoubleType);

		// Obtain the cursor position encoded as corner vector
		final int cornerInteger = cursor.getCornerRepresentation();

		// Determine if the value has to be added (factor==1) or subtracted
		// (factor==-1)
		final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions -
			IntegralMean.norm(cornerInteger)));
		valueAsDoubleType.mul(factor);

		sum.add(valueAsDoubleType);
	}

	output.set(sum);
}
 
Example #28
Source File: ConvertedRandomAccessible.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public ConvertedRandomAccessible(final RandomAccessible<A> source, final Converter<? super A, ? super B>
		converter, final Supplier<B> b)
{
	super(source);
	this.converter = converter;
	this.converted = b.get();
	this.supplier = b;
}
 
Example #29
Source File: IntegralVariance.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final RectangleNeighborhood<Composite<I>> input,
	final DoubleType output)
{
	// computation according to
	// https://en.wikipedia.org/wiki/Summed_area_table
	final IntegralCursor<Composite<I>> cursorS1 = new IntegralCursor<>(input);
	final int dimensions = input.numDimensions();

	// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
	final DoubleType sum1 = new DoubleType();
	sum1.setZero();

	// Convert from input to return type
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();

	// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
	final DoubleType sum2 = new DoubleType();
	sum2.setZero();

	final DoubleType valueAsDoubleType = new DoubleType();

	while (cursorS1.hasNext()) {
		final Composite<I> compositeValue = cursorS1.next();
		final I value1 = compositeValue.get(0).copy();
		conv.convert(value1, valueAsDoubleType);

		// Obtain the cursor position encoded as corner vector
		final int cornerInteger1 = cursorS1.getCornerRepresentation();

		// Determine if the value has to be added (factor==1) or subtracted
		// (factor==-1)
		final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions -
			IntegralMean.norm(cornerInteger1)));
		valueAsDoubleType.mul(factor);

		sum1.add(valueAsDoubleType);

		final I value2 = compositeValue.get(1).copy();
		conv.convert(value2, valueAsDoubleType);

		// Determine if the value has to be added (factor==1) or subtracted
		// (factor==-1)
		valueAsDoubleType.mul(factor);

		sum2.add(valueAsDoubleType);
	}

	final int area = (int) Intervals.numElements(Intervals.expand(input, -1l));

	valueAsDoubleType.set(area); // NB: Reuse available DoubleType
	sum1.mul(sum1);
	sum1.div(valueAsDoubleType); // NB

	sum2.sub(sum1);
	valueAsDoubleType.sub(new DoubleType(1)); // NB
	sum2.div(valueAsDoubleType); // NB

	output.set(sum2);
}
 
Example #30
Source File: IntegralMean.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final RectangleNeighborhood<Composite<I>> input,
	final DoubleType output)
{
	// computation according to
	// https://en.wikipedia.org/wiki/Summed_area_table
	final IntegralCursor<Composite<I>> cursor = new IntegralCursor<>(input);
	final int dimensions = input.numDimensions();

	// Compute \sum (-1)^{dim - ||cornerVector||_{1}} * I(x^{cornerVector})
	final DoubleType sum = new DoubleType();
	sum.setZero();

	// Convert from input to return type
	final Converter<I, DoubleType> conv = new RealDoubleConverter<>();
	final DoubleType valueAsDoubleType = new DoubleType();

	while (cursor.hasNext()) {
		final I value = cursor.next().get(0).copy();
		conv.convert(value, valueAsDoubleType);

		// Obtain the cursor position encoded as corner vector
		final int cornerInteger = cursor.getCornerRepresentation();

		// Determine if the value has to be added (factor==1) or subtracted
		// (factor==-1)
		final DoubleType factor = new DoubleType(Math.pow(-1.0d, dimensions -
			IntegralMean.norm(cornerInteger)));
		valueAsDoubleType.mul(factor);

		sum.add(valueAsDoubleType);
	}

	final int area = (int) Intervals.numElements(Intervals.expand(input, -1l));

	// Compute mean by dividing the sum divided by the number of elements
	valueAsDoubleType.set(area); // NB: Reuse DoubleType
	sum.div(valueAsDoubleType);

	output.set(sum);
}