Imglyb + BigDataViewer

Thanks @hanslovsky and @ctrueden.

scyjava_config.add_classpath('/path/to/jhdf5.jar'

didn’t seem to work. I’ll try wrapping a local Fiji installation as you suggested. Would this carry over into impacting the functionality of imglyb? Or would it only ensure that if I called BDV or BigStitcher through pyimagej that the correct B3D JAR is found?

Anyway I’ll try it tomorrow and report back on the result(s).

Thanks!

The code is now working as I had initially wanted. I am able to use imglyb to visualize the BigStitcher style H5/XML files on the fly in BDV. Thank you @hanslovsky @ctrueden and @tpietzsch for your help and input. The last error I had was because of the B3D compression, but using @ctrueden advice fixed the problem by adding the jhdf5 JAR specifically to the class path. Below is the working code - thanks everyone!

import jnius_config
import tempfile
tmp_dir = tempfile.mkdtemp()
jnius_config.add_classpath(tmp_dir)

import imagej
ij = imagej.init('C:\\Users\\AERB\\Documents\\Fiji.app', headless = False)

import pathlib
import subprocess
import os
from jnius import autoclass

java_code = '''
import java.util.List;
import bdv.util.BdvStackSource;
import mpicbg.spim.data.generic.AbstractSpimData;
import bdv.util.BdvFunctions;

public class MyShow
{
	public static List< BdvStackSource< ? > > show( final AbstractSpimData< ? > spimData )
	{
		return BdvFunctions.show( spimData );
	}
}
'''

fp = pathlib.Path(tmp_dir) / 'MyShow.java'
with open(fp, 'w') as f:
    f.write(java_code)

javac = pathlib.Path(os.environ[ 'JAVA_HOME' ]) / 'bin' / 'javac'

proc = subprocess.run( 
    [ str(javac), '-cp', str(jnius_config.split_char.join( jnius_config.get_classpath()) ), str(fp) ],
    stdout=subprocess.PIPE,
    stderr=subprocess.PIPE)

if proc.returncode != 0:
	print (proc.stderr)

MyShow = autoclass('MyShow')

xmlFilename = 'Y:\\test\\data.xml'

spimData = autoclass('bdv.spimdata.SpimDataMinimal')
spimXML = autoclass('bdv.spimdata.XmlIoSpimDataMinimal')

spimData = spimXML().load(xmlFilename)
print(spimData)

MyShow.show(spimData)
2 Likes

Glad to hear you got it to work and thank you for sharing the code. If this solves your initial question, you can mark any post as a answer for this thread and the forum will show this with a check mark. In this case it’s probably best to mark your own reply as the answer.

1 Like