def test_threshold2(img): img.threshold(thresholds=[80, 210], values=[0, 127, 255]) expected = Image.fromArray( np.array([[127, 255, 0], [127, 0, 255], [255, 127, 0]])) assert img == expected
def test_categorize2(img): expected = Image.fromArray( np.array([[255, 255, 100], [100, 0, 255], [255, 100, 0]])) img.categorize(3, initial_clusters=[2, 99, 254]) assert img == expected
def test_threshold1(img): img.threshold(thresholds=[127], values=[0, 255]) expected = Image.fromArray( np.array([[255, 255, 0], [0, 0, 255], [255, 0, 0]])) assert img == expected
def test_from_list(): data1 = np.array([[0, 255], [255, 100]]) data2 = np.array([[100, 255], [255, 0]]) input_data = [data1, data2] expected = np.array(input_data) img = Image.fromArray(input_data).asArray() assert np.alltrue(img == expected)
def test_threshold(): image = Image.fromArray(np.array([[0.3, 3.0], [1.2, 2.4], [2.1, 1.1]])) categorical_ref = np.array([[0, 2], [1, 2], [2, 1]]) thresholds = np.array([1.0, 2.0]) image.threshold(thresholds) labels = mpstool.img.labelize(image) assert np.alltrue(labels == categorical_ref)
def test_categorize1(img): expected = Image.fromArray( np.array([[255, 255, 100], [100, 100, 255], [255, 100, 100]])) print(img._data) img.categorize(2) print(img._data) assert img == expected
def generate(epoch, generator, N, args, device, exportCuts=False): os.makedirs("output/epoch", exist_ok=True) for i in range(N): output = generator.generate(1, device).cpu().detach() if exportCuts: cuts = extract_3cuts(output)[0].permute(1, 2, 0) cuts = (255 * cuts.numpy()).astype(np.uint8) for ind, dim in enumerate(["x", "y", "z"]): cut_dim = PILImage.fromarray(cuts[..., ind]) cut_dim.save("output/epoch/{}_{}_{}.png".format( args.name, i, dim)) output = output.numpy() output = (output * 255).astype(np.uint8) output = np.squeeze(output) output = Image.fromArray(output) output.exportAsVox("output/epoch/{}_{}.vox".format(args.name, i))
def img(): data = np.array([[200, 255, 60], [100, 10, 255], [250, 100, 0]]) return Image.fromArray(data)
def image(): return Image.fromArray(array())
def cube_image(cube): return Image.fromArray(cube)
min_dict[k] = min_dict[k].clip(0, 1) max_dict[k] = mean_dict[k] + std_dict[k] max_dict[k] = max_dict[k].clip(0, 1) # Read connectivity for the realizations cX = [] cY = [] cZ = [] cX_mean = {} cY_mean = {} cZ_mean = {} for n in tqdm(range(args.n_samples)): image = model.generate().to("cpu").detach().numpy() * 255 image = np.squeeze(image).astype(np.uint8) image = Image.fromArray(image) image.threshold(thresholds=[254], values=[0, 1]) connZ = stat_fun(image, axis=2) cZ.append(connZ) cZ_mean = {k: cZ_mean.get(k, 0) + connZ.get(k, 0) for k in set(connZ)} connX = stat_fun(image, axis=1) cX.append(connX) cX_mean = {k: cX_mean.get(k, 0) + connX.get(k, 0) for k in set(connX)} connY = stat_fun(image, axis=0) cY.append(connY) cY_mean = {k: cY_mean.get(k, 0) + connY.get(k, 0) for k in set(connY)} cX_mean = {k: cX_mean.get(k, 0) / args.n_samples for k in cX_mean.keys()}