Skip to content
Snippets Groups Projects

Many changes

Merged Amir MOHAMMADI requested to merge amir into master
13 files
+ 581
617
Compare changes
  • Side-by-side
  • Inline

Files

#!/usr/bin/env python
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
"""Script that computes statistics for image.
# @author: Tiago de Freitas Pereira <tiago.pereira@idiap.ch>
# @date: Wed 11 May 2016 09:39:36 CEST
"""
"""
Script that computes statistics for image
from __future__ import absolute_import
from __future__ import division
Usage:
from __future__ import print_function
compute_statistics.py <base_path> <output_file> --extension=<arg>
# import pkg_resources so that bob imports work properly:
compute_statistics.py -h | --help
import pkg_resources
Options:
-h --help Show this screen.
--extension=<arg> [default: .hdf5]
"""
from docopt import docopt
import bob.io.base
import os
import os
 
import logging
 
import click
import numpy
import numpy
import bob.io.image
import bob.io.image # to be able to load images
 
from bob.io.base import save, load
 
from bob.extension.scripts.click_helper import verbosity_option
 
 
logger = logging.getLogger(__name__)
def process_images(base_path, extension, shape):
def process_images(base_path, extension, shape):
files = os.listdir(base_path)
files = os.listdir(base_path)
sum_data = numpy.zeros(shape=shape)
sum_data = numpy.zeros(shape=shape)
print("Processing {0}".format(base_path))
logging.info("Processing {0}".format(base_path))
count = 0
count = 0
for f in files:
for f in files:
path = os.path.join(base_path, f)
path = os.path.join(base_path, f)
@@ -34,27 +31,34 @@ def process_images(base_path, extension, shape):
@@ -34,27 +31,34 @@ def process_images(base_path, extension, shape):
sum_data += s
sum_data += s
if os.path.splitext(path)[1] == extension:
if os.path.splitext(path)[1] == extension:
data = bob.io.base.load(path)
data = load(path)
count += 1
count += 1
sum_data += data
sum_data += data
return count, sum_data
return count, sum_data
def main():
@click.command()
args = docopt(__doc__, version='Mnist training with TensorFlow')
@click.argument('base_path')
 
@click.argument('output_file')
 
@click.option('--extension', default='.hdf5', show_default=True)
 
@verbosity_option()
 
def compute_statistics(base_path, output_file, extension, **kwargs):
 
"""Script that computes statistics for image.
 
"""
 
logger.debug('base_path: %s', base_path)
 
logger.debug('output_file: %s', output_file)
 
logger.debug('extension: %s', extension)
 
logger.debug('kwargs: %s', kwargs)
BASE_PATH = args['<base_path>']
# SHAPE = [3, 224, 224]
EXTENSION = args['--extension']
OUTPUT_FILE = args['<output_file>']
#SHAPE = [3, 224, 224]
SHAPE = [1, 64, 64]
SHAPE = [1, 64, 64]
count, sum_data = process_images(BASE_PATH, EXTENSION, SHAPE)
count, sum_data = process_images(base_path, extension, SHAPE)
means = numpy.zeros(shape=SHAPE)
means = numpy.zeros(shape=SHAPE)
for s in range(SHAPE[0]):
for s in range(SHAPE[0]):
means[s, ...] = sum_data[s, ...] / float(count)
means[s, ...] = sum_data[s, ...] / float(count)
bob.io.base.save(means, OUTPUT_FILE)
save(means, output_file)
bob.io.base.save(means[0, :, :].astype("uint8"), "xuxa.png")
save(means[0, :, :].astype("uint8"), "xuxa.png")
Loading