Java Code Examples for net.imglib2.type.logic.BitType#set()

The following examples show how to use net.imglib2.type.logic.BitType#set() . 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: LocalMeanThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryComputerOp<Iterable<T>, DoubleType> meanOp;

		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (meanOp == null) {
				meanOp = Computers.unary(ops(),	Ops.Stats.Mean.class, DoubleType.class, neighborhood);
			}

			final DoubleType m = new DoubleType();

			meanOp.compute(neighborhood, m);
			output.set(center.getRealDouble() > m.getRealDouble() - c);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
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: 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 5
Source File: LocalMedianThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryComputerOp<Iterable<T>, DoubleType> median;

		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (median == null) {
				median = Computers
						.unary(ops(), Ops.Stats.Median.class, DoubleType.class, neighborhood);
			}

			final DoubleType m = new DoubleType();
			median.compute(neighborhood, m);
			output.set(center.getRealDouble() > m.getRealDouble() - c);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 6
Source File: MaskFactory.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new mask image with a defined size and preset content.
 */
public static RandomAccessibleInterval<BitType> createMask(long[] dim, boolean val) {
	RandomAccessibleInterval<BitType> mask = createMask(dim);
	
	for (BitType t : Views.iterable(mask))
		t.set(val);
	
	return mask;
}
 
Example 7
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<BitType, LongArray> generateBitArrayTestImg(
	final boolean fill, final long... dims)
{
	ArrayImg<BitType, LongArray> bits = ArrayImgs.bits(dims);

	if (fill) {
		MersenneTwisterFast betterRNG = new MersenneTwisterFast(0xf1eece);
		for (BitType b : bits) {
			b.set(betterRNG.nextBoolean());
		}
	}
	return bits;
}
 
Example 8
Source File: DilationTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Before
public void initialize() {
	in = generateByteArrayTestImg(true, 10, 10);
	bitIn = ArrayImgs.bits(10, 10);
	final MersenneTwisterFast rnd = new MersenneTwisterFast(0x123456789caffee1L);
	for (BitType px : bitIn)
		px.set(rnd.nextBoolean());
}
 
Example 9
Source File: LocalBernsenThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryFunctionOp<Iterable<T>, Pair<T, T>> minMaxFunc;

		@SuppressWarnings({ "unchecked", "rawtypes" })
		@Override
		public void compute(final Iterable<T> neighborhood, final T center,
			final BitType output)
		{

			if (minMaxFunc == null) {
				minMaxFunc = (UnaryFunctionOp) Functions.unary(ops(), Ops.Stats.MinMax.class, Pair.class, neighborhood);
			}

			final Pair<T, T> outputs = minMaxFunc.calculate(neighborhood);
			final double minValue = outputs.getA().getRealDouble();
			final double maxValue = outputs.getB().getRealDouble();
			final double midGrey = (maxValue + minValue) / 2.0;

			if ((maxValue - minValue) < contrastThreshold) {
				output.set(midGrey >= halfMaxValue);
			}
			else {
				output.set(center.getRealDouble() >= midGrey);
			}
		}

		};
	
	op.setEnvironment(ops());	
	return op;
}
 
Example 10
Source File: LocalSauvolaThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryComputerOp<Iterable<T>, DoubleType> mean;
		private UnaryComputerOp<Iterable<T>, DoubleType> stdDeviation;

		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (mean == null) {
				mean = Computers.unary(ops(), Ops.Stats.Mean.class, new DoubleType(),
					neighborhood);
			}

			if (stdDeviation == null) {
				stdDeviation = Computers.unary(ops(), Ops.Stats.StdDev.class,
					new DoubleType(), neighborhood);
			}

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

			final DoubleType stdDevValue = new DoubleType();
			stdDeviation.compute(neighborhood, stdDevValue);

			double threshold = meanValue.get() * (1.0d + k * ((Math.sqrt(stdDevValue
				.get()) / r) - 1.0));

			output.set(center.getRealDouble() >= threshold);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 11
Source File: LocalMidGreyThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryFunctionOp<Iterable<T>, Pair<T, T>> minMaxFunc;

		@SuppressWarnings({ "unchecked", "rawtypes" })
		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (minMaxFunc == null) {
				minMaxFunc = (UnaryFunctionOp) Functions.unary(ops(),
					Ops.Stats.MinMax.class, Pair.class, neighborhood);
			}

			final Pair<T, T> outputs = minMaxFunc.calculate(neighborhood);

			final double minValue = outputs.getA().getRealDouble();
			final double maxValue = outputs.getB().getRealDouble();

			output.set(center.getRealDouble() > ((maxValue + minValue) / 2.0) - c);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 12
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 13
Source File: LocalNiblackThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryComputerOp<Iterable<T>, DoubleType> mean;
		private UnaryComputerOp<Iterable<T>, DoubleType> stdDeviation;

		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (mean == null) {
				mean = Computers.unary(ops(), Ops.Stats.Mean.class, new DoubleType(),
					neighborhood);
			}

			if (stdDeviation == null) {
				stdDeviation = Computers.unary(ops(), Ops.Stats.StdDev.class,
					new DoubleType(), neighborhood);
			}

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

			final DoubleType stdDev = new DoubleType();
			stdDeviation.compute(neighborhood, stdDev);

			output.set(center.getRealDouble() > m.getRealDouble() + k * stdDev
				.getRealDouble() - c);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 14
Source File: LocalPhansalkarThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryComputerOp<Iterable<T>, DoubleType> mean;
		private UnaryComputerOp<Iterable<T>, DoubleType> stdDeviation;

		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (mean == null) {
				mean = Computers.unary(ops(), Ops.Stats.Mean.class, new DoubleType(),
					neighborhood);
			}

			if (stdDeviation == null) {
				stdDeviation = Computers.unary(ops(), Ops.Stats.StdDev.class,
					new DoubleType(), neighborhood);
			}

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

			final DoubleType stdDevValue = new DoubleType();
			stdDeviation.compute(neighborhood, stdDevValue);

			double threshold = meanValue.get() * (1.0d + p * Math.exp(-q * meanValue
				.get()) + k * ((stdDevValue.get() / r) - 1.0));

			output.set(center.getRealDouble() >= threshold);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 15
Source File: LocalContrastThreshold.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
protected CenterAwareComputerOp<T, BitType> unaryComputer(final T inClass,
	final BitType outClass)
{
	final LocalThresholdMethod<T> op = new LocalThresholdMethod<T>() {

		private UnaryFunctionOp<Iterable<T>, Pair<T, T>> minMaxFunc;

		@SuppressWarnings({ "unchecked", "rawtypes" })
		@Override
		public void compute(final Iterable<T> neighborhood, final T center, final BitType output) {

			if (minMaxFunc == null) {
				minMaxFunc = (UnaryFunctionOp) Functions.unary(ops(),
					Ops.Stats.MinMax.class, Pair.class, neighborhood);
			}

			final Pair<T, T> outputs = minMaxFunc.calculate(neighborhood);

			final double centerValue = center.getRealDouble();
			final double diffMin = centerValue - outputs.getA().getRealDouble();
			final double diffMax = outputs.getB().getRealDouble() - centerValue;

			// set to background (false) if pixel closer to min value,
			// and to foreground (true) if pixel closer to max value.
			// If diffMin and diffMax are equal, output will be set to fg.
			output.set(diffMin <= diffMax);
		}
	};

	op.setEnvironment(ops());
	return op;
}
 
Example 16
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final C input, final BitType output) {
	output.set(input.getRealDouble() != 0);
}
 
Example 17
Source File: ConvertTypes.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final T input, final BitType output) {
	output.set(input.getIntegerLong() != 0);
}
 
Example 18
Source File: MaskFactory.java    From Colocalisation_Analysis with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Create a new mask based on a threshold condition for two images.
 */
public static<T extends RealType< T >> RandomAccessibleInterval<BitType> createMask(
		RandomAccessibleInterval<T> ch1, RandomAccessibleInterval<T> ch2,
		T threshold1, T threshold2, ThresholdMode tMode, CombinationMode cMode) {
	
	final long[] dims = new long[ ch1.numDimensions() ];
	ch1.dimensions(dims);
	RandomAccessibleInterval<BitType> mask = createMask(dims);
	Cursor<T> cursor1 = Views.iterable(ch1).cursor();
	Cursor<T> cursor2 = Views.iterable(ch2).cursor();
	Cursor<BitType> maskCursor = Views.iterable(mask).cursor();
	
	while (cursor1.hasNext() && cursor2.hasNext() && maskCursor.hasNext()) {
		cursor1.fwd();
		cursor2.fwd();
		maskCursor.fwd();
		
		boolean ch1Valid, ch2Valid;
		
		T data1 = cursor1.get();
		T data2 = cursor2.get();
		
		// get relation to threshold
		if (tMode == ThresholdMode.Above) {
			ch1Valid = data1.compareTo(threshold1) > 0;
			ch2Valid = data2.compareTo(threshold2) > 0;
		} else if (tMode == ThresholdMode.Below) {
			ch1Valid = data1.compareTo(threshold1) < 0;
			ch2Valid = data2.compareTo(threshold2) < 0;
		} else {
			throw new UnsupportedOperationException();
		}
		
		BitType maskData = maskCursor.get();
		
		// combine the results into mask
		if (cMode == CombinationMode.AND) {
			maskData.set( ch1Valid && ch2Valid );
		} else if (cMode == CombinationMode.OR) {
			maskData.set( ch1Valid || ch2Valid );
		} else if (cMode == CombinationMode.NONE) {
			maskData.set( !(ch1Valid || ch2Valid) );
		} else {
			throw new UnsupportedOperationException();
		}
	}
	
	return mask;
}
 
Example 19
Source File: ApplyThresholdComparable.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final Comparable<? super T> input1, final T input2,
	final BitType output)
{
	output.set(input1.compareTo(input2) > 0);
}
 
Example 20
Source File: ApplyThresholdComparator.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final T input1, final T input2, final BitType output) {
	output.set(comparator.compare(input1, input2) > 0);
}