Bioformat does not open files using Jython

Hi everyone,

I struggle hard with the bioformat in jython. I use this script :

from ij import IJ
from ij.process import ImageConverter as IC
import os
import sys
from ij.gui import WaitForUserDialog
from import FileSaver
from import DirectoryChooser
from ij import IJ, ImagePlus, VirtualStack
from ij.gui import Overlay
from loci.plugins import BF
indc = DirectoryChooser("Input")
outdc = DirectoryChooser("Output")
indir = indc.getDirectory()
outdir = outdc.getDirectory()

if indir==outdir :
	print "Input can't be the same directory as output."

#if (selectionType() != 0) :
#	myWait = WaitForUserDialog ("Warning", "Please, select a proper ROI")

for filename in os.listdir(indir):
	if filename.endswith(".lif"):
		imps = BF.openImagePlus(indir+filename)
		for imp in imps:
	if filename.endswith(".tif"):
		print "Processing ",filename
		imp = IJ.openImage(os.path.join(indir, filename))
		if imp is None :
			print "Could not open files in the selected directory :", filename 
	myWait = WaitForUserDialog ("Waiting", "Select ROI")
#		if contains(Roi) == False :
#			print "No ROI selected", "Make Inverse", "slice"), "Clear", "stack"), "Select None", "")
	fs = FileSaver(imp)

I struggle opening .lif files. In a reaaally weird way this codes properly works if I previously open a picture. But with nothing opened, it stops with “There is no image opened” message. It makes this error following the imp = IJ.getImage() command…

I tried for a week between my experiments to resolve this issue… So if you have some suggestions other than linking to website or subject I probably already watched. (Fiji website, a lot of posts concerning bioformat, bioformat library etc.)

Thanks a lot & have a very nice week-end.

What if you run only the part before IJ.getImage() (in the editor, Run>Run selected code)
Does any image shows up ?

But I wonder why you use IJ.getImage if you already have a variable imps or imp that contains the ImagePlus object…

1 Like

Really nice suggestion, it opens every picture in the selected directory.

I used IJ.getImage because I am a beginner, and i did not know that I could use it without defining it thanks to the previous imp variable.

I then tried to erase imp = IJ.getImage()
1st : It asks me to select an ROI (waitforuser) , while there are no opened picture.
2nd : It makes an error saying “Imp is not defined”

Update : For a strange reason that makes no sense to me. It now works using the code above. I changed nothing but it now works. Bioformat is a strange world.

1 Like