Commit 829b6221 authored by Franck Thollard's avatar Franck Thollard
Browse files

building abspath of images

parent 00b8c248
......@@ -13,7 +13,6 @@ Note:
import numpy as np
from scipy import ndimage
from scipy import misc
import os
import sys
......@@ -24,6 +23,7 @@ import argparse
# change this to be less verbose when running it
def load_img_set(img_list):
""" load a set of images as a stacked numpy array
......@@ -44,47 +44,48 @@ def load_img_set(img_list):
# compute the shape from the first image
img_arr = misc.imread(img_list[0])
img_arr = misc.imread(os.path.join(, img_list[0]))
shape0 = img_arr.shape
all_frames = np.empty((len(img_list), shape0[0], shape0[1], 3))
all_frames[0,:,:,:] = img_arr[:,:,:]
all_frames[0, :, :, :] = img_arr[:, :, :]
# loading the images:
for k, img_name in enumerate(img_list[1:]):
img_arr = misc.imread(img_name)
img_arr = misc.imread(os.path.join(, img_name))
if img_arr.shape != shape0:
all_frames = None
logging.error("image {} and {} do not share the same shape ({} vs {}".format(
img_list[0], img_name, shape0, img_arr.shape))
raise RuntimeError("shape mismatch between images")
all_frames[k,:,:,:] = img_arr[:,:,:]
all_frames[k, :, :, :] = img_arr[:, :, :]
# now all_frames[i] is an image
logging.debug("all frames loaded: all_frames shape is {}".format(all_frames.shape))
return all_frames
if __name__ == "__main__":
parser = argparse.ArgumentParser(description = "extract background from a set of images")
parser = argparse.ArgumentParser(description="extract background from a set of images")
parser.add_argument("-d", "--directory", type=str, default=".",
help="the directory where to find the images (default .)")
parser.add_argument("-o", "--output", type=str, default="median.jpg",
help="the output image (default median.jpg)")
parser.add_argument("-p", "--pattern", type=str, default=".jpg",
help="pattern to look for (default=.jpg)")
help="pattern to look for (default=.jpg)")
parser.add_argument("-H", action="store_true",
help="provides informations on the algorithm (and its limitations)")
args = parser.parse_args()
if args.H:
# get the list of images
img_list = [x for x in os.listdir(args.d) if x.endswith(args.p)]
img_list = [x for x in os.listdir( if x.endswith(args.pattern)]
if len(img_list) == 0:
logging.critical("no file found in {} with ending by {}, aborting",
args.d, args.p), args.pattern)
sys.exit(1)"%d images read", len(img_list))
logging.debug("img list = {}".format(img_list))
......@@ -99,9 +100,4 @@ if __name__ == "__main__":
median_img = np.median(all_frames, axis=0)
# save the new image as jpeg:
misc.imsave(args.o, median_img)
misc.imsave(args.output, median_img)
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