Commit 466ba443 authored by André Anjos's avatar André Anjos 💬

Improve sample viewing script

parent a652bf39
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Mon 07 Nov 2016 15:20:26 CET
"""Visualizes masks applied to vein imagery
Usage: %(prog)s [-v...] [options] <file> [<file>...]
%(prog)s --help
%(prog)s --version
Arguments:
<file> The HDF5 file to load image and mask from
Options:
-h, --help Shows this help message and exits
-V, --version Prints the version and exits
-v, --verbose Increases the output verbosity level
-s path, --save=path If set, saves image into a file instead of displaying
it
Examples:
Visualize the mask on a single image:
$ %(prog)s data.hdf5
Visualize multiple masks (like in a proof-sheet):
$ %(prog)s *.hdf5
"""
import os
import sys
import bob.core
logger = bob.core.log.setup("bob.bio.vein")
from ..preprocessor import utils
def main(user_input=None):
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import docopt
import pkg_resources
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('bob.bio.vein')[0].version
)
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
# Sets-up logging
verbosity = int(args['--verbose'])
bob.core.log.set_verbosity_level(logger, verbosity)
# Loads the image, the mask and save it to a PNG file
from ..preprocessor import utils
for filename in args['<file>']:
f = bob.io.base.HDF5File(filename)
image = f.read('image')
mask = f.read('mask')
img = utils.draw_mask_over_image(image, mask)
if args['--save']:
img.save(args['--save'])
else:
img.show()
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Mon 07 Nov 2016 15:20:26 CET
"""Visualizes a particular sample throughout many processing stages
Usage: %(prog)s [-v...] [-s <path>] <database> <processed> <stem> [<stem>...]
%(prog)s --help
%(prog)s --version
Arguments:
<database> Path to the database with the image to be inspected
<processed> Path with the directory holding the preprocessed and extracted
sub-directories containing the processing results of a
bob.bio.vein toolchain
<stem> Name of the object on the database to display, with the root or
the extension
Options:
-h, --help Shows this help message and exits
-V, --version Prints the version and exits
-v, --verbose Increases the output verbosity level
-s <path>, --save=<path> If set, saves image into a file instead of
displaying it
Examples:
Visualize to processing toolchain over a single image
$ %(prog)s /database /mc client/sample
Visualize multiple masks (like in a proof-sheet):
$ %(prog)s /database /mc client/sample1 client/sample2
"""
import os
import sys
import numpy
import bob.core
logger = bob.core.log.setup("bob.bio.vein")
import matplotlib.pyplot as mpl
from ..preprocessor import utils
import bob.io.base
import bob.io.image
def save_figures(title, image, mask, image_pp, binary):
'''Saves individual images on a directory
Parameters:
title (str): A title for this plot
image (numpy.ndarray): The original image representing the finger vein (2D
array with dtype = ``uint8``)
mask (numpy.ndarray): A 2D boolean array with the same size of the original
image containing the pixels in which the image is valid (``True``) or
invalid (``False``).
image_pp (numpy.ndarray): A version of the original image, pre-processed by
one of the available algorithms
binary (numpy.ndarray): A binarized version of the original image in which
all pixels (should) represent vein (``True``) or not-vein (``False``)
'''
os.makedirs(title)
bob.io.base.save(image, os.path.join(title, 'original.png'))
# add preprocessed image
from ..preprocessor import utils
img = utils.draw_mask_over_image(image_pp, mask)
img = numpy.array(img).transpose(2,0,1)
bob.io.base.save(img[:3], os.path.join(title, 'preprocessed.png'))
# add binary image
bob.io.base.save(binary.astype('uint8')*255, os.path.join(title,
'binarized.png'))
def proof_figure(title, image, mask, image_pp, binary):
'''Builds a proof canvas out of individual images
Parameters:
title (str): A title for this plot
image (numpy.ndarray): The original image representing the finger vein (2D
array with dtype = ``uint8``)
mask (numpy.ndarray): A 2D boolean array with the same size of the original
image containing the pixels in which the image is valid (``True``) or
invalid (``False``).
image_pp (numpy.ndarray): A version of the original image, pre-processed by
one of the available algorithms
binary (numpy.ndarray): A binarized version of the original image in which
all pixels (should) represent vein (``True``) or not-vein (``False``)
Returns:
matplotlib.pyplot.Figure: A figure canvas containing the proof for the
particular sample on the database
'''
fig = mpl.figure(figsize=(6,9), dpi=50) #900 x 300 pixels
# add original image
mpl.subplot(3, 1, 1)
mpl.title('%s - original' % title)
mpl.imshow(image, cmap="gray")
# add preprocessed image
from ..preprocessor import utils
img = utils.draw_mask_over_image(image_pp, mask)
mpl.subplot(3, 1, 2)
mpl.title('Preprocessed')
mpl.imshow(img)
# add binary image
mpl.subplot(3, 1, 3)
mpl.title('Binarized')
mpl.imshow(binary.astype('uint8')*255, cmap="gray")
return fig
def main(user_input=None):
if user_input is not None:
argv = user_input
else:
argv = sys.argv[1:]
import docopt
import pkg_resources
completions = dict(
prog=os.path.basename(sys.argv[0]),
version=pkg_resources.require('bob.bio.vein')[0].version
)
args = docopt.docopt(
__doc__ % completions,
argv=argv,
version=completions['version'],
)
# Sets-up logging
verbosity = int(args['--verbose'])
bob.core.log.set_verbosity_level(logger, verbosity)
# Loads the image, the mask and save it to a PNG file
for stem in args['<stem>']:
image = bob.bio.base.load(os.path.join(args['<database>'], stem + '.png'))
pp = bob.io.base.HDF5File(os.path.join(args['<processed>'],
'preprocessed', stem + '.hdf5'))
mask = pp.read('mask')
image_pp = pp.read('image')
binary = bob.io.base.load(os.path.join(args['<processed>'],
'extracted', stem + '.hdf5'))
fig = proof_figure(stem, image, mask, image_pp, binary)
#fig.title(stem)
if args['--save']:
#fig.savefig(args['--save'])
save_figures(args['--save'], image, mask, image_pp, binary)
else:
mpl.show()
print('Close window to continue...')
...@@ -346,23 +346,30 @@ mask ...@@ -346,23 +346,30 @@ mask
can use the option ``-n 5`` to print the 5 worst cases according to each of the can use the option ``-n 5`` to print the 5 worst cases according to each of the
metrics. metrics.
You can use the program ``view_mask.py`` to display the images after the You can use the program ``view_sample.py`` to display the images after
preprocessing step using: full processing using:
.. code-block:: sh .. code-block:: sh
$ view_mask.py /path/to/verafinger/mc/preprocessed/098-F/098_R_1.hdf5 --save=example.png $ ./bin/view_sample.py /path/to/verafinger/database /path/to/bob-bio-vein/output/for/toolchain 030-M/030_L_1 -s output-directory
$ # open example.png $ # open output-directory
And you should be able to view an image like this (example taken from the Vera And you should be able to view images like these (example taken from the Vera
fingervein database, using the automatic annotator): fingervein database, using the automatic annotator and Maximum Curvature
feature extractor):
.. figure:: img/vein-mask.* .. figure:: img/preprocessed.*
:scale: 50% :scale: 50%
Example RoI overlayed on finger vein image of the Vera fingervein database, Example RoI overlayed on finger vein image of the Vera fingervein database,
as produced by the script ``view_mask.py``. as produced by the script ``view_sample.py``.
.. figure:: img/binarized.*
:scale: 50%
Example of fingervein image from the Vera fingervein database, binarized by
using Maximum Curvature, after pre-processing.
.. include:: links.rst .. include:: links.rst
...@@ -14,3 +14,4 @@ bob.db.verafinger ...@@ -14,3 +14,4 @@ bob.db.verafinger
bob.db.putvein bob.db.putvein
bob.db.fv3d bob.db.fv3d
scikit-image scikit-image
matplotlib
...@@ -48,7 +48,7 @@ setup( ...@@ -48,7 +48,7 @@ setup(
'console_scripts': [ 'console_scripts': [
'compare_rois.py = bob.bio.vein.script.compare_rois:main', 'compare_rois.py = bob.bio.vein.script.compare_rois:main',
'view_mask.py = bob.bio.vein.script.view_mask:main', 'view_sample.py = bob.bio.vein.script.view_sample:main',
'blame.py = bob.bio.vein.script.blame:main', 'blame.py = bob.bio.vein.script.blame:main',
] ]
}, },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment