Example #1
0
def main():
    args = surfcut_parser().parse_args()

    image_path = args.image_path
    print(image_path)
    data = tifffile.imread(image_path)

    print(data.shape)
    view(data)
Example #2
0
def main():
    start_time = datetime.now()
    args = surfcut_parser().parse_args()

    image_path = args.image_path

    print("Loading data")
    data = tifffile.imread(image_path)

    print("Converting to 8 bit")
    data = data.astype(np.uint8)

    print("Smoothing")
    filtered = np.copy(data)
    for idx, plane in enumerate(filtered):
        filtered[idx] = filters.gaussian_filter(plane, args.gauss_sigma)

    print("Thresholding")
    binary = filtered > args.threshold
    del filtered
    print("Detecting edges")
    binary = edge_detect(binary)

    print("Shifting binary object down")
    shift_mag = int(args.shift + (args.depth / 2))
    down_shift = binary[0:-shift_mag]
    padding = np.zeros((shift_mag, binary.shape[1], binary.shape[2]))
    down_shift = np.append(padding, down_shift, axis=0)

    print("Shifting binary object up")
    shift_mag = int(args.shift - (args.depth / 2))
    up_shift = binary[0:-shift_mag]
    padding = np.zeros((shift_mag, binary.shape[1], binary.shape[2]))
    up_shift = np.append(padding, up_shift, axis=0)
    del binary

    print("Generating mask")
    mask = up_shift - down_shift
    del up_shift
    del down_shift
    mask = mask > 0

    print("Masking data")
    masked = data * mask

    print("Projecting data")
    projection = np.max(masked, axis=0)

    print(f"Finished. Total time taken: {format(datetime.now() - start_time)}")

    if not args.no_viewer:
        print("Opening viewer")
        view(data, masked, projection)
Example #3
0
def straight(data, mask):
    args = surfcut_parser().parse_args()
    imarray_real = numpy.array(data)
    imarray = numpy.array(mask)
    imdim = imarray.shape
    zthick = args.depth
    straightened = numpy.empty((zthick, imdim[1], imdim[2]))

    for i in range(1, imdim[1], 5):
        for j in range(1, imdim[2], 5):
            index = list(zip(*numpy.where(imarray[:, i, j] == True)))
            if index:
                index_first = index[0][0]
                if (index_first + args.depth + args.shift) < imdim[0]:
                    straightened[0:zthick, (i - 2):(i + 3),
                                 (j - 2):(j + 3)] = imarray_real[(
                                     index_first +
                                     args.shift):(index_first + args.shift +
                                                  args.depth), (i - 2):(i + 3),
                                                                 (j - 2):(j +
                                                                          3), ]

    return straightened