Skip to content

Commit aa7c36e

Browse files
committed
Add Convolve example
1 parent d49d200 commit aa7c36e

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*-
2+
* #%L
3+
* ImgLib2: a general-purpose, multidimensional image processing library.
4+
* %%
5+
* Copyright (C) 2009 - 2024 Tobias Pietzsch, Stephan Preibisch, Stephan Saalfeld,
6+
* John Bogovic, Albert Cardona, Barry DeZonia, Christian Dietz, Jan Funke,
7+
* Aivar Grislis, Jonathan Hale, Grant Harris, Stefan Helfrich, Mark Hiner,
8+
* Martin Horn, Steffen Jaensch, Lee Kamentsky, Larry Lindsey, Melissa Linkert,
9+
* Mark Longair, Brian Northan, Nick Perry, Curtis Rueden, Johannes Schindelin,
10+
* Jean-Yves Tinevez and Michael Zinsmaier.
11+
* %%
12+
* Redistribution and use in source and binary forms, with or without
13+
* modification, are permitted provided that the following conditions are met:
14+
*
15+
* 1. Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimer.
17+
* 2. Redistributions in binary form must reproduce the above copyright notice,
18+
* this list of conditions and the following disclaimer in the documentation
19+
* and/or other materials provided with the distribution.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
* #L%
33+
*/
34+
package net.imglib2.algorithm.blocks.convolve;
35+
36+
import bdv.cache.SharedQueue;
37+
import bdv.util.Bdv;
38+
import bdv.util.BdvFunctions;
39+
import bdv.util.BdvSource;
40+
import bdv.util.volatiles.VolatileViews;
41+
import bdv.viewer.DisplayMode;
42+
import ij.IJ;
43+
import ij.ImagePlus;
44+
import net.imglib2.algorithm.blocks.BlockAlgoUtils;
45+
import net.imglib2.algorithm.blocks.BlockSupplier;
46+
import net.imglib2.img.Img;
47+
import net.imglib2.img.display.imagej.ImageJFunctions;
48+
import net.imglib2.type.numeric.ARGBType;
49+
import net.imglib2.type.numeric.integer.UnsignedByteType;
50+
import net.imglib2.view.Views;
51+
52+
public class ConvolveBdvPlayground
53+
{
54+
public static void main( String[] args )
55+
{
56+
System.setProperty("apple.laf.useScreenMenuBar", "true");
57+
58+
final String fn = "/Users/pietzsch/workspace/data/e002_stack_fused-8bit.tif";
59+
final ImagePlus imp = IJ.openImage( fn );
60+
final Img< UnsignedByteType > img = ImageJFunctions.wrapByte( imp );
61+
62+
final BdvSource bdv = BdvFunctions.show(
63+
img,
64+
"img",
65+
Bdv.options() );
66+
bdv.setColor( new ARGBType( 0xffffff ) );
67+
bdv.setDisplayRange( 0, 255 );
68+
bdv.getBdvHandle().getViewerPanel().setDisplayMode( DisplayMode.SINGLE );
69+
70+
final BlockSupplier< UnsignedByteType > blocks = BlockSupplier
71+
.of( Views.extendMirrorDouble( img ) )
72+
.andThen( Convolve.gauss( 4 ) );
73+
74+
final long[] dimensions = img.dimensionsAsLongArray();
75+
final int[] cellDimensions = { 64, 64, 64 };
76+
final Img< UnsignedByteType > convolved = BlockAlgoUtils.cellImg(
77+
blocks,
78+
dimensions,
79+
cellDimensions );
80+
81+
final BdvSource out = BdvFunctions.show(
82+
VolatileViews.wrapAsVolatile( convolved, new SharedQueue( 8, 1 ) ),
83+
"convolve",
84+
Bdv.options()
85+
.addTo( bdv )
86+
);
87+
out.setDisplayRange( 0, 255 );
88+
out.setColor( new ARGBType( 0x00ff00 ) );
89+
}
90+
}

0 commit comments

Comments
 (0)