Ejemplo n.º 1
0
def tif_to_png(input, output):

    stack = tifread(input)
    os.chdir(output)

    for i, slice in enumerate(stack):
        pictures = Image.fromarray(slice)
        pictures.save('%02d.png' % i)
        print(str(i + 1) + "/" + str(len(stack)) + " files created")
Ejemplo n.º 2
0
def membrane(input, output):

    stack = tifread(input)
    os.chdir(output)

    for i, slice in enumerate(stack):
        edges_compared = edges(slice)
        pictures = Image.fromarray(edges_compared.astype('uint8') * 255)
        pictures.save('%02d.png' % i)
        print(str(i + 1) + "/" + str(len(stack)) + " files created")
Ejemplo n.º 3
0
def main():

    'reading tif files'
    true_label = tifread(a.true)
    pred_label = tifread(a.predicted)

    'unravel tif files'
    true, pred = unravel(true_label, pred_label)

    'calculation of ari, split and merge errors and all pa'
    splits, merges, ari = matrix(true, pred)
    recall, precision = recall_precision(true, pred)

    'prints'
    print("\nEvaluation results:\n")
    print("Splits                   = %i" % splits)
    print("Merges                   = %i" % merges)
    print("Adjusted Rand Index      = %0.5f" % ari)
    print("Recall                   = %0.5f" % recall)
    print("Precision                = %0.5f\n" % precision)
Ejemplo n.º 4
0
def cytoplasm(input, output):

    stack = tifread(input)
    os.chdir(output)

    for i, slice in enumerate(stack):
        edges_compared = edges(slice)
        cytoplasm_logical = np.logical_and(np.logical_not(edges_compared), slice > 0)
        pictures = Image.fromarray(cytoplasm_logical.astype('uint8') * 255)
        pictures.save('%02d.png' % i)
        print(str(i + 1) + "/" + str(len(stack)) + " files created")
Ejemplo n.º 5
0
def split_snemi3d(input, output, prefix):

    stack = tifread(input)
    os.chdir(output)

    'slicing original image stack'
    stack_split_a = stack[:, 512:, 512:]
    stack_split_b = stack[:, :512, 512:]
    stack_split_c = stack[:, :512, :512]
    stack_split_d = stack[:, 512:, :512]

    'saving all four split image stacks'
    tifsave('%s_a.tif' % prefix, stack_split_a)
    tifsave('%s_b.tif' % prefix, stack_split_b)
    tifsave('%s_c.tif' % prefix, stack_split_c)
    tifsave('%s_d.tif' % prefix, stack_split_d)
Ejemplo n.º 6
0
def consecutive(input, output, size):

    stack = tifread(input)
    os.chdir(output)

    if len(stack.shape) == 4:
        stack = stack[:, :, :, 0]

    stack1 = stack[:-1]
    stack2 = stack[1:]

    for i, (slice1, slice2) in enumerate(zip(stack1, stack2)):
        zero_array = np.zeros((3, int(size), int(size)))
        zero_array[0] = slice1
        zero_array[1] = slice2
        zero_array = np.ascontiguousarray(zero_array.transpose(1, 2, 0))
        consecutive_image = zero_array.astype('uint8')
        pictures = Image.fromarray(consecutive_image, 'RGB')
        pictures.save('%02d.png' % i)
        zero_array[0] = 0
        zero_array[1] = 0
        print(str(i + 1) + "/" + str(len(stack1)) + " files created")
Ejemplo n.º 7
0
def overlap(input, output):

    stack = tifread(input)
    os.chdir(output)
    list_for_slices = []

    for i, slice in enumerate(stack):
        edges_compared = edges(slice)
        list_for_slices.append(np.invert(edges_compared))
        print(str(i + 1) + "/" + str(len(stack)) + " membrane pictures for overlap detection processed")

    membranes = np.asarray(list_for_slices)
    membranes_indices = membranes * stack

    stack1 = membranes_indices[:-1]
    stack2 = membranes_indices[1:]
    compared_stack = np.logical_and(np.logical_and(stack1 == stack2, stack1 > 0), stack2 > 0)

    for i, slice in enumerate(compared_stack):
        overlap_image = slice.astype('uint8') * 255
        pictures = Image.fromarray(overlap_image)
        pictures.save('%02d.png' % i)
        print(str(i + 1) + "/" + str(len(compared_stack)) + " files created")
Ejemplo n.º 8
0
    "to browers running on the local machine, use 0.0.0.0 to permit access from remote browsers.")
parser.add_argument(
    "--static-content-url", help="Obtain the Neuroglancer client code from the specified URL.")
parser.add_argument("--em", required=False, help="path to em tif file")
parser.add_argument("--label", required=False, help="path to original labeled tif file")
parser.add_argument("--predicted", required=False, help="path to predicted tif file")

a = parser.parse_args()

if a.bind_address:
    neuroglancer.set_server_bind_address(a.bind_address)
if a.static_content_url:
    neuroglancer.set_static_content_source(url=a.static_content_url)


em_images = tifread(a.em)
em_array = np.asarray(em_images, dtype="uint8")

label_images = tifread(a.label)
label_array = np.asarray(label_images, dtype="uint16")

predicted_images = tifread(a.predicted)
predicted_array = np.asarray(predicted_images, dtype="uint16")

viewer = neuroglancer.Viewer()
with viewer.txn() as s:
    scaling = [5, 5, 30]
    offset = [0, 0, 0]

    s.layers["EM"] = neuroglancer.ImageLayer(
        source=neuroglancer.LocalVolume(em_array, voxel_size=scaling, voxel_offset=offset),