diff --git a/src/main/java/com/indago/io/DoubleTypeImgLoader.java b/src/main/java/com/indago/io/DoubleTypeImgLoader.java index 954a8e6..3fb451c 100644 --- a/src/main/java/com/indago/io/DoubleTypeImgLoader.java +++ b/src/main/java/com/indago/io/DoubleTypeImgLoader.java @@ -9,11 +9,13 @@ import ij.IJ; import ij.ImagePlus; +import net.imagej.ImgPlus; import net.imglib2.IterableInterval; import net.imglib2.RandomAccessibleInterval; import net.imglib2.img.ImagePlusAdapter; import net.imglib2.img.Img; import net.imglib2.img.array.ArrayImgFactory; +import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.DoubleType; import net.imglib2.view.Views; @@ -40,26 +42,34 @@ public static Img< DoubleType > loadTiff( final File file ) { public static RandomAccessibleInterval< DoubleType > loadTiffEnsureType( final File file ) { final Img< DoubleType > img = loadTiff( file ); - final long dims[] = new long[ img.numDimensions() ]; - img.dimensions( dims ); - final RandomAccessibleInterval< DoubleType > ret = - new ArrayImgFactory< DoubleType >().create( dims, new DoubleType() ); - final IterableInterval< DoubleType > iterRet = Views.iterable( ret ); - try { - DataMover.convertAndCopy( Views.extendZero( img ), iterRet ); - } catch ( final Exception e ) { - e.printStackTrace(); - } + final RandomAccessibleInterval< DoubleType > ret = copyToDouble( img ); return ret; } + public static ImgPlus< DoubleType > wrapEnsureType( final ImgPlus< ? extends RealType > imgPlus ) { + final Img< DoubleType > newImg = copyToDouble( imgPlus.getImg() ); + final ImgPlus< DoubleType > result = new ImgPlus<>( newImg, imgPlus.getName() ); + for ( int i = 0; i < result.numDimensions(); i++ ) + result.setAxis( imgPlus.axis( i ), i ); + return result; + } + public static RandomAccessibleInterval< DoubleType > wrapEnsureType( final ImagePlus imagePlus ) { final Img< DoubleType > img = ImagePlusAdapter.wrapReal( imagePlus ); + final RandomAccessibleInterval< DoubleType > ret = copyToDouble( img ); + return ret; + } + + /** + * @param img + * @return + */ + private static Img< DoubleType > copyToDouble( final Img< ? extends RealType > img ) { final long dims[] = new long[ img.numDimensions() ]; img.dimensions( dims ); - final RandomAccessibleInterval< DoubleType > ret = + final Img< DoubleType > ret = new ArrayImgFactory< DoubleType >().create( dims, new DoubleType() ); final IterableInterval< DoubleType > iterRet = Views.iterable( ret ); try { diff --git a/src/main/java/com/indago/plugins/seg/IndagoSegmentationPlugin.java b/src/main/java/com/indago/plugins/seg/IndagoSegmentationPlugin.java index a89cef3..d431a6f 100644 --- a/src/main/java/com/indago/plugins/seg/IndagoSegmentationPlugin.java +++ b/src/main/java/com/indago/plugins/seg/IndagoSegmentationPlugin.java @@ -12,6 +12,7 @@ import com.indago.io.ProjectFolder; import net.imagej.ImageJPlugin; +import net.imagej.ImgPlus; import net.imglib2.RandomAccessibleInterval; import net.imglib2.type.numeric.integer.IntType; import net.imglib2.type.numeric.real.DoubleType; @@ -25,7 +26,7 @@ public interface IndagoSegmentationPlugin extends ImageJPlugin, AutoCloseable { List< RandomAccessibleInterval< IntType > > getOutputs(); - void setProjectFolderAndData( ProjectFolder projectFolder, RandomAccessibleInterval< DoubleType > rawData ); + void setProjectFolderAndData( ProjectFolder projectFolder, ImgPlus< DoubleType > rawData ); String getUiName(); diff --git a/src/main/java/com/indago/plugins/seg/IndagoSegmentationPluginService.java b/src/main/java/com/indago/plugins/seg/IndagoSegmentationPluginService.java index cfc25b0..4dffaad 100644 --- a/src/main/java/com/indago/plugins/seg/IndagoSegmentationPluginService.java +++ b/src/main/java/com/indago/plugins/seg/IndagoSegmentationPluginService.java @@ -12,7 +12,7 @@ import com.indago.io.ProjectFolder; import net.imagej.ImageJService; -import net.imglib2.RandomAccessibleInterval; +import net.imagej.ImgPlus; import net.imglib2.type.numeric.real.DoubleType; @Plugin(type = Service.class) @@ -24,7 +24,7 @@ public class IndagoSegmentationPluginService extends AbstractPTService< IndagoSe /** * Gets the list of available plugin types. * The names on this list can be passed to - * {@link #createPlugin(String, ProjectFolder, RandomAccessibleInterval, Logger)} + * {@link #createPlugin(String, ProjectFolder, ImgPlus, Logger)} * to create instances of that animal. * * @return a set of plugin names @@ -36,7 +36,7 @@ public Set< String > getPluginNames() { public IndagoSegmentationPlugin createPlugin( final String name, final ProjectFolder projectFolder, - final RandomAccessibleInterval< DoubleType > raiData, + final ImgPlus< DoubleType > imgPlus, final Logger logger ) { // First, we get the animal plugin with the given name. final PluginInfo< IndagoSegmentationPlugin > info = plugins.get( name ); @@ -46,7 +46,7 @@ public IndagoSegmentationPlugin createPlugin( // Next, we use the plugin service to create an animal of that kind. final IndagoSegmentationPlugin segPlugin = getPluginService().createInstance( info ); segPlugin.setLogger( logger ); - segPlugin.setProjectFolderAndData( projectFolder, raiData ); + segPlugin.setProjectFolderAndData( projectFolder, imgPlus ); return segPlugin; }