コード例 #1
0
def gif_from_slices(dwi_in, oname, slice_type=2, slice_index=None, dt=0.1):
    min_val = dwi_in.min()
    max_val = dwi_in.max()
    dwi = (255 * ((dwi_in - min_val) / (max_val - min_val))).astype(np.uint8)
    if slice_index is None:
        slice_index = dwi.shape[slice_type] // 2
    n = dwi.shape[3]
    if slice_type == 0:
        slices = [dwi[slice_index, :, :, i].T[::-1, :] for i in range(n)]
    if slice_type == 1:
        slices = [dwi[:, slice_index, :, i].T[::-1, :] for i in range(n)]
    if slice_type == 2:
        slices = [dwi[:, :, slice_index, i].T[::-1, :] for i in range(n)]
    writeGif(oname, slices, duration=dt, dither=0)
コード例 #2
0
def create_dwi_gif(fname, dwi, axis=0, duration=0.5):
    try:
        from experiments.registration.images2gif import writeGif
    except:
        print ("experiments.registration module unavailable. Gif will not be generated.")
        return
    sh = dwi.shape
    n = sh[3]
    mid_slice = sh[axis] // 2
    images = []
    for i in range(n):
        if axis == 0:
            slice = dwi[mid_slice, :, :, i]
        elif axis == 1:
            slice = dwi[:, mid_slice, :, i]
        else:
            slice = dwi[:, :, mid_slice, i]
        slice = (254 * (slice.astype(np.float64) / slice.max())).astype(np.uint8).T[::-1, :]
        images.append(slice)
    writeGif(fname, images, duration=duration)
コード例 #3
0
    except:
        print ("experiments.registration module unavailable. Gif will not be generated.")
        return
    sh = dwi.shape
    n = sh[3]
    mid_slice = sh[axis] // 2
    images = []
    for i in range(n):
        if axis == 0:
            slice = dwi[mid_slice, :, :, i]
        elif axis == 1:
            slice = dwi[:, mid_slice, :, i]
        else:
            slice = dwi[:, :, mid_slice, i]
        slice = (254 * (slice.astype(np.float64) / slice.max())).astype(np.uint8).T[::-1, :]
        images.append(slice)
    writeGif(fname, images, duration=duration)


if __name__ == "__main__":
    im = np.zeros((200, 200, 3), dtype=np.uint32)
    f1 = im.copy()
    f1[10:30, :, 0] = 100
    f2 = im.copy()
    f2[:, 80:120, 1] = 255
    f3 = im.copy()
    f3[-50:-40, :, 2] = 50

    images = [f1, f2, f3, im]
    writeGif("lala3.gif", images, duration=0.5, dither=0)