def test_stretch(): np.random.seed(2323) A = np.random.random_integers(12, 120, size=(100,100)) A = stretch(A, 255) assert A.max() > 250 assert A.min() == 0 A = stretch(A,20) assert A.max() <= 20 A = stretch(A, 10, 20) assert A.min() >= 10 A = stretch(A * 0, 10, 20) assert A.min() >= 10
def preprocessimg(img): if len(img.shape) > 2: assert len(img.shape) == 3, "Cannot handle images of more than 3 dimensions." if options.get('3d.mode','perslice') == 'perslice': nr_slices=img.shape[0] out_proc=img.copy() out_res=img.copy() for z in xrange(nr_slices): proc,res=preprocessimg(img[z]) out_proc[z]=proc out_res[z]=res return out_proc,out_res else: raise Exception('pyslic.preprocessimg: Do not know how to handle 3d.mode: %s' % options['3d.mode']) if do_bgsub: regions = image.regions img = img.copy() if regions is not None: rid = (regionid if regionid is not None else 1) if options.get('bgsub.way','ml') == 'ml': img *= (regions == rid) img = bgsub(img, options) else: img = bgsub(img, options) img *= (cropimg == rid) else: if regionid: warn('Selecting a region different from 1 for an image without region information') img = bgsub(img, options) imgscaled = stretch(img, 255) T = thresholdfor(imgscaled,options) mask = (imgscaled > T) mask = majority_filter(mask) residual = img.copy() img *= mask residual *= ~mask return img,residual
def preprocessimg(img): if len(img.shape) > 2: assert len(img.shape) == 3, "Cannot handle images of more than 3 dimensions." if options.get("3d.mode", "perslice") == "perslice": nr_slices = img.shape[0] out_proc = img.copy() out_res = img.copy() for z in xrange(nr_slices): proc, res = preprocessimg(img[z]) out_proc[z] = proc out_res[z] = res return out_proc, out_res else: raise Exception("pyslic.preprocessimg: Do not know how to handle 3d.mode: %s" % options["3d.mode"]) if do_bgsub: regions = image.regions img = img.copy() if regions is not None: if options.get("bgsub.way", "ml") == "ml": img *= regions == regionid img = bgsub(img, options) else: img = bgsub(img, options) img *= cropimg == regionid else: if regionid: warn("Selecting a region different from 1 for an image without region information") img = bgsub(img, options) imgscaled = stretch(img, 255) T = thresholdfor(imgscaled, options) mask = imgscaled > T mask = majority_filter(mask) residual = img.copy() img *= mask residual *= ~mask return img, residual
def test_neg_numbers(): A = np.arange(-10,10) scaled = stretch(A, 255) assert scaled.shape == A.shape assert scaled.min() <= 1 assert scaled.max() >= 254