Commit dd6c302d authored by lombardo's avatar lombardo

enhancement: linear interpolation in reslicing. bugfix: in reslicing...

enhancement: linear interpolation in reslicing. bugfix: in reslicing (ZSurface_reslice2) using extendZeros can hurt the mincostsurface detection, extendBorder is used now
parent 27629633
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<groupId>de.mpicbg.scf</groupId> <groupId>de.mpicbg.scf</groupId>
<artifactId>MinCostZSurface_</artifactId> <artifactId>MinCostZSurface_</artifactId>
<version>1.1.1</version> <version>1.1.2</version>
<name>MinCostZSurface_</name> <name>MinCostZSurface_</name>
<description> <description>
......
...@@ -61,10 +61,8 @@ public class ResliceAlongZMap_Ops < T extends NumericType<T> & NativeType< T >, ...@@ -61,10 +61,8 @@ public class ResliceAlongZMap_Ops < T extends NumericType<T> & NativeType< T >,
Img<T> input_img = (Img<T>) input; Img<T> input_img = (Img<T>) input;
Img<U> zMap_img = (Img<U>) zMap; Img<U> zMap_img = (Img<U>) zMap;
outputExcerpt = img_utils.ZSurface_reslice(input_img, zMap_img, sliceAbove, sliceBelow); outputExcerpt = img_utils.ZSurface_reslice2(input_img, zMap_img, sliceAbove, sliceBelow);
//op.morphology().top
} }
......
...@@ -173,7 +173,7 @@ public class img_utils { ...@@ -173,7 +173,7 @@ public class img_utils {
for ( int d = 0; d < nDim; ++d ) for ( int d = 0; d < nDim; ++d )
tmp[ d ] = out_cursor.getFloatPosition(d) /upfactor[d]; tmp[ d ] = out_cursor.getFloatPosition(d) /upfactor[d];
interpolant.setPosition(tmp); interpolant.setPosition(tmp);
out_cursor.get().setReal( Math.round( interpolant.get().getRealFloat() ) ); out_cursor.get().setReal( interpolant.get().getRealFloat() );
} }
return output; return output;
...@@ -194,6 +194,44 @@ public class img_utils { ...@@ -194,6 +194,44 @@ public class img_utils {
return upsample( input, out_size, interpType); return upsample( input, out_size, interpType);
} }
public static <T extends NumericType<T> & NativeType<T> , U extends RealType<U> >
Img<T> ZSurface_reslice2(Img<T> input, Img<U> depthMap, int sliceOnTop, int sliceBelow)
{
RandomAccess< U > depthMapx = Views.extendBorder( depthMap ).randomAccess();
//RandomAccess< T > inputx = Views.extendZero( input ).randomAccess();
NLinearInterpolatorFactory<T> NLinterp_factory = new NLinearInterpolatorFactory<T>();
RealRandomAccess< T > inputx_Real = Views.interpolate( Views.extendBorder( input ), NLinterp_factory ).realRandomAccess();
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() );
Cursor< T > excerpt_cursor = excerpt.localizingCursor();
int[] tmp_pos = new int[nDim];
float z_map;
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 });
excerpt_cursor.get().set( inputx_Real.get() );
}
return excerpt;
}
/** /**
* *
* @param input a 3D image * @param input a 3D image
...@@ -206,7 +244,7 @@ public class img_utils { ...@@ -206,7 +244,7 @@ public class img_utils {
Img<T> ZSurface_reslice(Img<T> input, Img<U> depthMap, int sliceOnTop, int sliceBelow) Img<T> ZSurface_reslice(Img<T> input, Img<U> depthMap, int sliceOnTop, int sliceBelow)
{ {
RandomAccess< U > depthMapx = Views.extendBorder( depthMap ).randomAccess(); RandomAccess< U > depthMapx = Views.extendBorder( depthMap ).randomAccess();
RandomAccess< T > inputx = Views.extendZero( input ).randomAccess(); RandomAccess< T > inputx = Views.extendBorder( input ).randomAccess();
int nDim = input.numDimensions(); int nDim = input.numDimensions();
long[] dims = new long[nDim]; long[] dims = new long[nDim];
...@@ -235,8 +273,6 @@ public class img_utils { ...@@ -235,8 +273,6 @@ public class img_utils {
} }
// if input is a wrap of an imagePlus and processor has to be generated every time this could get slow
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment