How to count number of open files under using Python

I have the following code:

from ij import IJ
from ij.plugin import FolderOpener
imp ="~/MyDir/", " file="(*bw.png) sort virtual")
nof_column = 4, "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"~/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?

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