|
8 | 8 | * it under the terms of the GNU General Public License as |
9 | 9 | * published by the Free Software Foundation, either version 3 of the |
10 | 10 | * License, or (at your option) any later version. |
11 | | - * |
| 11 | + * |
12 | 12 | * This program is distributed in the hope that it will be useful, |
13 | 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | 15 | * GNU General Public License for more details. |
16 | | - * |
| 16 | + * |
17 | 17 | * You should have received a copy of the GNU General Public |
18 | 18 | * License along with this program. If not, see |
19 | 19 | * <http://www.gnu.org/licenses/gpl-3.0.html>. |
|
22 | 22 | package fiji.plugin.trackmate.batcher; |
23 | 23 |
|
24 | 24 | import java.io.IOException; |
| 25 | +import java.lang.reflect.Method; |
25 | 26 | import java.nio.file.Path; |
26 | 27 | import java.nio.file.Paths; |
27 | 28 | import java.util.Collection; |
|
42 | 43 | import ij.IJ; |
43 | 44 | import ij.ImagePlus; |
44 | 45 | import loci.formats.FormatException; |
45 | | -import loci.plugins.BF; |
46 | 46 | import net.imglib2.algorithm.Algorithm; |
47 | 47 | import net.imglib2.algorithm.MultiThreaded; |
48 | 48 |
|
@@ -146,7 +146,7 @@ public boolean process() |
146 | 146 | { |
147 | 147 | try |
148 | 148 | { |
149 | | - imps = BF.openImagePlus( path.toString() ); |
| 149 | + imps = openUsingBioFormats( path.toString() ); |
150 | 150 | } |
151 | 151 | catch ( FormatException | IOException e ) |
152 | 152 | { |
@@ -287,4 +287,31 @@ public boolean isCanceled() |
287 | 287 | { |
288 | 288 | return cancelReason != null; |
289 | 289 | } |
| 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 | + } |
290 | 317 | } |
0 commit comments