Skip to content

Commit

Permalink
Change SegmentationPlugins to take ImgPlus
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Jug committed Jan 25, 2019
1 parent 273568b commit f43aec4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
32 changes: 21 additions & 11 deletions src/main/java/com/indago/io/DoubleTypeImgLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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 );
Expand All @@ -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;
}
Expand Down

0 comments on commit f43aec4

Please sign in to comment.