More efficient hash-based search in getNumberOfImages