コード例 #1
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
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
コード例 #2
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
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
コード例 #3
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
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
コード例 #4
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
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)
コード例 #5
0
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)
コード例 #6
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
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
コード例 #7
0
ファイル: train.py プロジェクト: randlab/diaGAN
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))
コード例 #8
0
ファイル: test_image.py プロジェクト: UniNE-CHYN/mps_toolbox
def img():
    data = np.array([[200, 255, 60],
                     [100, 10, 255],
                     [250, 100, 0]])
    return Image.fromArray(data)
コード例 #9
0
def image():
    return Image.fromArray(array())
コード例 #10
0
def cube_image(cube):
    return Image.fromArray(cube)
コード例 #11
0
ファイル: stats_torch.py プロジェクト: randlab/diaGAN
            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()}