Commit 15eae51e by Jiri Borovec

fix, unordered fn map()

parent adda4897
......@@ -109,43 +109,49 @@ def crop_images(imgs, v_lim=0.):
return imgs_crop
def threshold_image_fix(img):
def threshold_image_fix(idx_img):
""" treashold imahe with givem value in range (0, 1)
:param img:
:return:
"""
idx, img = idx_img
img_th = img > IMAGE_BINARY_THRESHOLD
return img_th
return idx, img_th
def threshold_image_otsu(img):
def threshold_image_otsu(idx_img):
idx, img = idx_img
th = filters.threshold_otsu(img[img > 0])
logger.debug('threshold with val: {}'.format(th))
img_th = img > th
return img_th
return idx, img_th
def threshold_image_adapt(img):
def threshold_image_adapt(idx_img):
idx, img = idx_img
img_th = filters.threshold_adaptive(img, 450)
selem = morphology.disk(12)
img_th = morphology.opening(img_th, selem)
return img_th
return idx, img_th
def threshold_image_3cls_gene(img):
def threshold_image_3cls_gene(idx_img):
idx, img = idx_img
img_th = img >= (2 / 3.)
return img_th
return idx, img_th
def threshold_image_3cls_disc(img):
def threshold_image_3cls_disc(idx_img):
idx, img = idx_img
img_th = img >= (1 / 3.)
return img_th
return idx, img_th
def scale_image(img):
def scale_image(idx_img):
idx, img = idx_img
img_scale = transform.rescale(img, scale=0.5, order=0)
return img_scale
return idx, img_scale
def apply_images(imgs, func, nb_jobs=NB_THREADS):
......@@ -160,12 +166,13 @@ def apply_images(imgs, func, nb_jobs=NB_THREADS):
if nb_jobs > 1:
logger.info('running in %i threads...', nb_jobs)
mproc_pool = mproc.Pool(nb_jobs)
imgs_final = mproc_pool.map(func, imgs)
idx_imgs = mproc_pool.map(func, enumerate(imgs))
mproc_pool.close()
mproc_pool.join()
else:
logger.info('running single thread')
imgs_final = [func(im) for im in imgs]
idx_imgs = [func(im) for im in enumerate(imgs)]
imgs_final = [img for _, img in sorted(idx_imgs)]
return imgs_final
......
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