...
 
Commits (2)
......@@ -29,7 +29,7 @@ import java.io.File;
*
* The image chunks are made by height / numThreads. Each chunk is processed in MinCostZSurface class
*/
@Plugin(type = Op.class, menuPath = "Plugins>MinCost2ZSurfaceMT", name = "MinCost2ZSurfaceMT", headless = true, label = "MinCost2ZSurfaceMT")
@Plugin(type = Op.class, menuPath = "Plugins>MinCost2ZSurface>Multi Threads", name = "MinCost2ZSurfaceMT", headless = true, label = "MinCost2ZSurfaceMT")
public class MinCost2ZSurfaceMT_Ops<T extends RealType<T> & NativeType<T>> extends AbstractOp {
//
// should implement Map if I want to benefit the ops matching
......
......@@ -22,7 +22,7 @@ import org.scijava.plugin.Plugin;
import java.io.File;
@Plugin(type = Op.class, menuPath = "Plugins>MinCost2ZSurface", name="MinCost2ZSurface", headless = true, label="MinCost2ZSurface")
@Plugin(type = Op.class, menuPath = "Plugins>MinCost2ZSurface>Single Thread", name="MinCost2ZSurface", headless = true, label="MinCost2ZSurface")
public class MinCost2ZSurface_Ops < T extends RealType<T> & NativeType< T > > extends AbstractOp {
//
// should implement Map if I want to benefit the ops matching
......
......@@ -30,7 +30,7 @@ import java.io.File;
* This class is not necessary as a single thread can deal with it in a fairly fast way.
* Caution: too many threads gives an error as well.
*/
@Plugin(type = Op.class, menuPath = "Plugins>MinCostZSurfaceMT", name="MinCostZSurfaceMT", headless = true, label="MinCostZSurfaceMT")
@Plugin(type = Op.class, menuPath = "Plugins>MinCostZSurface>Multi Threads", name="MinCostZSurfaceMT", headless = true, label="MinCostZSurfaceMT")
public class MinCostZSurfaceMT_Ops< T extends RealType<T> & NativeType< T >> extends AbstractOp {
//
// should implement ops if I want to benefit the matching mechanism
......@@ -239,9 +239,8 @@ public class MinCostZSurfaceMT_Ops< T extends RealType<T> & NativeType< T >> ext
ij.ui().showUI();
// ask the user for a file to open
// final File file = ij.ui().chooseFile(null, "open");
final File file = ij.ui().chooseFile(null, "open");
final File file = new File("/Users/moon/temp/20190129_wingsdic_400nm20E_upcrawl_000-z1-z213.tif");
if (file != null) {
// load the dataset
final Dataset dataset = ij.scifio().datasetIO().open(file.getPath());
......
......@@ -23,7 +23,7 @@ import org.scijava.plugin.Plugin;
import java.io.File;
@Plugin(type = Op.class, menuPath = "Plugins>MinCostZSurface", name="MinCostZSurface", headless = true, label="MinCostZSurface")
@Plugin(type = Op.class, menuPath = "Plugins>MinCostZSurface>Single Thread", name="MinCostZSurface", headless = true, label="MinCostZSurface")
public class MinCostZSurface_Ops< T extends RealType<T> & NativeType< T > > extends AbstractOp {
//
// should implement ops if I want to benefit the matching mechanism
......
package de.mpicbg.scf.mincostsurface;
import net.imagej.Dataset;
import net.imagej.ImageJ;
import net.imagej.ops.AbstractOp;
import net.imagej.ops.Op;
import net.imagej.ops.OpService;
import net.imglib2.img.Img;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import org.scijava.ItemIO;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import java.io.File;
/**
* Author: HongKee Moon (moon@mpi-cbg.de), Scientific Computing Facility
* Organization: MPI-CBG Dresden
* Date: October 2019
*/
@Plugin(type = Op.class, name="zMapResliceMT", headless = true, label="zMapResliceMT", visible=true, menuPath = "Plugins>Z map reslice>Multi Threads")
public class ResliceAlongZMapMT_Ops < T extends RealType<T> & NativeType< T >, U extends RealType<U>> extends AbstractOp {
@Parameter( label = "input image" )
private Img input;
@Parameter ( label = "z map" )
private Img zMap;
@Parameter ( label = "slice Above the z map" )
private int sliceAbove;
@Parameter ( label = "slice Below the z map" )
private int sliceBelow;
@Parameter ( label = "Number of Threads")
private int numThreads;
// output
@Parameter (type = ItemIO.OUTPUT)
private Img<T> outputExcerpt;
@Parameter
OpService op;
@Override
public void run() {
Img<T> input_img = (Img<T>) input;
Img<U> zMap_img = (Img<U>) zMap;
outputExcerpt = img_utils.ZSurface_reslice3(input_img, zMap_img, sliceAbove, sliceBelow, numThreads);
}
public static void main(final String... args) throws Exception {
// create the ImageJ application context with all available services
final ImageJ ij = new ImageJ();
ij.ui().showUI();
// ask the user for a file to open
final File file = ij.ui().chooseFile(null, "open");
if (file != null) {
// load the dataset
final Dataset dataset = ij.scifio().datasetIO().open(file.getPath());
// show the image
ij.ui().show(dataset);
// invoke the plugin
ij.command().run(ResliceAlongZMap_Ops.class, true);
}
}
}
......@@ -30,7 +30,7 @@ import java.io.File;
//@Plugin(type = Command.class, menuPath = "Plugins>Z map reslice")
@Plugin(type = Op.class, name="zMapReslice", headless = true, label="zMapReslice", visible=true, menuPath = "Plugins>Z map reslice")
@Plugin(type = Op.class, name="zMapReslice", headless = true, label="zMapReslice", visible=true, menuPath = "Plugins>Z map reslice>Single Thread")
public class ResliceAlongZMap_Ops < T extends NumericType<T> & NativeType< T >, U extends RealType<U> > extends AbstractOp {
......
package de.mpicbg.scf.mincostsurface;
import net.imglib2.multithreading.SimpleMultiThreading;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.RealType;
......@@ -9,6 +10,7 @@ import net.imglib2.Interval;
import net.imglib2.RandomAccess;
import net.imglib2.RealRandomAccess;
import net.imglib2.util.Intervals;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;
import net.imglib2.algorithm.gauss3.Gauss3;
import net.imglib2.exception.IncompatibleTypeException;
......@@ -231,6 +233,134 @@ public class img_utils {
return excerpt;
}
public static <T extends NumericType<T> & NativeType<T> , U extends RealType<U> >
Img<T> ZSurface_reslice3(Img<T> input, Img<U> depthMap, int sliceOnTop, int sliceBelow, int numThreads)
{
final long[][] inputOffset = new long[ numThreads ][input.numDimensions()];
for ( int d = 0; d < inputOffset.length; d++ )
{
inputOffset[d] = new long[input.numDimensions()];
for (int i = 0; i < inputOffset[d].length; i++) {
inputOffset[d][i] = 0;
}
// width
// offset[d][0] = inputSource.dimension( 0 ) / numThreads * d;
// height
inputOffset[d][1] = input.dimension( 1 ) / numThreads * d;
// depth
// offset[d][2] = 0;
}
int nDim = input.numDimensions();
long[] dims = new long[nDim];
input.dimensions(dims);
long output_height = sliceOnTop + sliceBelow + 1;
final ImgFactory< T > imgFactory = new ArrayImgFactory< T >();
final Img< T > excerpt = imgFactory.create( new long[] {dims[0],dims[1], output_height} , input.firstElement().createVariable() );
final long[][] offset = new long[ numThreads ][excerpt.numDimensions()];
for ( int d = 0; d < offset.length; d++ )
{
offset[d] = new long[excerpt.numDimensions()];
for (int i = 0; i < offset[d].length; i++) {
offset[d][i] = 0;
}
// width
// offset[d][0] = inputSource.dimension( 0 ) / numThreads * d;
// height
offset[d][1] = excerpt.dimension( 1 ) / numThreads * d;
// depth
// offset[d][2] = 0;
}
final long[][] depthMapOffset = new long[ numThreads ][depthMap.numDimensions()];
long unit = excerpt.dimension( 1 ) / numThreads;
for ( int d = 0; d < depthMapOffset.length; d++ )
{
depthMapOffset[d] = new long[depthMap.numDimensions()];
for (int i = 0; i < depthMapOffset[d].length; i++) {
depthMapOffset[d][i] = 0;
}
depthMapOffset[d][1] = unit * d;
}
NLinearInterpolatorFactory<T> NLinterp_factory = new NLinearInterpolatorFactory<T>();
final Thread[] threads = SimpleMultiThreading.newThreads( numThreads );
for ( int i = 0; i < threads.length; i++ )
{
int finalI = i;
threads[ i ] = new Thread( "ZSurface Reslice thread " + finalI)
{
@Override
public void run()
{
long[] max = new long[excerpt.numDimensions()];
for(int i = 0; i < excerpt.numDimensions(); i++) {
max[i] = excerpt.dimension(i);
}
max[1] = unit;
IntervalView< T > excerptIntervalView = Views.offsetInterval(excerpt, offset[finalI], max);
RandomAccess< T > randomAccess = excerptIntervalView.randomAccess();
Cursor< T > excerpt_cursor = excerptIntervalView.cursor();
max = new long[input.numDimensions()];
for(int i = 0; i < input.numDimensions(); i++) {
max[i] = input.dimension(i);
}
max[1] = unit;
IntervalView< T > intervalView = Views.offsetInterval(input, inputOffset[finalI], max);
RealRandomAccess< T > inputx_Real = Views.interpolate( Views.extendBorder( intervalView ), NLinterp_factory ).realRandomAccess();
max = new long[depthMap.numDimensions()];
for(int i = 0; i < depthMap.numDimensions(); i++) {
max[i] = depthMap.dimension(i);
}
max[1] = unit;
IntervalView< U > depthMapIntervalView = Views.offsetInterval(depthMap, depthMapOffset[finalI], max);
RandomAccess< U > depthMapx = depthMapIntervalView.randomAccess();
float z_map;
int[] tmp_pos = new int[nDim];
while(excerpt_cursor.hasNext())
{
excerpt_cursor.fwd();
excerpt_cursor.localize(tmp_pos);
depthMapx.setPosition(new int[] {tmp_pos[0],tmp_pos[1]});
z_map = depthMapx.get().getRealFloat();
inputx_Real.setPosition(new float[] {(float)tmp_pos[0],(float)tmp_pos[1], (float)(tmp_pos[2]-(sliceOnTop)) + z_map });
randomAccess.setPosition(excerpt_cursor);
// try {
randomAccess.get().set( inputx_Real.get() );
// } catch (java.lang.ArrayIndexOutOfBoundsException e) {
// continue;
// }
}
}
};
}
SimpleMultiThreading.startAndJoin( threads );
return excerpt;
}
/**
......