Java Code Examples for net.imglib2.type.numeric.ARGBType#set()

The following examples show how to use net.imglib2.type.numeric.ARGBType#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: ConsensusWarpFieldBuilder.java    From render with GNU General Public License v2.0 6 votes vote down vote up
private int[] buildModelIndexGrid() {

        final int[] targetCellIndexes = new int[getNumberOfCells()];

        final ArrayImg<ARGBType, IntArray> target = ArrayImgs.argbs(targetCellIndexes, columnCount, rowCount);
        final KDTree<ARGBType> kdTree = new KDTree<>(consensusSetIndexSamples);
        final NearestNeighborSearch<ARGBType> nnSearchSamples = new NearestNeighborSearchOnKDTree<>(kdTree);

        final Cursor<ARGBType> targetCursor = target.localizingCursor();

        Sampler<ARGBType> sampler;
        ARGBType sampleItem;
        ARGBType targetItem;
        while (targetCursor.hasNext()) {

            targetCursor.fwd();
            nnSearchSamples.search(targetCursor);
            sampler = nnSearchSamples.getSampler();

            sampleItem = sampler.get();
            targetItem = targetCursor.get();
            targetItem.set(sampleItem);
        }

        return targetCellIndexes;
    }
 
Example 2
Source File: CompositeProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void accumulate(final Cursor<? extends ARGBType>[] accesses, final ARGBType t)
{
	t.set(0);
	for (int i = 0; i < composites.size(); ++i)
		composites.get(i).compose(t, accesses[i].get());
	final int nonpre = t.get();
	t.set(PixelUtils.NonPretoPre(nonpre));
	//		@SuppressWarnings( "restriction" )
	//		final int pre = PixelUtils.NonPretoPre( nonpre );
	//		final int a = nonpre & 0xff;
	//		if ( a == 0xff )
	//			return;
	//		if ( a == 0x00 )
	//			return;
	//		int r = nonpre >> 24 & 0xff;
	//		int g = nonpre >> 16 & 0xff;
	//		int b = nonpre >> 8 & 0xff;
	//		r = ( r * a + 0x7f ) / 0xff;
	//		g = ( g * a + 0x7f ) / 0xff;
	//		b = ( b * a + 0x7f ) / 0xff;
	//		final int pre = a << 0 | r << 24 | g << 16 | b << 8;
	//		final int pre = PixelUtils.NonPretoPre( nonpre );
	//		t.set( pre );
}
 
Example 3
Source File: ARGBCompositeAlphaAdd.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void compose(final ARGBType a, final ARGBType b)
{
	final int argbA = a.get();
	final int argbB = b.get();

	final int rA = ARGBType.red(argbA);
	final int rB = ARGBType.red(argbB);
	final int gA = ARGBType.green(argbA);
	final int gB = ARGBType.green(argbB);
	final int bA = ARGBType.blue(argbA);
	final int bB = ARGBType.blue(argbB);

	final double aA = ARGBType.alpha(argbA) / 255.0;
	final double aB = ARGBType.alpha(argbB) / 255.0;
	//		final double aB = ( rB == gB || gB == bB ) ? ARGBType.alpha( argbB ) / 255.0 : ARGBType.alpha( argbB )
	// / 255.0 * 0.125;

	final double aTarget = aA + aB - aA * aB;

	final int rTarget = Math.min(255, (int) Math.round(rA + rB * aB));
	final int gTarget = Math.min(255, (int) Math.round(gA + gB * aB));
	final int bTarget = Math.min(255, (int) Math.round(bA + bB * aB));

	a.set(ARGBType.rgba(rTarget, gTarget, bTarget, (int) (aTarget * 255)));
}
 
Example 4
Source File: ARGBColorConverter.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void convert(final R input, final ARGBType output)
{
	final double v = input.getRealDouble() - min.get();
	if (v < 0)
	{
		output.set(black);
	}
	else
	{
		final int r0 = (int) (scaleR * v + 0.5);
		final int g0 = (int) (scaleG * v + 0.5);
		final int b0 = (int) (scaleB * v + 0.5);
		final int r  = Math.min(255, r0);
		final int g  = Math.min(255, g0);
		final int b  = Math.min(255, b0);
		output.set(ARGBType.rgba(r, g, b, A));
	}
}
 
Example 5
Source File: ARGBColorConverter.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void convert(final R input, final ARGBType output)
{
	final double v = input.getRealDouble() - min.get();
	if (v < 0)
	{
		output.set(black);
	}
	else
	{
		final int r0 = (int) (scaleR * v + 0.5);
		final int g0 = (int) (scaleG * v + 0.5);
		final int b0 = (int) (scaleB * v + 0.5);
		final int r  = Math.min(255, r0);
		final int g  = Math.min(255, g0);
		final int b  = Math.min(255, b0);
		output.set(ARGBType.rgba(r, g, b, A));
	}
}
 
Example 6
Source File: LinearIntensityMap.java    From TrakEM2 with GNU General Public License v3.0 5 votes vote down vote up
final static protected < T extends RealType< T > > void mapARGB(
		final IterableInterval< ARGBType > image,
		final IterableInterval< RealComposite< T > > coefficients )
{
	final Cursor< ARGBType > cs = image.cursor();
	final Cursor< RealComposite< T > > ct = coefficients.cursor();

	while ( cs.hasNext() )
	{
		final RealComposite< T > t = ct.next();
		final double alpha = t.get( 0 ).getRealDouble();
		final double beta = t.get( 1 ).getRealDouble();

		final ARGBType s = cs.next();
		final int argb = s.get();
		final int a = ( ( argb >> 24 ) & 0xff );
		final double r = ( ( argb >> 16 ) & 0xff ) * alpha + beta;
		final double g = ( ( argb >> 8 ) & 0xff ) * alpha + beta;
		final double b = ( argb & 0xff ) * alpha + beta;

		s.set(
				( a << 24 ) |
				( ( r < 0 ? 0 : r > 255 ? 255 : ( int )( r + 0.5 ) ) << 16 ) |
				( ( g < 0 ? 0 : g > 255 ? 255 : ( int )( g + 0.5 ) ) << 8 ) |
				( b < 0 ? 0 : b > 255 ? 255 : ( int )( b + 0.5 ) ) );
	}
}
 
Example 7
Source File: MaximumProjectorARGB.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void accumulate( final Cursor< ? extends ARGBType >[] accesses, final ARGBType target )
{
	int aMax = 0, rMax = 0, gMax = 0, bMax = 0;
	for ( final Cursor< ? extends ARGBType > access : accesses )
	{
		final int value = access.get().get();
		final int a = ARGBType.alpha( value );
		final int r = ARGBType.red( value );
		final int g = ARGBType.green( value );
		final int b = ARGBType.blue( value );
		
		aMax = Math.max( aMax, a );
		rMax = Math.max( rMax, r );
		gMax = Math.max( gMax, g );
		bMax = Math.max( bMax, b );
	}
	
	if ( aMax > 255 )
		aMax = 255;
	if ( rMax > 255 )
		rMax = 255;
	if ( gMax > 255 )
		gMax = 255;
	if ( bMax > 255 )
		bMax = 255;
	
	
	target.set( ARGBType.rgba( rMax, gMax, bMax, aMax ) );
}
 
Example 8
Source File: ARGBCompositeColorConverter.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static <
		R extends RealType<R>,
		C extends RealComposite<R>,
		V extends Volatile<C>> void convertInverting(
		V input,
		final ARGBType output,
		final int numChannels,
		final DoubleProperty[] min,
		final double[] scaleR,
		final double[] scaleG,
		final double[] scaleB,
		final int A
) {
	double rd = 0.0;
	double gd = 0.0;
	double bd = 0.0;
	final RealComposite<? extends RealType<?>> c = input.get();
	for (int channel = 0; channel < numChannels; ++channel) {
		final double v = c.get(channel).getRealDouble() - min[channel].get();
		rd += scaleR[channel] * v;
		gd += scaleG[channel] * v;
		bd += scaleB[channel] * v;
	}
	final int r0 = (int) (rd + 0.5);
	final int g0 = (int) (gd + 0.5);
	final int b0 = (int) (bd + 0.5);
	final int r = Math.min(255, Math.max(r0, 0));
	final int g = Math.min(255, Math.max(g0, 0));
	final int b = Math.min(255, Math.max(b0, 0));
	output.set(ARGBType.rgba(r, g, b, A));
}
 
Example 9
Source File: ARGBColorConverter.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void convert(final R input, final ARGBType output)
{
	final double v  = input.getRealDouble() - min.get();
	final int    r0 = (int) (scaleR * v + 0.5);
	final int    g0 = (int) (scaleG * v + 0.5);
	final int    b0 = (int) (scaleB * v + 0.5);
	final int    r  = Math.min(255, Math.max(r0, 0));
	final int    g  = Math.min(255, Math.max(g0, 0));
	final int    b  = Math.min(255, Math.max(b0, 0));
	output.set(ARGBType.rgba(r, g, b, A));
}
 
Example 10
Source File: ARGBColorConverter.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void convert(final R input, final ARGBType output)
{
	final double v  = input.getRealDouble() - min.get();
	final int    r0 = (int) (scaleR * v + 0.5);
	final int    g0 = (int) (scaleG * v + 0.5);
	final int    b0 = (int) (scaleB * v + 0.5);
	final int    r  = Math.min(255, Math.max(r0, 0));
	final int    g  = Math.min(255, Math.max(g0, 0));
	final int    b  = Math.min(255, Math.max(b0, 0));
	output.set(ARGBType.rgba(r, g, b, A));
}
 
Example 11
Source File: HighlightingStreamConverterSerializer.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public JsonElement serialize(
		final HighlightingStreamConverter<?> src,
		final Type typeOfSrc,
		final JsonSerializationContext context)
{
	final JsonObject                     map    = new JsonObject();
	final AbstractHighlightingARGBStream stream = src.getStream();
	map.addProperty(TYPE_KEY, src.getClass().getName());
	map.addProperty(STREAM_TYPE_KEY, stream.getClass().getName());
	map.addProperty(SEED_KEY, stream.getSeed());

	final TLongIntMap specifiedColors = stream.getExplicitlySpecifiedColorsCopy();
	if (specifiedColors.size() > 0)
	{
		final JsonObject colors = new JsonObject();
		final ARGBType   dummy  = new ARGBType();
		for (final TLongIntIterator colorIt = specifiedColors.iterator(); colorIt.hasNext(); )
		{
			colorIt.advance();
			dummy.set(colorIt.value());
			colors.addProperty(Long.toString(colorIt.key()), Colors.toHTML(dummy));
		}
		LOG.debug("Adding specified colors {}", colors);
		map.add(SPECIFIED_COLORS_KEY, colors);

	}

	LOG.debug("Returning serialized converter as {}", map);

	return map;
}
 
Example 12
Source File: ARGBCompositeAlphaYCbCr.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void compose(final ARGBType a, final ARGBType b)
{
	final int argbA = a.get();
	final int argbB = b.get();

	final double rA = ARGBType.red(argbA) / 255.0;
	final double rB = ARGBType.red(argbB) / 255.0;
	final double gA = ARGBType.green(argbA) / 255.0;
	final double gB = ARGBType.green(argbB) / 255.0;
	final double bA = ARGBType.blue(argbA) / 255.0;
	final double bB = ARGBType.blue(argbB) / 255.0;

	final double aA = ARGBType.alpha(argbA) / 255.0;
	final double aB = ARGBType.alpha(argbB) / 255.0;
	//		final double aB = ( rB == gB || gB == bB ) ? ARGBType.alpha( argbB ) / 255.0 * 0.5 : ARGBType.alpha(
	// argbB ) / 255.0 * 0.125;

	final double aTarget = aA + aB - aA * aB;

	final double yA  = rgb2y(rA, gA, bA);
	final double cbA = rgb2cb(rA, gA, bA);
	final double crA = rgb2cr(rA, gA, bA);

	final double cbB = rgb2cb(rB, gB, bB);
	final double crB = rgb2cr(rB, gB, bB);

	final double aBInv = 1.0 - aB;

	final double cbTarget = cbA * aBInv + cbB * aB;
	final double crTarget = crA * aBInv + crB * aB;

	final double rTarget = ycbcr2r(yA, cbTarget, crTarget);
	final double gTarget = ycbcr2g(yA, cbTarget, crTarget);
	final double bTarget = ycbcr2b(yA, cbTarget, crTarget);

	a.set(ARGBType.rgba(
			Math.max(0, Math.min(255, (int) Math.round(rTarget * 255))),
			Math.max(0, Math.min(255, (int) Math.round(gTarget * 255))),
			Math.max(0, Math.min(255, (int) Math.round(bTarget * 255))),
			(int) (aTarget * 255)
	                   ));
}
 
Example 13
Source File: ThresholdingSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void convert(final V mask, final ARGBType color)
{
	color.set(mask.get().get() ? masked : notMasked);
}
 
Example 14
Source File: ThresholdingSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void convert(final B mask, final ARGBType color)
{
	color.set(mask.get() ? masked : notMasked);
}
 
Example 15
Source File: HighlightingStreamConverterIntegerType.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
	public void convert(final V input, final ARGBType output)
	{
		output.set(stream.argb(input.get().getIntegerLong()));
//		LOG.trace("Converted input {} to output {}", input, output);
	}
 
Example 16
Source File: AveragingProjectorARGB.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
protected void accumulate( final Cursor< ? extends ARGBType >[] accesses, final ARGBType target )
{
	int aSum = 0, rSum = 0, gSum = 0, bSum = 0;
	int nonZeroAccesses = 0;
	for ( final Cursor< ? extends ARGBType > access : accesses )
	{
		final int value = access.get().get();
		final int a = ARGBType.alpha( value );
		final int r = ARGBType.red( value );
		final int g = ARGBType.green( value );
		final int b = ARGBType.blue( value );
		
		if (a>0 || r>0 || g>0 || b>0)
			nonZeroAccesses++;
		
		aSum += a;
		rSum += r;
		gSum += g;
		bSum += b;
	}
	
	nonZeroAccesses = nonZeroAccesses > 0 ? nonZeroAccesses : 1;
	
	aSum /= nonZeroAccesses;
	rSum /= nonZeroAccesses;
	gSum /= nonZeroAccesses;
	bSum /= nonZeroAccesses;
	
	if ( aSum > 255 )
		aSum = 255;
	if ( rSum > 255 )
		rSum = 255;
	if ( gSum > 255 )
		gSum = 255;
	if ( bSum > 255 )
		bSum = 255;
	
	
	target.set( ARGBType.rgba( rSum, gSum, bSum, aSum ) );
}
 
Example 17
Source File: SimpleInterruptibleProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Render the 2D target image by copying values from the source. Source can have more dimensions than the target.
 * Target coordinate <em>(x,y)</em> is copied from source coordinate <em>(x,y,0,...,0)</em>.
 *
 * @return true if rendering was completed (all target pixels written). false if rendering was interrupted.
 */
@Override
public boolean map()
{
	interrupted.set(false);

	final StopWatch stopWatch = new StopWatch();
	stopWatch.start();

	min[0] = target.min(0);
	min[1] = target.min(1);
	max[0] = target.max(0);
	max[1] = target.max(1);

	final long cr = -target.dimension(0);

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

	final boolean         createExecutor = executorService == null;
	final ExecutorService ex             = createExecutor
	                                       ? Executors.newFixedThreadPool(numThreads)
	                                       : executorService;
	final int             numTasks;
	if (numThreads > 1)
	{
		numTasks = Math.min(numThreads * 10, height);
	}
	else
		numTasks = 1;
	final double                    taskHeight = (double) height / numTasks;
	final ArrayList<Callable<Void>> tasks      = new ArrayList<>(numTasks);
	for (int taskNum = 0; taskNum < numTasks; ++taskNum)
	{
		final long myMinY   = min[1] + (int) (taskNum * taskHeight);
		final long myHeight = (taskNum == numTasks - 1
		                       ? height
		                       : (int) ((taskNum + 1) * taskHeight)) - myMinY - min[1];

		final Callable<Void> r = () -> {
			if (interrupted.get())
				return null;

			System.out.println("WTF!");
			final RandomAccess<A>        sourceRandomAccess = source.randomAccess(
					SimpleInterruptibleProjectorPreMultiply.this);
			final RandomAccess<ARGBType> targetRandomAccess = target.randomAccess(target);

			sourceRandomAccess.setPosition(min);
			sourceRandomAccess.setPosition(myMinY, 1);
			targetRandomAccess.setPosition(min[0], 0);
			targetRandomAccess.setPosition(myMinY, 1);
			for (int y = 0; y < myHeight; ++y)
			{
				if (interrupted.get())
					return null;
				for (int x = 0; x < width; ++x)
				{
					final ARGBType argb = targetRandomAccess.get();
					converter.convert(sourceRandomAccess.get(), argb);
					final int nonpre = argb.get();
					argb.set(PixelUtils.NonPretoPre(nonpre));
					sourceRandomAccess.fwd(0);
					targetRandomAccess.fwd(0);
				}
				sourceRandomAccess.move(cr, 0);
				targetRandomAccess.move(cr, 0);
				sourceRandomAccess.fwd(1);
				targetRandomAccess.fwd(1);
			}
			return null;
		};
		tasks.add(r);
	}
	try
	{
		ex.invokeAll(tasks);
	} catch (final InterruptedException e)
	{
		Thread.currentThread().interrupt();
	}
	if (createExecutor)
		ex.shutdown();

	lastFrameRenderNanoTime = stopWatch.nanoTime();

	return !interrupted.get();
}