mpicbg.spim.data.sequence.VoxelDimensions Java Examples

The following examples show how to use mpicbg.spim.data.sequence.VoxelDimensions. 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: DHM.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates the List of {@link ViewSetup} for the {@link SpimData} object.
 * The {@link ViewSetup} are defined independent of the {@link TimePoint},
 * each {@link TimePoint} should have the same {@link ViewSetup}s. The {@link MissingViews}
 * class defines if some of them are missing for some of the {@link TimePoint}s
 *
 * @return
 */
protected ArrayList< ViewSetup > createViewSetups( final DHMMetaData meta )
{
	final ArrayList< Channel > channels = new ArrayList< Channel >();
	channels.add( new Channel( meta.getAmpChannelId(), meta.getAmplitudeDir() ) );
	channels.add( new Channel( meta.getPhaseChannelId(), meta.getPhaseDir() ) );

	final ArrayList< Illumination > illuminations = new ArrayList< Illumination >();
	illuminations.add( new Illumination( 0, String.valueOf( 0 ) ) );

	final ArrayList< Angle > angles = new ArrayList< Angle >();
	angles.add( new Angle( 0, String.valueOf( 0 ) ) );

	final ArrayList< ViewSetup > viewSetups = new ArrayList< ViewSetup >();
	for ( final Channel c : channels )
		for ( final Illumination i : illuminations )
			for ( final Angle a : angles )
			{
				final VoxelDimensions voxelSize = new FinalVoxelDimensions( meta.calUnit, meta.calX, meta.calY, meta.calZ );
				final Dimensions dim = new FinalDimensions( new long[]{ meta.getWidth(), meta.getHeight(), meta.getDepth() } );
				viewSetups.add( new ViewSetup( viewSetups.size(), null, dim, voxelSize, c, a, i ) );
			}

	return viewSetups;
}
 
Example #2
Source File: ProcessFusion.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected < T extends RealType< T > > ContentBased< T > getContentBased( final RandomAccessibleInterval< T > img, final ViewDescription desc, final ImgLoader imgLoader )
{
	final double[] sigma1 = ProcessFusion.defaultContentBasedSigma1.clone();
	final double[] sigma2 = ProcessFusion.defaultContentBasedSigma2.clone();

	final double minRes = getMinRes( desc, imgLoader );
	final VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad( desc.getViewSetup(), desc.getTimePoint(), imgLoader );

	if ( ProcessFusion.defaultAdjustContentBasedSigmaForAnisotropy )
	{
		for ( int d = 0; d < 2; ++d )
		{
			sigma1[ d ] /= voxelSize.dimension( d ) / minRes;
			sigma2[ d ] /= voxelSize.dimension( d ) / minRes;
		}
	}

	return new ContentBased<T>( img, bb.getImgFactory( new ComplexFloatType() ), sigma1, sigma2);
}
 
Example #3
Source File: ProcessFusion.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
protected Blending getBlending( final Interval interval, final ViewDescription desc, final ImgLoader imgLoader )
{
	final float[] blending = ProcessFusion.defaultBlendingRange.clone();
	final float[] border = ProcessFusion.defaultBlendingBorder.clone();
	
	final float minRes = (float)getMinRes( desc, imgLoader );
	final VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad( desc.getViewSetup(), desc.getTimePoint(), imgLoader );

	if ( ProcessFusion.defaultAdjustBlendingForAnisotropy )
	{
		for ( int d = 0; d < 2; ++d )
		{
			blending[ d ] /= ( float ) voxelSize.dimension( d ) / minRes;
			border[ d ] /= ( float ) voxelSize.dimension( d ) / minRes;
		}
	}
	
	return new Blending( interval, border, blending );
}
 
Example #4
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
@Override
public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	final ArrayImg< UnsignedShortType, ? > img = ArrayImgs.unsignedShorts( d.dimension( 0 ), d.dimension( 1 ), d.dimension( 2 ) );

	final String ampOrPhaseDir;

	if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId )
		ampOrPhaseDir = amplitudeDir;
	else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() ==  phaseChannelId )
		ampOrPhaseDir = phaseDir;
	else
		throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." );

	populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension );

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );

	return img;
}
 
Example #5
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Updates one specific ViewSetup using the imageMetaDataCache
 * 
 * @param setup - {@link ViewSetup}s that can potentially be updated if it is in the cache
 * @param forceUpdate - overwrite the data if it is already present
 * @return true if something was updated, false if it was not in the cache or if could have been updated but was already there
 */
public boolean updateXMLMetaData( final ViewSetup setup, final boolean forceUpdate )
{
	boolean updated = false;
	
	if ( viewIdLookUp.containsKey( setup.getId() ) )
	{
		// look up the metadata using the ViewId linked by the ViewSetupId
		final Pair< Dimensions, VoxelDimensions > metaData = imageMetaDataCache.get( viewIdLookUp.get( setup.getId() ) );

		if ( !setup.hasSize() || forceUpdate )
		{
			setup.setSize( metaData.getA() );
			updated = true;
		}

		if ( !setup.hasVoxelSize() || forceUpdate )
		{
			setup.setVoxelSize( metaData.getB() );
			updated = true;
		}
	}
	
	return updated;
}
 
Example #6
Source File: Apply_Transformation.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static void setModelToCalibration( final SpimData spimData, final ViewId viewId, final double minResolution )
{
	setModelToIdentity( spimData, viewId );
	
	final ViewRegistrations viewRegistrations = spimData.getViewRegistrations();
	final ViewRegistration r = viewRegistrations.getViewRegistration( viewId );
	
	final ViewDescription viewDescription = spimData.getSequenceDescription().getViewDescription( 
			viewId.getTimePointId(), viewId.getViewSetupId() );

	VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad( viewDescription.getViewSetup(), viewDescription.getTimePoint(), spimData.getSequenceDescription().getImgLoader() );
	final double calX = voxelSize.dimension( 0 ) / minResolution;
	final double calY = voxelSize.dimension( 1 ) / minResolution;
	final double calZ = voxelSize.dimension( 2 ) / minResolution;
	
	final AffineTransform3D m = new AffineTransform3D();
	m.set( calX, 0.0f, 0.0f, 0.0f, 
		   0.0f, calY, 0.0f, 0.0f,
		   0.0f, 0.0f, calZ, 0.0f );
	final ViewTransform vt = new ViewTransformAffine( "calibration", m );
	r.preconcatenateTransform( vt );
}
 
Example #7
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the cached imageMetaData
 */
protected void updateMetaDataCache( final ViewId viewId,
		final int w, final int h, final int d,
		final double calX, final double calY, final double calZ )
{
	imageMetaDataCache.put( viewId, new ValuePair< Dimensions, VoxelDimensions >(
			new FinalDimensions( new long[] { w, h, d } ),
			new FinalVoxelDimensions( "", calX, calY, calZ ) ) );

	// links the viewSetupId to the last added viewId, overwrites earlier entries
	viewIdLookUp.put( viewId.getViewSetupId(), viewId );
}
 
Example #8
Source File: StackList.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Assembles the {@link ViewRegistration} object consisting of a list of {@link ViewRegistration}s for all {@link ViewDescription}s that are present
 * 
 * @param viewDescriptionList
 * @param minResolution - the smallest resolution in any dimension (distance between two pixels in the output image will be that wide)
 * @return
 */
protected static ViewRegistrations createViewRegistrations( final Map< ViewId, ViewDescription > viewDescriptionList, final double minResolution )
{
	final HashMap< ViewId, ViewRegistration > viewRegistrationList = new HashMap< ViewId, ViewRegistration >();
	
	for ( final ViewDescription viewDescription : viewDescriptionList.values() )
		if ( viewDescription.isPresent() )
		{
			final ViewRegistration viewRegistration = new ViewRegistration( viewDescription.getTimePointId(), viewDescription.getViewSetupId() );
			
			final VoxelDimensions voxelSize = viewDescription.getViewSetup().getVoxelSize(); 

			final double calX = voxelSize.dimension( 0 ) / minResolution;
			final double calY = voxelSize.dimension( 1 ) / minResolution;
			final double calZ = voxelSize.dimension( 2 ) / minResolution;
			
			final AffineTransform3D m = new AffineTransform3D();
			m.set( calX, 0.0f, 0.0f, 0.0f, 
				   0.0f, calY, 0.0f, 0.0f,
				   0.0f, 0.0f, calZ, 0.0f );
			final ViewTransform vt = new ViewTransformAffine( "calibration", m );
			viewRegistration.preconcatenateTransform( vt );
			
			viewRegistrationList.put( viewRegistration, viewRegistration );
		}
	
	return new ViewRegistrations( viewRegistrationList );
}
 
Example #9
Source File: ViewSetupUtils.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param setup - the {@link BasicViewSetup}
 * @return - the Voxelsize for this {@link ViewSetup} or null if it is not in the XML
 */
public static VoxelDimensions getVoxelSize( final BasicViewSetup setup )
{
	if ( setup.hasVoxelSize() )
		return setup.getVoxelSize();
	else
		return null;
}
 
Example #10
Source File: ViewSetupUtils.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @param setup - the {@link BasicViewSetup} for which to get the Voxelsize
 * @param t - the {@link TimePoint} from which to load the Voxelsize
 * @param loader - the {@link ImgLoader}
 * @return - the Voxelsize for this {@link ViewSetup}
 */
public static VoxelDimensions getVoxelSizeOrLoad( final BasicViewSetup setup, final TimePoint t, final ImgLoader loader )
{
	if ( setup.hasVoxelSize() )
		return setup.getVoxelSize();
	else
		return loader.getSetupImgLoader( setup.getId() ).getVoxelSize( t.getId() );
}
 
Example #11
Source File: DifferenceOf.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
public int downsampleFactor( final int downsampleXY, final int downsampleZ, final VoxelDimensions v )
{
	final double calXY = Math.min( v.dimension( 0 ), v.dimension( 1 ) );
	final double calZ = v.dimension( 2 ) * downsampleZ;
	final double log2ratio = Math.log( calZ / calXY ) / Math.log( 2 );

	final double exp2;

	if ( downsampleXY == 0 )
		exp2 = Math.pow( 2, Math.floor( log2ratio ) );
	else
		exp2 = Math.pow( 2, Math.ceil( log2ratio ) );

	return (int)Math.round( exp2 );
}
 
Example #12
Source File: TileConfigurationHelpers.java    From BigStitcher with GNU General Public License v2.0 5 votes vote down vote up
public static Map<ViewId, Translation3D> getTransformsForData(Map<ViewId, Translation3D> locations, boolean pixelUnits, AbstractSpimData< ? > data )
{
	final Map<ViewId, Translation3D> res = new HashMap<>();
	final Set< ViewId > vidsWithTransformations = locations.keySet();
	final Collection< BasicViewDescription< ? > > vds = (Collection< BasicViewDescription< ? > >) data.getSequenceDescription().getViewDescriptions().values();

	for ( BasicViewDescription< ? > vd : vds )
	{
		ViewId key;
		if (vidsWithTransformations.contains( vd ))
			key = vd;
		else if (vidsWithTransformations.contains( new ViewId(-1, vd.getViewSetupId()) ))
			key = new ViewId(-1, vd.getViewSetupId());
		else
			continue;

		final ViewRegistration vr = data.getViewRegistrations().getViewRegistration( vd );
		final AffineTransform3D calib = new AffineTransform3D();
		calib.set( vr.getTransformList().get( vr.getTransformList().size() - 1 ).asAffine3D().getRowPackedCopy() );

		final VoxelDimensions voxelDims = vd.getViewSetup().getVoxelSize();

		final Translation3D translation3d = locations.get( key );
		final double[] translationVec = translation3d.getTranslationCopy();

		if (!pixelUnits)
			for (int d = 0; d<voxelDims.numDimensions(); d++)
				translationVec[d] /= voxelDims.dimension( d );

		for (int d = 0; d<calib.numDimensions(); d++)
			translationVec[d] *= calib.get( d, d );

		res.put( new ViewId(vd.getTimePointId(), vd.getViewSetupId()), new Translation3D( translationVec ) );
	}
	return res;
}
 
Example #13
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public VoxelDimensions getVoxelSize( final ViewId view )
{
	// if there is no data for the viewId
	if ( !imageMetaDataCache.containsKey( view ) )
	{
		// check if the data is present for the same viewsetup of another timepoint
		if ( !viewIdLookUp.containsKey( view.getViewSetupId() ) )
			loadMetaData( view );
		else
			return imageMetaDataCache.get( viewIdLookUp.get( view.getViewSetupId() ) ).getB();
	}
	return imageMetaDataCache.get( view ).getB();
}
 
Example #14
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	final ArrayImg< FloatType, ? > img = ArrayImgs.floats( d.dimension( 0 ), d.dimension( 1 ), d.dimension(  2 ) );

	final String ampOrPhaseDir;

	if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId )
		ampOrPhaseDir = amplitudeDir;
	else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() ==  phaseChannelId )
		ampOrPhaseDir = phaseDir;
	else
		throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." );

	populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension );

	if ( normalize )
		normalize( img );

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );

	return img;
}
 
Example #15
Source File: LegacyDHMImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void loadMetaData( ViewId view )
{
	final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view );
	final Dimensions d = vd.getViewSetup().getSize();
	final VoxelDimensions dv = vd.getViewSetup().getVoxelSize();

	updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) );
}
 
Example #16
Source File: AbstractImgLoader.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
protected AbstractImgLoader()
{
	imageMetaDataCache = new HashMap< ViewId, Pair< Dimensions, VoxelDimensions > >();
	viewIdLookUp = new HashMap< Integer, ViewId >();
}
 
Example #17
Source File: ThinOut_Detections.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static Histogram plotHistogram( final SpimData2 spimData, final List< ViewId > viewIds, final ChannelProcessThinOut channel )
{
	final ViewInterestPoints vip = spimData.getViewInterestPoints();

	// list of all distances
	final ArrayList< Double > distances = new ArrayList< Double >();
	final Random rnd = new Random( System.currentTimeMillis() );
	String unit = null;

	for ( final ViewId viewId : viewIds )
	{
		final ViewDescription vd = spimData.getSequenceDescription().getViewDescription( viewId );
		
		if ( !vd.isPresent() || vd.getViewSetup().getChannel().getId() != channel.getChannel().getId() )
			continue;

		final ViewInterestPointLists vipl = vip.getViewInterestPointLists( viewId );
		final InterestPointList ipl = vipl.getInterestPointList( channel.getLabel() );

		final VoxelDimensions voxelSize = vd.getViewSetup().getVoxelSize();

		if ( ipl.getInterestPoints() == null )
			ipl.loadInterestPoints();

		if ( unit == null )
			unit = vd.getViewSetup().getVoxelSize().unit();

		// assemble the list of points
		final List< RealPoint > list = new ArrayList< RealPoint >();

		for ( final InterestPoint ip : ipl.getInterestPoints() )
		{
			list.add ( new RealPoint(
					ip.getL()[ 0 ] * voxelSize.dimension( 0 ),
					ip.getL()[ 1 ] * voxelSize.dimension( 1 ),
					ip.getL()[ 2 ] * voxelSize.dimension( 2 ) ) );
		}

		// make the KDTree
		final KDTree< RealPoint > tree = new KDTree< RealPoint >( list, list );

		// Nearest neighbor for each point
		final KNearestNeighborSearchOnKDTree< RealPoint > nn = new KNearestNeighborSearchOnKDTree< RealPoint >( tree, 2 );

		for ( final RealPoint p : list )
		{
			// every n'th point only
			if ( rnd.nextDouble() < 1.0 / (double)channel.getSubsampling() )
			{
				nn.search( p );
				
				// first nearest neighbor is the point itself, we need the second nearest
				distances.add( nn.getDistance( 1 ) );
			}
		}
	}

	final Histogram h = new Histogram( distances, 100, "Distance Histogram [Channel=" + channel.getChannel().getName() + "]", unit  );
	h.showHistogram();
	IOFunctions.println( "Channel " + channel.getChannel().getName() + ": min distance=" + h.getMin() + ", max distance=" + h.getMax() );
	return h;
}
 
Example #18
Source File: ProcessFusion.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static double getMinRes( final ViewDescription desc, final ImgLoader imgLoader )
{
	final VoxelDimensions size = ViewSetupUtils.getVoxelSizeOrLoad( desc.getViewSetup(), desc.getTimePoint(), imgLoader );
	return Math.min( size.dimension( 0 ), Math.min( size.dimension( 1 ), size.dimension( 2 ) ) );
}
 
Example #19
Source File: SlideBook6.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates the List of {@link ViewSetup} for the {@link SpimData} object.
 * The {@link ViewSetup} are defined independent of the {@link TimePoint},
 * each {@link TimePoint} should have the same {@link ViewSetup}s. The {@link MissingViews}
 * class defines if some of them are missing for some of the {@link TimePoint}s
 *
 * @return
 */
protected ArrayList<ViewSetup> createViewSetups(final SlideBook6MetaData meta) {
    // TODO: query rotation angle of each SlideBook channel
    final double[] yaxis = new double[]{0, 1, 0};
    final ArrayList<Angle> angles = new ArrayList<Angle>();
    final Angle angleA = new Angle(0, "Path_A");
    angleA.setRotation(yaxis, defaultAngles[0]);
    angles.add(angleA);

    final Angle angleB = new Angle(1, "Path_B");
    angleB.setRotation(yaxis, defaultAngles[1]);
    angles.add(angleB);

    // define multiple illuminations, one for every capture in the slide file
    final ArrayList<ViewSetup> viewSetups = new ArrayList<ViewSetup>();

    int firstCapture = defaultCapture;
    int numCaptures = 1;
    if (defaultCapture == -1) {
        firstCapture = 0;
        numCaptures = meta.numCaptures();
    }

    // create one illumination for each capture if defaultCapture == -1, otherwise just one capture
    for (int capture = firstCapture; capture < firstCapture + numCaptures; capture++) {
        final int channels = meta.numChannels(capture);

        // multi-angle captures must have pairs of channels
        if (channels > 1 && channels % 2 == 0) {
            String imageName = meta.imageName(capture);
            imageName = imageName.replaceAll("[^a-zA-Z0-9_-]", "_"); // convert illegal characters to _
            imageName = imageName.toLowerCase(); // convert to lowercase
            // up to 8 illuminations (SlideBook channels) per SlideBook capture
            final Illumination i = new Illumination(capture * 8, imageName);

            for (int ch = 0; ch < channels / 2; ch++) {
                // use name of first channel, SlideBook channels are diSPIM angles and each SlideBook image should have two angles per channel
                String channelName = meta.channels(capture)[ch * 2];
                channelName = channelName.replaceAll("[^a-zA-Z0-9_-]", "_"); // convert illegal characters to _
                channelName = channelName.toLowerCase(); // convert to lowercase

                final Channel channel = new Channel(ch, channelName);

                for (final Angle a : angles) {
                    float voxelSizeUm = defaultCalibrations[0];
                    float zSpacing = defaultCalibrations[2];

                    final VoxelDimensions voxelSize = new FinalVoxelDimensions("um", voxelSizeUm, voxelSizeUm, zSpacing);
                    final Dimensions dim = new FinalDimensions(new long[]{meta.imageSize(capture)[0], meta.imageSize(capture)[1], meta.imageSize(capture)[2]});

                    viewSetups.add(new ViewSetup(viewSetups.size(), a.getName(), dim, voxelSize, channel, a, i));
                }
            }
        }
    }

    return viewSetups;
}
 
Example #20
Source File: SlideBook6.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static void applyAxis(final SpimData data, final double minResolution) {
    ViewRegistrations viewRegistrations = data.getViewRegistrations();
    for (final ViewDescription vd : data.getSequenceDescription().getViewDescriptions().values()) {
        if (vd.isPresent()) {
            final Angle a = vd.getViewSetup().getAngle();

            if (a.hasRotation()) {
                final ViewRegistration vr = viewRegistrations.getViewRegistration(vd);

                final Dimensions dim = vd.getViewSetup().getSize();

                VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSizeOrLoad(vd.getViewSetup(), vd.getTimePoint(), data.getSequenceDescription().getImgLoader());
                final double calX = voxelSize.dimension(0) / minResolution;
                final double calY = voxelSize.dimension(1) / minResolution;
                final double calZ = voxelSize.dimension(2) / minResolution;

                AffineTransform3D calModel = new AffineTransform3D();
                calModel.set(
                        1, 0, 0, -dim.dimension(0) / 2 * calX,
                        0, 1, 0, -dim.dimension(1) / 2 * calY,
                        0, 0, 1, -dim.dimension(2) / 2 * calZ);
                ViewTransform vt = new ViewTransformAffine("Center view", calModel);
                vr.preconcatenateTransform(vt);

                final double[] tmp = new double[16];
                final double[] axis = a.getRotationAxis();
                final double degrees = a.getRotationAngleDegrees();
                final AffineTransform3D rotModel = new AffineTransform3D();
                final String d;

                if (axis[0] == 1 && axis[1] == 0 && axis[2] == 0) {
                    rotModel.rotate(0, Math.toRadians(degrees));
                    d = "Rotation around x-axis by " + degrees + " degrees";
                } else if (axis[0] == 0 && axis[1] == 1 && axis[2] == 0) {
                    rotModel.rotate(1, Math.toRadians(degrees));
                    d = "Rotation around y-axis by " + degrees + " degrees";
                } else if (axis[0] == 0 && axis[0] == 0 && axis[2] == 1) {
                    rotModel.rotate(2, Math.toRadians(degrees));
                    d = "Rotation around z-axis by " + degrees + " degrees";
                } else {
                    IOFunctions.println("Arbitrary rotation axis not supported yet.");
                    continue;
                }

                vt = new ViewTransformAffine(d, rotModel);
                vr.preconcatenateTransform(vt);
                vr.updateModel();
            }
        }
    }
}
 
Example #21
Source File: RandomAccessibleIntervalDataSource.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public VoxelDimensions getVoxelDimensions()
{
	// TODO What to do about this? Do we need this at all?
	return null;
}
 
Example #22
Source File: ThinOut_Detections.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static boolean thinOut( final SpimData2 spimData, final List< ViewId > viewIds, final List< ChannelProcessThinOut > channels, final boolean save )
{
	final ViewInterestPoints vip = spimData.getViewInterestPoints();

	for ( final ChannelProcessThinOut channel : channels )
	{
		final double minDistance = channel.getMin();
		final double maxDistance = channel.getMax();
		final boolean keepRange = channel.keepRange();

		for ( final ViewId viewId : viewIds )
		{
			final ViewDescription vd = spimData.getSequenceDescription().getViewDescription( viewId );
			
			if ( !vd.isPresent() || vd.getViewSetup().getChannel().getId() != channel.getChannel().getId() )
				continue;

			final ViewInterestPointLists vipl = vip.getViewInterestPointLists( viewId );
			final InterestPointList oldIpl = vipl.getInterestPointList( channel.getLabel() );

			if ( oldIpl.getInterestPoints() == null )
				oldIpl.loadInterestPoints();

			final VoxelDimensions voxelSize = vd.getViewSetup().getVoxelSize();

			// assemble the list of points (we need two lists as the KDTree sorts the list)
			// we assume that the order of list2 and points is preserved!
			final List< RealPoint > list1 = new ArrayList< RealPoint >();
			final List< RealPoint > list2 = new ArrayList< RealPoint >();
			final List< double[] > points = new ArrayList< double[] >();

			for ( final InterestPoint ip : oldIpl.getInterestPoints() )
			{
				list1.add ( new RealPoint(
						ip.getL()[ 0 ] * voxelSize.dimension( 0 ),
						ip.getL()[ 1 ] * voxelSize.dimension( 1 ),
						ip.getL()[ 2 ] * voxelSize.dimension( 2 ) ) );

				list2.add ( new RealPoint(
						ip.getL()[ 0 ] * voxelSize.dimension( 0 ),
						ip.getL()[ 1 ] * voxelSize.dimension( 1 ),
						ip.getL()[ 2 ] * voxelSize.dimension( 2 ) ) );

				points.add( ip.getL() );
			}

			// make the KDTree
			final KDTree< RealPoint > tree = new KDTree< RealPoint >( list1, list1 );

			// Nearest neighbor for each point, populate the new list
			final KNearestNeighborSearchOnKDTree< RealPoint > nn = new KNearestNeighborSearchOnKDTree< RealPoint >( tree, 2 );
			final InterestPointList newIpl = new InterestPointList(
					oldIpl.getBaseDir(),
					new File(
							oldIpl.getFile().getParentFile(),
							"tpId_" + viewId.getTimePointId() + "_viewSetupId_" + viewId.getViewSetupId() + "." + channel.getNewLabel() ) );

			newIpl.setInterestPoints( new ArrayList< InterestPoint >() );

			int id = 0;
			for ( int j = 0; j < list2.size(); ++j )
			{
				final RealPoint p = list2.get( j );
				nn.search( p );
				
				// first nearest neighbor is the point itself, we need the second nearest
				final double d = nn.getDistance( 1 );
				
				if ( ( keepRange && d >= minDistance && d <= maxDistance ) || ( !keepRange && ( d < minDistance || d > maxDistance ) ) )
				{
					newIpl.getInterestPoints().add( new InterestPoint( id++, points.get( j ).clone() ) );
				}
			}

			if ( keepRange )
				newIpl.setParameters( "thinned-out '" + channel.getLabel() + "', kept range from " + minDistance + " to " + maxDistance );
			else
				newIpl.setParameters( "thinned-out '" + channel.getLabel() + "', removed range from " + minDistance + " to " + maxDistance );

			vipl.addInterestPointList( channel.getNewLabel(), newIpl );

			IOFunctions.println( new Date( System.currentTimeMillis() ) + ": TP=" + vd.getTimePointId() + " ViewSetup=" + vd.getViewSetupId() + 
					", Detections: " + oldIpl.getInterestPoints().size() + " >>> " + newIpl.getInterestPoints().size() );

			if ( save && !newIpl.saveInterestPoints() )
			{
				IOFunctions.println( "Error saving interest point list: " + new File( newIpl.getBaseDir(), newIpl.getFile().toString() + newIpl.getInterestPointsExt() ) );
				return false;
			}
		}
	}
		
	return true;
}
 
Example #23
Source File: Specify_Calibration.java    From SPIM_Registration with GNU General Public License v2.0 4 votes vote down vote up
public static ArrayList< Cal > findCalibrations( final AbstractSpimData< ? extends AbstractSequenceDescription< ?, ?, ? > > spimData, final List< ViewId > viewIds )
{
	// this is the same for all timepoints, we are just interested in the ViewSetup
	final TimePoint t = spimData.getSequenceDescription().getTimePoints().getTimePointsOrdered().get( 0 );

	final ArrayList< Cal > calibrations = new ArrayList< Cal >(); 
	
	for ( final ViewId viewId : viewIds )
	{
		if ( viewId.getTimePointId() != t.getId() )
			continue;

		final BasicViewDescription< ? > vd = spimData.getSequenceDescription().getViewDescriptions().get( viewId );
		final BasicViewSetup vs = vd.getViewSetup();
		final String name;

		if ( ViewSetup.class.isInstance( vs ) )
		{
			name =
				"angle: " + ((ViewSetup)vs).getAngle().getName() +
				" channel: " + ((ViewSetup)vs).getChannel().getName() +
				" illum: " + ((ViewSetup)vs).getIllumination().getName() +
				", present at timepoint: " + t.getName() +
				": " + vd.isPresent();
		}
		else
		{
			name =
				"viewsetup: " + vs.getId() + ", present at timepoint: " +
				t.getName() + ": " + vd.isPresent();
		}

		// only consider voxelsizes as defined in the XML
		VoxelDimensions voxelSize = ViewSetupUtils.getVoxelSize( vs );

		if ( voxelSize == null )
			voxelSize = new FinalVoxelDimensions( "", new double[]{ 1, 1, 1 } );

		final double x = voxelSize.dimension( 0 );
		final double y = voxelSize.dimension( 1 );
		final double z = voxelSize.dimension( 2 );
		String unit = voxelSize.unit();

		if ( unit == null )
			unit = "";

		IOFunctions.println( "cal: [" + x + ", " + y + ", " + z + "] " + unit + "  -- " + name );

		final Cal calTmp = new Cal( new double[]{ x, y, z }, unit );
		boolean foundMatch = false;

		for ( int j = 0; j < calibrations.size() && !foundMatch; ++j )
		{
			final Cal cal = calibrations.get( j );
			if ( cal.equals( calTmp ) )
			{
				cal.increaseCount();
				foundMatch = true;
			}
		}

		if ( !foundMatch )
			calibrations.add( calTmp );
	}

	return calibrations;
}
 
Example #24
Source File: GenerateSpimData.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
public VoxelDimensions getVoxelSize( int timepointId ) { return null; }
 
Example #25
Source File: GenerateSpimData.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static SpimData grid3x2()
{
	final ArrayList< ViewSetup > setups = new ArrayList< ViewSetup >();
	final ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();

	final Channel c0 = new Channel( 0, "RFP" );
	final Channel c1 = new Channel( 1, "YFP" );
	final Channel c2 = new Channel( 2, "GFP" );

	final Angle a0 = new Angle( 0 );
	final Illumination i0 = new Illumination( 0 );

	final Tile t0 = new Tile( 0, "Tile0", new double[]{ 0.0, 0.0, 0.0 } );
	final Tile t1 = new Tile( 1, "Tile1", new double[]{ 450.0, 0.0, 0.0 } );
	final Tile t2 = new Tile( 2, "Tile2", new double[]{ 0.0, 450.0, 0.0 } );
	final Tile t3 = new Tile( 3, "Tile3", new double[]{ 450.0, 450.0, 0.0 } );

	final Dimensions d0 = new FinalDimensions( 512l, 512l, 86l );
	final VoxelDimensions vd0 = new FinalVoxelDimensions( "px", 0.4566360, 0.4566360, 2.0000000 );

	setups.add( new ViewSetup( 0, "setup 0", d0, vd0, t0, c0, a0, i0 ) );
	setups.add( new ViewSetup( 1, "setup 1", d0, vd0, t1, c0, a0, i0 ) );
	setups.add( new ViewSetup( 2, "setup 2", d0, vd0, t2, c0, a0, i0 ) );
	setups.add( new ViewSetup( 3, "setup 3", d0, vd0, t3, c0, a0, i0 ) );

	setups.add( new ViewSetup( 4, "setup 4", d0, vd0, t0, c1, a0, i0 ) );
	setups.add( new ViewSetup( 5, "setup 5", d0, vd0, t1, c1, a0, i0 ) );
	setups.add( new ViewSetup( 6, "setup 6", d0, vd0, t2, c1, a0, i0 ) );
	setups.add( new ViewSetup( 7, "setup 7", d0, vd0, t3, c1, a0, i0 ) );

	setups.add( new ViewSetup( 8, "setup 8", d0, vd0, t0, c2, a0, i0 ) );
	setups.add( new ViewSetup( 9, "setup 9", d0, vd0, t1, c2, a0, i0 ) );
	setups.add( new ViewSetup( 10, "setup 10", d0, vd0, t2, c2, a0, i0 ) );
	setups.add( new ViewSetup( 11, "setup 11", d0, vd0, t3, c2, a0, i0 ) );

	final ArrayList< TimePoint > t = new ArrayList< TimePoint >();
	t.add( new TimePoint( 0 ) );
	final TimePoints timepoints = new TimePoints( t );

	final ArrayList< ViewId > missing = new ArrayList< ViewId >();
	final MissingViews missingViews = new MissingViews( missing );

	final ImgLoader imgLoader = new ImgLoader()
	{
		@Override
		public SetupImgLoader< ? > getSetupImgLoader( int setupId )
		{
			return new MySetupImgLoader( setupId );
		}
	};

	for ( final ViewSetup vs : setups )
	{
		final ViewRegistration vr = new ViewRegistration( t.get( 0 ).getId(), vs.getId() );

		final Tile tile = vs.getTile();

		final double minResolution = Math.min( Math.min( vs.getVoxelSize().dimension( 0 ), vs.getVoxelSize().dimension( 1 ) ), vs.getVoxelSize().dimension( 2 ) );
		
		final double calX = vs.getVoxelSize().dimension( 0 ) / minResolution;
		final double calY = vs.getVoxelSize().dimension( 1 ) / minResolution;
		final double calZ = vs.getVoxelSize().dimension( 2 ) / minResolution;

		final AffineTransform3D m = new AffineTransform3D();
		m.set( calX, 0.0f, 0.0f, 0.0f, 
			   0.0f, calY, 0.0f, 0.0f,
			   0.0f, 0.0f, calZ, 0.0f );
		final ViewTransform vt = new ViewTransformAffine( "Calibration", m );
		vr.preconcatenateTransform( vt );

		final AffineTransform3D translation = new AffineTransform3D();

		if ( tile.hasLocation() )
		{
			translation.set( tile.getLocation()[ 0 ] / calX, 0, 3 );
			translation.set( tile.getLocation()[ 1 ] / calY, 1, 3 );
			translation.set( tile.getLocation()[ 2 ] / calZ, 2, 3 );
		}

		vr.preconcatenateTransform( new ViewTransformAffine( "Translation", translation ) );

		vr.updateModel();		
		
		registrations.add( vr );
	}

	final SequenceDescription sd = new SequenceDescription( timepoints, setups, imgLoader, missingViews );
	final SpimData data = new SpimData( new File( "" ), sd, new ViewRegistrations( registrations ) );

	return data;
}
 
Example #26
Source File: FractalImgLoader.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public FractalImgLoader( final List<Interval> intervals, final VoxelDimensions vd0, final AveragedRandomAccessible< LongType > fractalsRA )
{
	this.intervals = intervals;
	this.vd0 = vd0;
	this.fractalsRA = fractalsRA;
}
 
Example #27
Source File: MinimalTest.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
@Override
public VoxelDimensions getVoxelSize( int timepointId ) { return null; }
 
Example #28
Source File: MinimalTest.java    From BigStitcher with GNU General Public License v2.0 4 votes vote down vote up
public static SpimData twoAngles()
{
	final ArrayList< ViewSetup > setups = new ArrayList< ViewSetup >();
	final ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();

	final Channel c0 = new Channel( 0, "test" );
	final Angle a0 = new Angle( 0 );
	final Angle a1 = new Angle( 1 );
	final Illumination i0 = new Illumination( 0 );

	final Dimensions d0 = new FinalDimensions( 512l, 512l, 86l );
	final VoxelDimensions vd0 = new FinalVoxelDimensions( "px", 0.4566360, 0.4566360, 2.0000000 );

	setups.add( new ViewSetup( 0, "setup 0", d0, vd0, c0, a0, i0 ) );
	setups.add( new ViewSetup( 1, "setup 1", d0, vd0, c0, a1, i0 ) );

	final ArrayList< TimePoint > t = new ArrayList< TimePoint >();
	t.add( new TimePoint( 0 ) );
	final TimePoints timepoints = new TimePoints( t );

	final ArrayList< ViewId > missing = new ArrayList< ViewId >();
	final MissingViews missingViews = new MissingViews( missing );

	final ImgLoader imgLoader = new ImgLoader()
	{
		@Override
		public SetupImgLoader< ? > getSetupImgLoader( int setupId )
		{
			return new MySetupImgLoader( setupId );
		}
	};

	for ( final ViewSetup vs : setups )
	{
		final ViewRegistration vr = new ViewRegistration( t.get( 0 ).getId(), vs.getId() );

		final double minResolution = Math.min( Math.min( vs.getVoxelSize().dimension( 0 ), vs.getVoxelSize().dimension( 1 ) ), vs.getVoxelSize().dimension( 2 ) );
		
		final double calX = vs.getVoxelSize().dimension( 0 ) / minResolution;
		final double calY = vs.getVoxelSize().dimension( 1 ) / minResolution;
		final double calZ = vs.getVoxelSize().dimension( 2 ) / minResolution;
		
		final AffineTransform3D m = new AffineTransform3D();
		m.set( calX, 0.0f, 0.0f, 0.0f, 
			   0.0f, calY, 0.0f, 0.0f,
			   0.0f, 0.0f, calZ, 0.0f );
		final ViewTransform vt = new ViewTransformAffine( "Calibration", m );
		vr.preconcatenateTransform( vt );

		vr.updateModel();		
		
		registrations.add( vr );
	}

	final SequenceDescription sd = new SequenceDescription( timepoints, setups, imgLoader, missingViews );
	final SpimData data = new SpimData( new File( "" ), sd, new ViewRegistrations( registrations ) );

	return data;
}
 
Example #29
Source File: DataSourceTest.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public VoxelDimensions getVoxelDimensions() {
	return null;
}
 
Example #30
Source File: MaskedSource.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Override
public VoxelDimensions getVoxelDimensions()
{
	return source.getVoxelDimensions();
}