Skip to content
Snippets Groups Projects
Commit ed47fcb6 authored by Tobias Pietzsch's avatar Tobias Pietzsch
Browse files

store name, size, and voxel size with ViewSetup when exporting fused data.

parent c889d8a2
No related branches found
No related tags found
No related merge requests found
......@@ -8,13 +8,16 @@ import java.util.Map;
import mpicbg.spim.data.generic.base.Entity;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicImgLoader;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
import mpicbg.spim.data.registration.ViewRegistration;
import mpicbg.spim.data.registration.ViewRegistrations;
import mpicbg.spim.data.sequence.Channel;
import mpicbg.spim.data.sequence.ImgLoader;
import mpicbg.spim.data.sequence.TimePoint;
import mpicbg.spim.data.sequence.TimePoints;
import mpicbg.spim.data.sequence.ViewId;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.Dimensions;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.real.FloatType;
......@@ -59,8 +62,14 @@ public class FusionResult
{
final HashMap< Integer, Integer > setupIdToChannelId = new HashMap< Integer, Integer >();
setupIdToChannelId.put( 0, 0 );
final BasicImgLoader< UnsignedShortType > fusionLoader = new FusionImageLoader< FloatType >( filepath +"/" + filepattern, setupIdToChannelId, numSlices, new FusionImageLoader.Gray32ImagePlusLoader(), sliceValueMin, sliceValueMax );
desc = new SequenceDescriptionMinimal( timepoints, Entity.idMap( Arrays.asList( new BasicViewSetup( 0, null, null, null ) ) ), fusionLoader, null );
final ImgLoader< UnsignedShortType > fusionLoader = new FusionImageLoader< FloatType >( filepath +"/" + filepattern, setupIdToChannelId, numSlices, new FusionImageLoader.Gray32ImagePlusLoader(), sliceValueMin, sliceValueMax );
final int setupId = 0;
final String name = "fused";
final ViewId view = new ViewId( timepoints.getTimePointsOrdered().get( 0 ).getId(), setupId );
final Dimensions size = fusionLoader.getImageSize( view );
final VoxelDimensions voxelSize = fusionLoader.getVoxelSize( view );
final BasicViewSetup setup = new BasicViewSetup( setupId, name, size, voxelSize );
desc = new SequenceDescriptionMinimal( timepoints, Entity.idMap( Arrays.asList( setup ) ), fusionLoader, null );
final ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();
for ( final TimePoint timepoint : timepoints.getTimePointsOrdered() )
registrations.add( new ViewRegistration( timepoint.getId(), 0, perTimePointFusionTransforms.get( timepoint.getId() ) ) );
......@@ -78,15 +87,22 @@ public class FusionResult
final Map< Integer, AffineTransform3D > perTimePointFusionTransforms )
{
final HashMap< Integer, Integer > setupIdToChannelId = new HashMap< Integer, Integer >();
for ( int setupId = 0; setupId < channels.size(); ++setupId )
{
setupIdToChannelId.put( setupId, channels.get( setupId ) );
}
final ImgLoader< UnsignedShortType > fusionLoader = new FusionImageLoader< FloatType >( filepath +"/" + filepattern, setupIdToChannelId, numSlices, new FusionImageLoader.Gray32ImagePlusLoader(), sliceValueMin, sliceValueMax );
final ArrayList< BasicViewSetup > setups = new ArrayList< BasicViewSetup >();
for ( int id = 0; id < channels.size(); ++id )
for ( int setupId = 0; setupId < channels.size(); ++setupId )
{
final BasicViewSetup setup = new BasicViewSetup( id, null, null, null );
setup.setAttribute( new Channel( channels.get( id ) ) );
final String name = "fused c " + channels.get( setupId );
final ViewId view = new ViewId( timepoints.getTimePointsOrdered().get( 0 ).getId(), setupId );
final Dimensions size = fusionLoader.getImageSize( view );
final VoxelDimensions voxelSize = fusionLoader.getVoxelSize( view );
final BasicViewSetup setup = new BasicViewSetup( setupId, name, size, voxelSize );
setup.setAttribute( new Channel( channels.get( setupId ) ) );
setups.add( setup );
setupIdToChannelId.put( id, channels.get( id ) );
}
final BasicImgLoader< UnsignedShortType > fusionLoader = new FusionImageLoader< FloatType >( filepath +"/" + filepattern, setupIdToChannelId, numSlices, new FusionImageLoader.Gray32ImagePlusLoader(), sliceValueMin, sliceValueMax );
desc = new SequenceDescriptionMinimal( timepoints, Entity.idMap( setups ), fusionLoader, null );
final ArrayList< ViewRegistration > registrations = new ArrayList< ViewRegistration >();
for ( final TimePoint timepoint : timepoints.getTimePointsOrdered() )
......
......@@ -6,11 +6,14 @@ import io.scif.img.ImgOpener;
import java.util.HashMap;
import mpicbg.spim.data.generic.sequence.BasicImgLoader;
import mpicbg.spim.data.sequence.FinalVoxelDimensions;
import mpicbg.spim.data.sequence.ImgLoader;
import mpicbg.spim.data.sequence.ViewDescription;
import mpicbg.spim.data.sequence.ViewId;
import mpicbg.spim.data.sequence.VoxelDimensions;
import net.imglib2.Cursor;
import net.imglib2.Dimensions;
import net.imglib2.FinalDimensions;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.converter.Converters;
import net.imglib2.converter.RealUnsignedShortConverter;
......@@ -40,7 +43,7 @@ import net.imglib2.view.Views;
*
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
*/
public class FusionImageLoader< T extends RealType< T > > implements BasicImgLoader< UnsignedShortType >
public class FusionImageLoader< T extends RealType< T > > implements ImgLoader< UnsignedShortType >
{
private final String pattern;
......@@ -83,16 +86,12 @@ public class FusionImageLoader< T extends RealType< T > > implements BasicImgLoa
final int tp = view.getTimePointId();
final int c = setupIdToChannelId.get( view.getViewSetupId() );
RandomAccessibleInterval< T > slice = sliceLoader.load( String.format( pattern, tp, c, 0 ) );
final long[] dimensions = new long[ 3 ];
dimensions[ 0 ] = slice.dimension( 0 );
dimensions[ 1 ] = slice.dimension( 1 );
dimensions[ 2 ] = numSlices;
final Dimensions dimensions = getImageSize( view );
final Img< UnsignedShortType > img = factory.create( dimensions, type );
for ( int z = 0; z < numSlices; ++z )
{
slice = sliceLoader.load( String.format( pattern, tp, c, z ) );
final RandomAccessibleInterval< T > slice = sliceLoader.load( String.format( pattern, tp, c, z ) );
final Cursor< UnsignedShortType > d = Views.flatIterable( Views.hyperSlice( img, 2, z ) ).cursor();
for ( final UnsignedShortType t : Converters.convert( Views.flatIterable( slice ), converter, type ) )
......@@ -128,7 +127,7 @@ public class FusionImageLoader< T extends RealType< T > > implements BasicImgLoa
try
{
System.out.println( fn );
return opener.openImg( fn, factory, type );
return opener.openImgs( fn, factory, type ).get( 0 );
}
catch ( final ImgIOException e )
{
......@@ -164,4 +163,29 @@ public class FusionImageLoader< T extends RealType< T > > implements BasicImgLoa
return ImageJFunctions.wrapByte( new ImagePlus( fn ) );
}
}
@Override
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
throw new UnsupportedOperationException();
}
@Override
public Dimensions getImageSize( final ViewId view )
{
final int tp = view.getTimePointId();
final int c = setupIdToChannelId.get( view.getViewSetupId() );
final RandomAccessibleInterval< T > slice = sliceLoader.load( String.format( pattern, tp, c, 0 ) );
return new FinalDimensions(
slice.dimension( 0 ),
slice.dimension( 1 ),
numSlices );
}
@Override
public VoxelDimensions getVoxelSize( final ViewId view )
{
return new FinalVoxelDimensions( "px", 1, 1, 1 );
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment