Skip to content

Commit 6ec174d

Browse files
committed
Since we don't have loci_plugins, let's try to call bioformats
another way. Here I copied and adapted code from IJ.
1 parent aad0573 commit 6ec174d

1 file changed

Lines changed: 31 additions & 4 deletions

File tree

src/main/java/fiji/plugin/trackmate/batcher/TrackMateBatcher.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
* it under the terms of the GNU General Public License as
99
* published by the Free Software Foundation, either version 3 of the
1010
* License, or (at your option) any later version.
11-
*
11+
*
1212
* This program is distributed in the hope that it will be useful,
1313
* but WITHOUT ANY WARRANTY; without even the implied warranty of
1414
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515
* GNU General Public License for more details.
16-
*
16+
*
1717
* You should have received a copy of the GNU General Public
1818
* License along with this program. If not, see
1919
* <http://www.gnu.org/licenses/gpl-3.0.html>.
@@ -22,6 +22,7 @@
2222
package fiji.plugin.trackmate.batcher;
2323

2424
import java.io.IOException;
25+
import java.lang.reflect.Method;
2526
import java.nio.file.Path;
2627
import java.nio.file.Paths;
2728
import java.util.Collection;
@@ -42,7 +43,6 @@
4243
import ij.IJ;
4344
import ij.ImagePlus;
4445
import loci.formats.FormatException;
45-
import loci.plugins.BF;
4646
import net.imglib2.algorithm.Algorithm;
4747
import net.imglib2.algorithm.MultiThreaded;
4848

@@ -146,7 +146,7 @@ public boolean process()
146146
{
147147
try
148148
{
149-
imps = BF.openImagePlus( path.toString() );
149+
imps = openUsingBioFormats( path.toString() );
150150
}
151151
catch ( FormatException | IOException e )
152152
{
@@ -287,4 +287,31 @@ public boolean isCanceled()
287287
{
288288
return cancelReason != null;
289289
}
290+
291+
/** Copied and adapted from the ij.io.Opener class. */
292+
@SuppressWarnings( { "rawtypes", "unchecked" } )
293+
public static ImagePlus[] openUsingBioFormats( final String path ) throws FormatException, IOException
294+
{
295+
final String className = "loci.plugins.BF";
296+
final String methodName = "openImagePlus";
297+
try
298+
{
299+
final Class c = IJ.getClassLoader().loadClass( className );
300+
if ( c == null )
301+
return null;
302+
final Class[] argClasses = new Class[ 1 ];
303+
argClasses[ 0 ] = methodName.getClass();
304+
final Method m = c.getMethod( methodName, argClasses );
305+
final Object[] args = new Object[ 1 ];
306+
args[ 0 ] = path;
307+
final Object obj = m.invoke( null, args );
308+
final ImagePlus[] images = obj != null ? ( ImagePlus[] ) obj : null;
309+
if ( images == null || images.length == 0 )
310+
return null;
311+
return images;
312+
}
313+
catch ( final Exception e )
314+
{}
315+
return null;
316+
}
290317
}

0 commit comments

Comments
 (0)