-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* #%L | ||
* ImgLib2: a general-purpose, multidimensional image processing library. | ||
* %% | ||
* Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, | ||
* Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves | ||
* Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, | ||
* Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, | ||
* Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. | ||
* %% | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* The views and conclusions contained in the software and documentation are | ||
* those of the authors and should not be interpreted as representing official | ||
* policies, either expressed or implied, of any organization. | ||
* #L% | ||
*/ | ||
|
||
package tests; | ||
|
||
import net.imglib2.FinalInterval; | ||
import net.imglib2.RandomAccess; | ||
import net.imglib2.RandomAccessible; | ||
import net.imglib2.RandomAccessibleInterval; | ||
import net.imglib2.converter.Converter; | ||
import net.imglib2.display.projectors.AbstractProjector2D; | ||
|
||
|
141 changes: 141 additions & 0 deletions
141
src/test/java/tests/XYRandomAccessibleProjectorBenchmarkOld.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* #%L | ||
* ImgLib2: a general-purpose, multidimensional image processing library. | ||
* %% | ||
* Copyright (C) 2009 - 2013 Stephan Preibisch, Tobias Pietzsch, Barry DeZonia, | ||
* Stephan Saalfeld, Albert Cardona, Curtis Rueden, Christian Dietz, Jean-Yves | ||
* Tinevez, Johannes Schindelin, Lee Kamentsky, Larry Lindsey, Grant Harris, | ||
* Mark Hiner, Aivar Grislis, Martin Horn, Nick Perry, Michael Zinsmaier, | ||
* Steffen Jaensch, Jan Funke, Mark Longair, and Dimiter Prodanov. | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 2 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-2.0.html>. | ||
* #L% | ||
*/ | ||
|
||
package tests; | ||
|
||
import ij.ImageJ; | ||
import net.imglib2.FinalInterval; | ||
import net.imglib2.RandomAccess; | ||
import net.imglib2.RandomAccessible; | ||
import net.imglib2.RandomAccessibleInterval; | ||
import net.imglib2.converter.Converter; | ||
import net.imglib2.display.RealARGBConverter; | ||
import net.imglib2.display.projectors.AbstractProjector2D; | ||
import net.imglib2.exception.IncompatibleTypeException; | ||
import net.imglib2.img.Img; | ||
import net.imglib2.img.array.ArrayImgFactory; | ||
import net.imglib2.img.display.imagej.ImageJFunctions; | ||
import net.imglib2.io.ImgIOException; | ||
import net.imglib2.io.ImgOpener; | ||
import net.imglib2.type.numeric.ARGBType; | ||
import net.imglib2.type.numeric.integer.UnsignedByteType; | ||
|
||
public class XYRandomAccessibleProjectorBenchmarkOld | ||
{ | ||
final Img< UnsignedByteType > img; | ||
|
||
final Img< ARGBType > argbImg; | ||
|
||
public XYRandomAccessibleProjectorBenchmarkOld( final String filename ) throws ImgIOException, IncompatibleTypeException | ||
{ | ||
// open with ImgOpener using an ArrayImgFactory | ||
final ArrayImgFactory< UnsignedByteType > factory = new ArrayImgFactory< UnsignedByteType >(); | ||
img = new ImgOpener().openImg( filename, factory, new UnsignedByteType() ); | ||
argbImg = new ArrayImgFactory< ARGBType >().create( img, new ARGBType() ); | ||
convert( img, argbImg ); | ||
|
||
ImageJFunctions.show( argbImg ); | ||
} | ||
|
||
public void convert( final Img< UnsignedByteType > in, final Img< ARGBType > out ) | ||
{ | ||
final XYRandomAccessibleProjector< UnsignedByteType, ARGBType > projector = new XYRandomAccessibleProjector< UnsignedByteType, ARGBType >( in, out, new RealARGBConverter< UnsignedByteType >(0, 1000) ); | ||
for ( int iteration = 0; iteration < 10; ++iteration ) | ||
{ | ||
final long start = System.currentTimeMillis(); | ||
for ( int i = 0; i < 50; ++i ) | ||
projector.map(); | ||
final long end = System.currentTimeMillis(); | ||
System.out.println( ( end - start ) + " ms (iteration " + iteration + ")" ); | ||
} | ||
} | ||
|
||
public static void main( final String[] args ) throws IncompatibleTypeException, ImgIOException | ||
{ | ||
new ImageJ(); | ||
new XYRandomAccessibleProjectorBenchmarkOld( "DrosophilaWing.tif" ); | ||
} | ||
|
||
/** | ||
* TODO | ||
* | ||
* @author ImgLib2 developers | ||
* @author Stephan Saalfeld <[email protected]> | ||
* @author Tobias Pietzsch <[email protected]> | ||
*/ | ||
class XYRandomAccessibleProjector< A, B > extends AbstractProjector2D< A, B > | ||
{ | ||
final protected RandomAccessibleInterval< B > target; | ||
private RandomAccessible<A> source; | ||
private Converter<? super A, B> converter; | ||
|
||
public XYRandomAccessibleProjector( final RandomAccessible< A > source, final RandomAccessibleInterval< B > target, final Converter< ? super A, B > converter ) | ||
{ | ||
super( source.numDimensions() ); | ||
this.target = target; | ||
this.source = source; | ||
this.converter = converter; | ||
} | ||
|
||
@Override | ||
public void map() | ||
{ | ||
for ( int d = 2; d < position.length; ++d ) | ||
min[ d ] = max[ d ] = position[ d ]; | ||
|
||
min[ 0 ] = target.min( 0 ); | ||
min[ 1 ] = target.min( 1 ); | ||
max[ 0 ] = target.max( 0 ); | ||
max[ 1 ] = target.max( 1 ); | ||
final FinalInterval sourceInterval = new FinalInterval( min, max ); | ||
|
||
final long cr = -target.dimension( 0 ); | ||
|
||
final RandomAccess< B > targetRandomAccess = target.randomAccess( target ); | ||
final RandomAccess< A > sourceRandomAccess = source.randomAccess( sourceInterval ); | ||
|
||
final long width = target.dimension( 0 ); | ||
final long height = target.dimension( 1 ); | ||
|
||
sourceRandomAccess.setPosition( min ); | ||
targetRandomAccess.setPosition( min[ 0 ], 0 ); | ||
targetRandomAccess.setPosition( min[ 1 ], 1 ); | ||
for ( long y = 0; y < height; ++y ) | ||
{ | ||
for ( long x = 0; x < width; ++x ) | ||
{ | ||
converter.convert( sourceRandomAccess.get(), targetRandomAccess.get() ); | ||
sourceRandomAccess.fwd( 0 ); | ||
targetRandomAccess.fwd( 0 ); | ||
} | ||
sourceRandomAccess.move( cr, 0 ); | ||
targetRandomAccess.move( cr, 0 ); | ||
sourceRandomAccess.fwd( 1 ); | ||
targetRandomAccess.fwd( 1 ); | ||
} | ||
} | ||
} | ||
} |