How to count number of open files under FolderOpener.open() using Python

I have the following code:

from ij import IJ
from ij.plugin import FolderOpener
imp = FolderOpener.open("~/MyDir/", " file="(*bw.png) sort virtual")
nof_column = 4
IJ.run(imp, "Make Montage...", "columns=" + nof_column + " rows=3 scale=1 font=30 label")

Basically what I want to do is you count the number of files opened by FolderOpener.open("~/MyDir/", " file="(*bw.png) sort virtual") then later use that to decide how many column to use to create montage.

How can I use python method to get access of the number of files?

Hi,
what about from the imp returned by the FolderOpener
n = imp.getImageStackSize()