Java Code Examples for net.imglib2.util.Pair#getB()

The following examples show how to use net.imglib2.util.Pair#getB() . 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: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static TLongHashSet generateContainedLabelsSet(
		final RandomAccessibleInterval<Pair<UnsignedLongType, LabelMultisetType>> relevantData)
{
	final TLongHashSet currentDataAsSet = new TLongHashSet();
	for (final Pair<UnsignedLongType, LabelMultisetType> p : Views.iterable(relevantData))
	{
		final UnsignedLongType  pa  = p.getA();
		final LabelMultisetType pb  = p.getB();
		final long              pav = pa.getIntegerLong();
		if (pav == Label.INVALID)
		{
			pb
					.entrySet()
					.stream()
					.map(Entry::getElement)
					.mapToLong(Label::id)
					.forEach(currentDataAsSet::add);
		}
		else
		{
			currentDataAsSet.add(pav);
		}
	}
	return currentDataAsSet;
}
 
Example 2
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 3
Source File: ExportSpimData2HDF5.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean queryParameters( SpimData2 spimData, final boolean is16bit )
{
	System.out.println( "queryParameters()" );

	if ( newTimepoints == null || newViewSetups == null )
	{
		IOFunctions.println( "new timepoints and new viewsetup list not set yet ... cannot continue" );
		return false;
	}

	perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups );

	String fn = LoadParseQueryXML.defaultXMLfilename;
	if ( fn.endsWith( ".xml" ) )
		fn = fn.substring( 0, fn.length() - ".xml".length() );
	for ( int i = 0;; ++i )
	{
		Generic_Resave_HDF5.lastExportPath = String.format( "%s-f%d.xml", fn, i );
		if ( !new File( Generic_Resave_HDF5.lastExportPath ).exists() )
			break;
	}

	final int firstviewSetupId = newViewSetups.get( 0 ).getId();
	params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), true, getDescription(), is16bit );

	if ( params == null )
	{
		System.out.println( "abort " );
		return false;
	}

	Pair< SpimData2, HashMap< ViewId, Partition > > init = initSpimData( newTimepoints, newViewSetups, params, perSetupExportMipmapInfo );
	this.spimData = init.getA();
	viewIdToPartition = init.getB();

	return true;
}
 
Example 4
Source File: ExtractPSF.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected static File getFileNameForViewId( final ViewDescription vd, final ArrayList< Pair< Pair< Angle, Illumination >, String > > filenames )
{
	for ( final Pair< Pair< Angle, Illumination >, String > pair : filenames )
		if ( pair.getA().getA().getId() == vd.getViewSetup().getAngle().getId() && pair.getA().getB().getId() == vd.getViewSetup().getIllumination().getId() )
			return new File( pair.getB() );

	return null;
}
 
Example 5
Source File: DefaultASCII.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public String calculate(final IterableInterval<T> input) {
	if (min == null || max == null) {
		final Pair<T, T> minMax = minMaxFunc.calculate(input);
		if (min == null) min = minMax.getA();
		if (max == null) max = minMax.getB();
	}
	return ascii(input, min, max);
}
 
Example 6
Source File: DefaultFeretsDiameter.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {

	final RealLocalizable p1 = input.getA();
	final RealLocalizable p2 = input.getB();

	output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0),
			p1.getDoublePosition(1) - p2.getDoublePosition(1)));
}
 
Example 7
Source File: DefaultFeretsAngle.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {

	final RealLocalizable p1 = input.getA();
	final RealLocalizable p2 = input.getB();

	final double degree = Math.atan2(p2.getDoublePosition(1) - p1.getDoublePosition(1),
			p2.getDoublePosition(0) - p1.getDoublePosition(0)) * (180.0 / Math.PI);

	output.set(degree % 180);
}
 
Example 8
Source File: LinkOverlay.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public void setSelectedLink(Pair<Group<ViewId>, Group<ViewId>> link)
{
	if (link == null)
		selectedLink = null;
	else
		selectedLink = new ValuePair<>( link.getA(), link.getB() );
}
 
Example 9
Source File: MeshGeneratorJobManager.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private void setMeshVisibility(final Pair<MeshView, Node> meshAndBlock, final boolean isVisible)
{
	if (meshAndBlock.getA() != null)
		meshAndBlock.getA().setVisible(isVisible);

	if (meshAndBlock.getB() != null)
		meshAndBlock.getB().setVisible(isVisible);
}
 
Example 10
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType< T > > Pair<Pair< AffineGet, Double >, RealInterval> computeStitchingLucasKanade(
		final Group<? extends ViewId> viewIdsA,
		final Group<? extends ViewId> viewIdsB,
		final ViewRegistrations vrs,
		final LucasKanadeParameters params,
		final AbstractSequenceDescription< ?,? extends BasicViewDescription<?>, ? > sd,
		final GroupedViewAggregator gva,
		final long[] downsampleFactors,
		final ExecutorService service )
{
	
	// the transformation that maps the downsampled image coordinates back to the original input(!) image space
	final AffineTransform3D dsCorrectionT1 = new AffineTransform3D();
	final AffineTransform3D dsCorrectionT2 = new AffineTransform3D();

	// get Overlap Bounding Box
	final List<List<ViewId>> views = new ArrayList<>();
	views.add( new ArrayList<>(viewIdsA.getViews()) );
	views.add( new ArrayList<>(viewIdsB.getViews()) );
	BoundingBoxMaximalGroupOverlap< ViewId > bbDet = new BoundingBoxMaximalGroupOverlap<ViewId>( views, sd, vrs );
	BoundingBox bbOverlap = bbDet.estimate( "Max Overlap" );

	// this should be caught outside of this method already, but check nonetheless
	if (bbOverlap == null)
		return null;

	// get one image per group
	final RandomAccessibleInterval<T> img1 = gva.aggregate( viewIdsA, sd, downsampleFactors, dsCorrectionT1 );	
	final RandomAccessibleInterval<T> img2 = gva.aggregate( viewIdsB, sd, downsampleFactors, dsCorrectionT2 );

	if (img1 == null || img2 == null)
	{
		IOFunctions.println( "WARNING: Tried to open missing View when computing Stitching for " + viewIdsA + " and " + 
					viewIdsB + ". No link between those could be determined");
		return null;
	}

	// get translations
	// TODO: is the 2d check here meaningful?
	boolean is2d = img1.numDimensions() == 2;
	Pair< AffineGet, TranslationGet > t1 = TransformTools.getInitialTransforms( vrs.getViewRegistration(viewIdsA.iterator().next()), is2d, dsCorrectionT1 );
	Pair< AffineGet, TranslationGet > t2 = TransformTools.getInitialTransforms( vrs.getViewRegistration(viewIdsB.iterator().next()), is2d, dsCorrectionT2 );

	final Pair< AffineTransform, Double > result  = PairwiseStitching.getShiftLucasKanade(  img1, img2, t1.getB(), t2.getB(), params, service );

	if (result == null)
		return null;

	// TODO: is scaling just the translational part okay here?
	for (int i = 0; i< result.getA().numDimensions(); ++i)			
		result.getA().set( result.getA().get(i, result.getA().numDimensions()) * downsampleFactors[i], i, result.getA().numDimensions() ); 

	// TODO (?): Different translational part of downsample Transformations should be considered via TransformTools.getInitialTransforms
	// we probalbly do not have to correct for them ?

	// NB: as we will deal in global coordinates, not pixel coordinates in global optimization,
	// calculate global R' = VT^-1 * R * VT from pixel transformation R 
	ViewRegistration vrOld = vrs.getViewRegistration(viewIdsB.iterator().next());
	AffineTransform3D resTransform = new AffineTransform3D();
	resTransform.set( result.getA().getRowPackedCopy() );
	resTransform.concatenate( vrOld.getModel().inverse() );
	resTransform.preConcatenate( vrOld.getModel() );

	IOFunctions.println("resulting transformation (pixel coordinates): " + Util.printCoordinates(result.getA().getRowPackedCopy()));
	IOFunctions.println("resulting transformation (global coordinates): " + Util.printCoordinates(resTransform.getRowPackedCopy()));

	return new ValuePair<>( new ValuePair<>( resTransform, result.getB() ), bbOverlap );
}
 
Example 11
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType< T > > Pair<Pair< AffineGet, Double >, RealInterval> computeStitching(
		final Group<? extends ViewId> viewIdsA,
		final Group<? extends ViewId> viewIdsB,
		final ViewRegistrations vrs,
		final PairwiseStitchingParameters params,
		final AbstractSequenceDescription< ?,? extends BasicViewDescription<?>, ? > sd,
		final GroupedViewAggregator gva,
		final long[] downsampleFactors,
		final ExecutorService service )
{

	// the transformation that maps the downsampled image coordinates back to the original input(!) image space
	final AffineTransform3D dsCorrectionT1 = new AffineTransform3D();
	final AffineTransform3D dsCorrectionT2 = new AffineTransform3D();

	// get Overlap Bounding Box
	final List<List<ViewId>> views = new ArrayList<>();
	views.add( new ArrayList<>(viewIdsA.getViews()) );
	views.add( new ArrayList<>(viewIdsB.getViews()) );
	BoundingBoxMaximalGroupOverlap< ViewId > bbDet = new BoundingBoxMaximalGroupOverlap<ViewId>( views, sd, vrs );
	BoundingBox bbOverlap = bbDet.estimate( "Max Overlap" );

	// this should be caught outside of this method already, but check nonetheless
	if (bbOverlap == null)
		return null;

	// get one image per group
	final RandomAccessibleInterval<T> img1 = gva.aggregate( viewIdsA, sd, downsampleFactors, dsCorrectionT1 );	
	final RandomAccessibleInterval<T> img2 = gva.aggregate( viewIdsB, sd, downsampleFactors, dsCorrectionT2 );

	if (img1 == null || img2 == null)
	{
		IOFunctions.println( "WARNING: Tried to open missing View when computing Stitching for " + viewIdsA + " and " + 
					viewIdsB + ". No link between those could be determined");
		return null;
	}

	// get translations
	// TODO: is the 2d check here meaningful?
	// everything will probably be 3d at this point, since ImgLoaders return 3d images
	boolean is2d = img1.numDimensions() == 2;
	Pair< AffineGet, TranslationGet > t1 = TransformTools.getInitialTransforms( vrs.getViewRegistration(viewIdsA.iterator().next()), is2d, dsCorrectionT1 );
	Pair< AffineGet, TranslationGet > t2 = TransformTools.getInitialTransforms( vrs.getViewRegistration(viewIdsB.iterator().next()), is2d, dsCorrectionT2 );

	final Pair< Translation, Double > result  = PairwiseStitching.getShift( img1, img2, t1.getB(), t2.getB(), params, service );

	if (result == null)
		return null;
	
	for (int i = 0; i< result.getA().numDimensions(); ++i)			
		result.getA().set( result.getA().get(i, result.getA().numDimensions()) * downsampleFactors[i], i ); 

	// TODO (?): Different translational part of downsample Transformations should be considered via TransformTools.getInitialTransforms
	// we probalbly do not have to correct for them ?

	// NB: as we will deal in global coordinates, not pixel coordinates in global optimization,
	// calculate global R' = VT^-1 * R * VT from pixel transformation R 
	ViewRegistration vrOld = vrs.getViewRegistration(viewIdsB.iterator().next());
	AffineTransform3D resTransform = new AffineTransform3D();
	resTransform.set( result.getA().getRowPackedCopy() );
	resTransform.concatenate( vrOld.getModel().inverse() );
	resTransform.preConcatenate( vrOld.getModel() );

	System.out.println("shift (pixel coordinates): " + Util.printCoordinates(result.getA().getTranslationCopy()));
	System.out.println("shift (global coordinates): " + Util.printCoordinates(resTransform.getRowPackedCopy()));
	System.out.print("cross-corr: " + result.getB());

	return new ValuePair<>( new ValuePair<>( resTransform, result.getB() ), bbOverlap );
}
 
Example 12
Source File: PhaseCorrelation2Util.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static <T extends RealType<T>> List<PhaseCorrelationPeak2> getPCMMaxima(RandomAccessibleInterval<T> pcm, ExecutorService service, int maxN, boolean subpixelAccuracy){
	
	List<PhaseCorrelationPeak2> res = new ArrayList<PhaseCorrelationPeak2>();
	
	ArrayList<Pair<Localizable, Double>> maxima = FourNeighborhoodExtrema.findMaxMT(Views.extendPeriodic(pcm), pcm, maxN, service);
	//ArrayList<Pair<Localizable, Double>> maxima = FourNeighborhoodExtrema.findMax(Views.extendPeriodic(pcm), pcm, maxN);
	
	
			
	for (Pair<Localizable, Double> p: maxima){
		PhaseCorrelationPeak2 pcp = new PhaseCorrelationPeak2(p.getA(), p.getB());
		if (subpixelAccuracy)
			pcp.calculateSubpixelLocalization(pcm);

		res.add(pcp);
	}
	return res;		
}
 
Example 13
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType< T > > Pair<Pair< AffineGet, Double >, RealInterval> computeStitchingNonEqualTransformationsLucasKanade(
		final Group<? extends ViewId> viewIdsA,
		final Group<? extends ViewId> viewIdsB,
		final ViewRegistrations vrs,
		final LucasKanadeParameters params,
		final AbstractSequenceDescription< ?,? extends BasicViewDescription<?>, ? > sd,
		final GroupedViewAggregator gva,
		final long[] downsampleFactors,
		final ExecutorService service )
{
	final double[] downsampleDbl = new double[downsampleFactors.length];
	for (int d = 0; d < downsampleFactors.length; d++)
		downsampleDbl[d] = downsampleFactors[d];

	// get Overlap Bounding Box
	final List<List<ViewId>> views = new ArrayList<>();
	views.add( new ArrayList<>(viewIdsA.getViews()) );
	views.add( new ArrayList<>(viewIdsB.getViews()) );
	BoundingBoxMaximalGroupOverlap< ViewId > bbDet = new BoundingBoxMaximalGroupOverlap<ViewId>( views, sd, vrs );
	BoundingBox bbOverlap = bbDet.estimate( "Max Overlap" );

	// we could not find overlap -> ignore this pair
	if (bbOverlap == null)
		return null;

	List<RandomAccessibleInterval< FloatType >> raiOverlaps = new ArrayList<>();		
	for (List< ViewId > tileViews : views)
	{
		// wrap every view id (corresponding e.g. to different channels, illums,.. ) in list
		List<List< ViewId >> wrapped = tileViews.stream().map( v -> {
			ArrayList< ViewId > wrp = new ArrayList<ViewId>();
			wrp.add( v );
			return wrp;} ).collect( Collectors.toList() );

		// open all of them "virtually fused"
		List< RandomAccessibleInterval< FloatType > > openFused = 
				DisplayOverlapTestPopup.openVirtuallyFused( sd, vrs, wrapped, bbOverlap, downsampleDbl );

		// aggregate the group into one image
		RandomAccessibleInterval< FloatType > raiI = gva.aggregate( 
				openFused, 
				tileViews,
				sd );

		raiOverlaps.add(raiI);
	}

	// the overlap in both images
	final RandomAccessibleInterval< FloatType > img1 = raiOverlaps.get(0);
	final RandomAccessibleInterval< FloatType > img2 = raiOverlaps.get(1);
	
	// compute phase correlation shift (passing (0,0,..) translations prevents any overlap correction inside)
	final Pair< AffineTransform, Double > result = PairwiseStitching.getShiftLucasKanade(
			img1,
			img2,
			new Translation( img1.numDimensions() ),
			new Translation( img1.numDimensions() ),
			params,
			service );

	if (result == null)
		return null;

	// scale just the translational part
	for (int i = 0; i< result.getA().numDimensions(); ++i)			
		result.getA().set( result.getA().get(i, result.getA().numDimensions()) * downsampleFactors[i], i ); 

	// TODO (?): Different translational part of downsample Transformations should be considered via TransformTools.getInitialTransforms
	// we probalbly do not have to correct for them ?

	final AffineTransform3D vr = vrs.getViewRegistration(viewIdsB.iterator().next()).getModel();		
	final AffineTransform resCorrected = new AffineTransform( result.getA().numDimensions() );
	resCorrected.set( result.getA() );

	IOFunctions.println("resulting transformation: " + Util.printCoordinates(result.getA().getRowPackedCopy()));

	return new ValuePair<>( new ValuePair<>( resCorrected, result.getB() ), bbOverlap );
}
 
Example 14
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < T extends RealType< T > > Pair<Pair< AffineGet, Double >, RealInterval> computeStitchingNonEqualTransformations(
		final Group<? extends ViewId> viewIdsA,
		final Group<? extends ViewId> viewIdsB,
		final ViewRegistrations vrs,
		final PairwiseStitchingParameters params,
		final AbstractSequenceDescription< ?,? extends BasicViewDescription<?>, ? > sd,
		final GroupedViewAggregator gva,
		final long[] downsampleFactors,
		final ExecutorService service )
{

	final double[] downsampleDbl = new double[downsampleFactors.length];
	for (int d = 0; d < downsampleFactors.length; d++)
		downsampleDbl[d] = downsampleFactors[d];

	// get Overlap Bounding Box
	final List<List<ViewId>> views = new ArrayList<>();
	views.add( new ArrayList<>(viewIdsA.getViews()) );
	views.add( new ArrayList<>(viewIdsB.getViews()) );
	BoundingBoxMaximalGroupOverlap< ViewId > bbDet = new BoundingBoxMaximalGroupOverlap<ViewId>( views, sd, vrs );
	BoundingBox bbOverlap = bbDet.estimate( "Max Overlap" );

	// we could not find overlap -> ignore this pair
	if (bbOverlap == null)
		return null;

	List<RandomAccessibleInterval< FloatType >> raiOverlaps = new ArrayList<>();		
	for (List< ViewId > tileViews : views)
	{
		// wrap every view id (corresponding e.g. to different channels, illums,.. ) in list
		List<List< ViewId >> wrapped = tileViews.stream().map( v -> {
			ArrayList< ViewId > wrp = new ArrayList<ViewId>();
			wrp.add( v );
			return wrp;} ).collect( Collectors.toList() );

		// open all of them "virtually fused"
		List< RandomAccessibleInterval< FloatType > > openFused = 
				DisplayOverlapTestPopup.openVirtuallyFused( sd, vrs, wrapped, bbOverlap, downsampleDbl );

		// aggregate the group into one image
		RandomAccessibleInterval< FloatType > raiI = gva.aggregate( 
				openFused, 
				tileViews,
				sd );

		raiOverlaps.add(raiI);
	}

	// the overlap in both images
	final RandomAccessibleInterval< FloatType > img1 = raiOverlaps.get(0);
	final RandomAccessibleInterval< FloatType > img2 = raiOverlaps.get(1);
	
	// compute phase correlation shift (passing (0,0,..) translations prevents any overlap correction inside)
	final Pair< Translation, Double > result = PairwiseStitching.getShift(
			img1,
			img2,
			new Translation( img1.numDimensions() ),
			new Translation( img1.numDimensions() ),
			params,
			service );

	if (result == null)
		return null;

	for (int i = 0; i< result.getA().numDimensions(); ++i)			
		result.getA().set( result.getA().get(i, result.getA().numDimensions()) * downsampleFactors[i], i ); 

	// TODO (?): Different translational part of downsample Transformations should be considered via TransformTools.getInitialTransforms
	// we probalbly do not have to correct for them ?
	final AffineTransform3D vr = vrs.getViewRegistration(viewIdsB.iterator().next()).getModel();		
	final AffineTransform resCorrected = new AffineTransform( result.getA().numDimensions() );
	resCorrected.set( result.getA() );

	System.out.println("shift: " + Util.printCoordinates(result.getA().getTranslationCopy()));
	System.out.print("cross-corr: " + result.getB());

	return new ValuePair<>( new ValuePair<>( resCorrected, result.getB() ), bbOverlap );
}
 
Example 15
Source File: TransformationTools.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static < A > Pair< A, A > reversePair( final Pair< A, A > pair )
{
	return new ValuePair< A, A >( pair.getB(), pair.getA() );
}
 
Example 16
Source File: Data_Explorer.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run( String arg )
{
	if ( showNote )
	{
		showNote();
		showNote = false;
	}

	final LoadParseQueryXML result = new LoadParseQueryXML();

	result.addButton( "Define a new dataset", new ActionListener()
	{
		@Override
		public void actionPerformed(ActionEvent e)
		{
			result.setReturnFalse( true );
			result.getGenericDialog().dispose();
			setDefineNewDataset();
		}
	});

	if ( !result.queryXML( "XML Explorer", "", false, false, false, false ) && !newDataset )
		return;

	final SpimData2 data;
	final String xml;
	final XmlIoSpimData2 io;

	if ( newDataset )
	{
		final Pair< SpimData2, String > dataset = new Define_Multi_View_Dataset().defineDataset( true );

		if ( dataset == null )
			return;

		data = dataset.getA();
		xml = dataset.getB();
		io = new XmlIoSpimData2( "" );
	}
	else
	{
		data = result.getData();
		xml = result.getXMLFileName();
		io = result.getIO();
	}

	final ViewSetupExplorer< SpimData2, XmlIoSpimData2 > explorer = new ViewSetupExplorer<SpimData2, XmlIoSpimData2 >( data, xml, io );

	explorer.getFrame().toFront();

	
}
 
Example 17
Source File: RemoveDetectionsPopup.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void actionPerformed( final ActionEvent e )
{
	if ( panel == null )
	{
		IOFunctions.println( "Panel not set for " + this.getClass().getSimpleName() );
		return;
	}

	if ( !SpimData2.class.isInstance( panel.getSpimData() ) )
	{
		IOFunctions.println( "Only supported for SpimData2 objects: " + this.getClass().getSimpleName() );
		return;
	}


	if ( index == 0 )
	{
		final List< ViewId > viewIds = panel.selectedRowsViewId();
		final SpimData2 data = (SpimData2)panel.getSpimData();

		// ask which channels have the objects we are searching for
		final List< ChannelProcessThinOut > channels = ThinOut_Detections.getChannelsAndLabels( data, viewIds );

		if ( channels == null )
			return;

		// get the actual min/max thresholds for cutting out
		if ( !ThinOut_Detections.getThinOutThresholds( data, viewIds, channels ) )
			return;

		// thin out detections and save the new interestpoint files
		if ( !ThinOut_Detections.thinOut( data, viewIds, channels, false ) )
			return;

		panel.updateContent(); // update interestpoint panel if available

		return;
	}
	else
	{
		final List< BasicViewDescription< ? extends BasicViewSetup > > vds = panel.selectedRows();

		if ( vds.size() != 1 )
		{
			JOptionPane.showMessageDialog( null, "Interactive Removal of Detections only supports a single view at a time." );
			return;
		}

		final Pair< String, String > labels = Interactive_Remove_Detections.queryLabelAndNewLabel( (SpimData2)panel.getSpimData(), (ViewDescription)vds.get( 0 ) );

		if ( labels == null )
			return;

		final SpimData2 spimData = (SpimData2)panel.getSpimData();
		final ViewDescription vd = (ViewDescription)vds.get( 0 );
		final ViewInterestPoints interestPoints = spimData.getViewInterestPoints();
		final ViewInterestPointLists lists = interestPoints.getViewInterestPointLists( vd );
		final String label = labels.getA();
		final String newLabel = labels.getB();

		final InteractiveProjections ip = new InteractiveProjections( spimData, vd, label, newLabel, 2 - (index - 1) );

		ip.runWhenDone( new Thread( new Runnable()
		{
			@Override
			public void run()
			{
				if ( ip.wasCanceled() )
					return;

				final List< InterestPoint > ipList = ip.getInterestPointList();

				if ( ipList.size() == 0 )
				{
					IOFunctions.println( "No detections remaining. Quitting." );
					return;
				}

				// add new label
				final InterestPointList newIpl = new InterestPointList(
						lists.getInterestPointList( label ).getBaseDir(),
						new File(
								lists.getInterestPointList( label ).getFile().getParentFile(),
								"tpId_" + vd.getTimePointId() + "_viewSetupId_" + vd.getViewSetupId() + "." + newLabel ) );

				newIpl.setInterestPoints( ipList );
				newIpl.setParameters( "manually removed detections from '" +label + "'" );

				lists.addInterestPointList( newLabel, newIpl );

				panel.updateContent(); // update interestpoint panel if available
			}
		}) );

		return;
	}
}
 
Example 18
Source File: RestrictPainting.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
private static <T, U> void restrictTo(
		final RandomAccessible<Pair<T, U>> source,
		final RandomAccessible<UnsignedLongType> mask,
		final Localizable seed,
		final Shape shape,
		final Predicate<T> backgroundFilter,
		final Predicate<U> canvasFilter)
{
	final int n = source.numDimensions();

	final RandomAccessible<Pair<Pair<T, U>, UnsignedLongType>> paired = Views.pair(source, mask);

	final TLongList[] coordinates = new TLongList[n];
	for (int d = 0; d < n; ++d)
	{
		coordinates[d] = new TLongArrayList();
		coordinates[d].add(seed.getLongPosition(d));
	}

	final RandomAccessible<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>> neighborhood       = shape
			.neighborhoodsRandomAccessible(
			paired);
	final RandomAccess<Neighborhood<Pair<Pair<T, U>, UnsignedLongType>>>     neighborhoodAccess = neighborhood
			.randomAccess();

	final RandomAccess<UnsignedLongType> targetAccess = mask.randomAccess();
	targetAccess.setPosition(seed);
	targetAccess.get().set(1);

	final UnsignedLongType zero = new UnsignedLongType(0);
	final UnsignedLongType one  = new UnsignedLongType(1);
	final UnsignedLongType two  = new UnsignedLongType(2);

	for (int i = 0; i < coordinates[0].size(); ++i)
	{
		for (int d = 0; d < n; ++d)
		{
			neighborhoodAccess.setPosition(coordinates[d].get(i), d);
		}

		final Cursor<Pair<Pair<T, U>, UnsignedLongType>> neighborhoodCursor = neighborhoodAccess.get().cursor();

		while (neighborhoodCursor.hasNext())
		{
			final Pair<Pair<T, U>, UnsignedLongType> p                   = neighborhoodCursor.next();
			final UnsignedLongType                   m                   = p.getB();
			final Pair<T, U>                         backgroundAndCanvas = p.getA();
			if (m.valueEquals(zero) && canvasFilter.test(backgroundAndCanvas.getB()))
			{
				// If background is same as at seed, mark mask with two
				// (==not active), else with one (==active).
				m.set(backgroundFilter.test(backgroundAndCanvas.getA()) ? two : one);
				for (int d = 0; d < n; ++d)
				{
					coordinates[d].add(neighborhoodCursor.getLongPosition(d));
				}
			}

		}

		if (i > CLEANUP_THRESHOLD)
		{
			for (int d = 0; d < coordinates.length; ++d)
			{
				final TLongList c = coordinates[d];
				coordinates[d] = c.subList(i, c.size());
			}
			i = 0;
		}

	}
}
 
Example 19
Source File: AppendSpimData2HDF5.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean queryParameters( final SpimData2 spimData, final boolean is16bit )
{
	System.out.println( "queryParameters()" );

	if ( newTimepoints == null || newViewSetups == null )
	{
		IOFunctions.println( "new timepoints and new viewsetup list not set yet ... cannot continue" );
		return false;
	}

	Hdf5ImageLoader il = ( Hdf5ImageLoader ) spimData.getSequenceDescription().getImgLoader();

	perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups );

	String fn = il.getHdf5File().getAbsolutePath();
	if ( fn.endsWith( ".h5" ) )
		fn = fn.substring( 0, fn.length() - ".h5".length() );
	String fusionHdfFilename = "";
	String fusionXmlFilename = "";
	for ( int i = 0;; ++i )
	{
		fusionHdfFilename = String.format( "%s-f%d.h5", fn, i );
		fusionXmlFilename = String.format( "%s-f%d.xml", fn, i );
		if ( !new File( fusionHdfFilename ).exists() && !new File( fusionXmlFilename ).exists() )
			break;
	}

	final int firstviewSetupId = newViewSetups.get( 0 ).getId();
	params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), false, getDescription(), is16bit );
	if ( params == null )
	{
		System.out.println( "abort " );
		return false;
	}
	params.setHDF5File( new File( fusionHdfFilename ) );
	params.setSeqFile( new File( fusionXmlFilename ) );

	Pair< SpimData2, HashMap< ViewId, Partition > > init = ExportSpimData2HDF5.initSpimData(
			newTimepoints, newViewSetups, params, perSetupExportMipmapInfo );
	fusionOnlySpimData = init.getA();
	viewIdToPartition = init.getB();

	perSetupExportMipmapInfo.putAll(
			MergePartitionList.getHdf5PerSetupExportMipmapInfos( spimData.getSequenceDescription() ) );

	this.spimData = spimData;
	AppendSpimData2.appendSpimData2( spimData, newTimepoints, newViewSetups );

	ArrayList< Partition > mergedPartitions = MergePartitionList.getMergedHdf5PartitionList(
			spimData.getSequenceDescription(), fusionOnlySpimData.getSequenceDescription() );

	String mergedHdfFilename = "";
	for ( int i = 0;; ++i )
	{
		mergedHdfFilename = String.format( "%s-m%d.h5", fn, i );
		if ( !new File( mergedHdfFilename ).exists() )
			break;
	}

	SequenceDescription seq = spimData.getSequenceDescription();
	Hdf5ImageLoader newLoader = new Hdf5ImageLoader(
			new File( mergedHdfFilename ), mergedPartitions, seq, false );
	seq.setImgLoader( newLoader );
	WriteSequenceToHdf5.writeHdf5PartitionLinkFile( spimData.getSequenceDescription(), perSetupExportMipmapInfo );

	return true;
}