Esempio n. 1
0
def test_conversion_color2():
    img = Image.fromGslib("tests/data/test_color.gslib")
    img.exportAsPng("tests/data/test_color.png", colored=True)
    img = Image.fromGslib("tests/data/test_color.gslib")
    img.exportAsPpm("tests/data/test_color.ppm")
    img2 = Image.fromPng("tests/data/test_color.png")
    img3 = Image.fromPpm("tests/data/test_color.ppm")
    assert np.alltrue((img.asArray()-img2.asArray()) < 1e8)
    assert img == img3
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
def test_import_gslb2var():
    img = Image.fromGslib("tests/data/2var.gslib")
    var1 = img.asArray("V0").reshape((3, 3))
    var2 = img.asArray("V1").reshape((3, 3))
    expected1 = np.array([[1, 1, 1], [1, 1, 1], [0, 0, 0]])
    expected2 = np.array([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
    assert np.alltrue(var1 == expected1)
    assert np.alltrue(var2 == expected2)
Esempio n. 6
0
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)
Esempio n. 8
0
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
Esempio n. 9
0
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))
Esempio n. 10
0
def test_from_txt(img):
    img1 = Image.fromTxt("tests/data/test_img.txt", (3, 3))
    img2 = Image.fromTxt("tests/data/test_img.txt", (3, 3, 1))
    assert img == img1
    assert img == img2
Esempio n. 11
0
def cube_image(cube):
    return Image.fromArray(cube)
Esempio n. 12
0
def image():
    return Image.fromArray(array())
Esempio n. 13
0
def test_vtk_pgm():
    img = Image.fromVtk("tests/data/test_img.vtk")
    img.exportAsPgm("tests/data/test_img.pgm")
    img2 = img.fromPgm("tests/data/test_img.pgm")
    assert np.alltrue(img == img2)
Esempio n. 14
0
def test_conversion_txt_gslib():
    img = Image.fromTxt("tests/data/test_img.txt", (3, 3))
    img.exportAsGslib("tests/data/test_img.gslib")
    img_test = Image.fromGslib("tests/data/test_img.gslib")
    assert np.alltrue(img_test == img)
Esempio n. 15
0
def img():
    data = np.array([[200, 255, 60],
                     [100, 10, 255],
                     [250, 100, 0]])
    return Image.fromArray(data)
Esempio n. 16
0
def test_conversion_png_txt():
    img = Image.fromPng("tests/data/test_img.png")
    img.exportAsTxt("tests/data/test_img2.txt")
    img_test = Image.fromTxt("tests/data/test_img2.txt", (3, 3))
    assert np.alltrue(img_test == img)
Esempio n. 17
0
def test_conversion_vox_png():
    img = Image.fromVox("tests/data/test_img.vox")
    img.exportAsPng("tests/data/test_img.png")
    img_test = Image.fromPng("tests/data/test_img.png")
    assert np.alltrue(img_test == img)
Esempio n. 18
0
if __name__ == "__main__":
    parser = argparse.ArgumentParser()

    parser.add_argument("-fun", "--fun", type=str, required=True)
    parser.add_argument('-model', "--model", type=str, required=True)
    parser.add_argument('-ti', "--ti", type=str, required=True)
    parser.add_argument('-output', "--output", type=str, default="output.csv")
    parser.add_argument("-n-samples", "--n-samples", type=int, default=100)
    parser.add_argument("-n-ti", "--n-ti", type=int, default=100)

    args = parser.parse_args()
    model = GAN(args.model)

    if ".vox" in args.ti:
        ti = Image.fromVox(args.ti)
    elif ".gslib" in args.ti:
        ti = Image.fromGslib(args.ti)

    ti.threshold(thresholds=[1], values=[0, 1])
    ti = ti.asArray()

    if args.fun == "conn":
        stat_fun = mpstool.connectivity.get_function
    elif args.fun == "vario":
        stat_fun = mpstool.stats.variogram
    else:
        raise Exception(
            "argument -fun not recognized. Should be 'conn' or 'vario' ")

    # Read connectivity for the TI : min and max of values
Esempio n. 19
0
def test_gslib_to_vtk():
    img = Image.fromGslib("tests/data/test_img.gslib")
    img.exportAsVtk("tests/data/test_img.vtk")
    img2 = img.fromVtk("tests/data/test_img.vtk")
    assert np.alltrue(img == img2)
Esempio n. 20
0
def test_gslib_io():
    img = Image.fromGslib("tests/data/test_color_simple.gslib")
    img.exportAsGslib("tests/data/test_color_simple2.gslib")
    img = Image.fromGslib("tests/data/test_color_simple.gslib")
    img2 = Image.fromGslib("tests/data/test_color_simple2.gslib")
    assert(img == img2)
Esempio n. 21
0
def test_pgm_vox():
    img = Image.fromPgm("tests/data/test_img.pgm")
    img.exportAsVox("tests/data/test_img.vox")
    img_test = Image.fromVox("tests/data/test_img.vox")
    assert np.alltrue(img_test == img)
Esempio n. 22
0
    parser.add_argument('-ti', "--ti", type=str, required=True)
    parser.add_argument('-output', "--output", type=str, default="output.csv")
    parser.add_argument("-n-samples", "--n-samples", type=int, default=100)
    parser.add_argument("-n-ti", "--n-ti", type=int, default=100)

    args = parser.parse_args()
    model = Generator(256)
    if not torch.cuda.is_available():
        model = model.to("cpu")
        model.load_state_dict(torch.load(args.model, map_location="cpu"))
    else:
        model = model.to("cuda")
        model.load_state_dict(torch.load(args.model))

    if ".vox" in args.ti:
        ti = Image.fromVox(args.ti)
    elif ".gslib" in args.ti:
        ti = Image.fromGslib(args.ti)
    ti.threshold(thresholds=[1], values=[0, 1])
    ti = ti.asArray()

    if args.fun == "conn":
        stat_fun = mpstool.connectivity.get_function
    elif args.fun == "vario":
        stat_fun = mpstool.stats.variogram
    else:
        raise Exception(
            "argument mode not recognized. Should be 'conn' or 'vario' ")

    # Read connectivity for the TI : min and max of values
    cX_ti = []