Example #1
0
def predict(in_path, out_path, win_size=30):
    nuclear_channel_names = ['nuclear']
    trained_network_dir = "/app/DeepCell/trained_networks/Nuclear"
    prefix = "2016-07-12_nuclei_all_61x61_bn_feature_net_61x61_"

    image_list = os.listdir(in_path)
    models_to_use = 5
    list_of_weights = [
        os.path.join(trained_network_dir, prefix + str(i) + ".h5")
        for i in range(models_to_use)
    ]

    for i in range(len(image_list)):
        data_location = os.path.join(in_path, image_list[i])
        nuclear_location = os.path.join(in_path, image_list[i])
        im = skimage.io.imread(
            os.path.join(in_path, image_list[i], "nuclear.png"))
        nuclear_predictions = run_models_on_directory(
            data_location,
            nuclear_channel_names,
            nuclear_location,
            model_fn=nuclear_fn,
            list_of_weights=list_of_weights,
            image_size_x=im.shape[1],
            image_size_y=im.shape[0],
            win_x=win_size,
            win_y=win_size,
            split=False)
Example #2
0
def segment_SLIP_pos(data_direc, mask_direc):
    data_location = data_direc
    phase_location = mask_direc

    phase_channel_names = ['Phase']  #['channel000']

    trained_network_phase_directory = "/home/nquach/DeepCell2/trained_networks/ecoli/ecoli_all/"

    phase_prefix = "2016-07-20_ecoli_all_31x31_bn_feature_net_31x31_"
    #"2017-02-12_ecoli_90x_31x31_ecoli_90x_feature_net_31x31_"

    win_phase = 30

    image_size_x, image_size_y = get_image_sizes(data_location,
                                                 phase_channel_names)
    image_size_x /= 2
    image_size_y /= 2

    list_of_phase_weights = []
    for j in xrange(5):
        phase_weights = os.path.join(trained_network_phase_directory,
                                     phase_prefix + str(j) + ".h5")
        print(phase_weights)
        list_of_phase_weights += [phase_weights]

    phase_predictions = run_models_on_directory(
        data_location,
        phase_channel_names,
        phase_location,
        model_fn=fn,
        list_of_weights=list_of_phase_weights,
        image_size_x=image_size_x,
        image_size_y=image_size_y,
        win_x=win_phase,
        win_y=win_phase,
        std=False,
        split=False)

    #phase_masks = segment_nuclei(phase_predictions, mask_location = mask_location, threshold = 0.75, area_threshold = 100, solidity_threshold = 0.75, eccentricity_threshold = 0.95)
Example #3
0
print list_of_nuclear_weights
"""
Run model on directory
"""

# cytoplasm_predictions = run_models_on_directory(data_location, cyto_channel_names, cyto_location, n_features = 3, model_fn = cyto_fn,
# 	list_of_weights = list_of_cyto_weights, image_size_x = image_size_x, image_size_y = image_size_y,
# 	win_x = win_cyto, win_y = win_cyto, std = False, split = False)

nuclear_predictions = run_models_on_directory(
    data_location,
    nuclear_channel_names,
    nuclear_location,
    model_fn=nuclear_fn,
    list_of_weights=list_of_nuclear_weights,
    image_size_x=image_size_x,
    image_size_y=image_size_y,
    win_x=win_nuclear,
    win_y=win_nuclear,
    std=False,
    split=False)
"""
Refine segmentation with active contours
"""

# nuclear_masks = segment_nuclei(img = None, color_image = True, load_from_direc = nuclear_location, mask_location = mask_location, area_threshold = 100, solidity_threshold = 0, eccentricity_threshold = 1)
# cytoplasm_masks = segment_cytoplasm(img = None, load_from_direc = cyto_location, color_image = True, nuclear_masks = nuclear_masks, mask_location = mask_location, smoothing = 1, num_iters = 120)
"""
Compute validation metrics (optional)
"""
# direc_val = os.path.join(direc_name, 'Validation')
                        data_location = direc_name
                        cyto_location = os.path.join(direc_name, 'Output')
                        image_size_x, image_size_y = get_image_sizes(data_location,cyto_channel_names)
                        #image_size_x /= 4                                                                                                     
                        #image_size_y /= 4                                                                                                     

                        """                                                                                                                    
                        Define model                                                                                                           
                        """

                        list_of_cyto_weights = []
                        for j in xrange(1):
                                cyto_weights = os.path.join(trained_network_cyto_directory,  cyto_prefix + str(j) + ".h5")
                                list_of_cyto_weights += [cyto_weights]


                        """                                                                                                                    
                        Run model on directory                                                                                                 
                        """

                        cytoplasm_predictions = run_models_on_directory(data_location, cyto_channel_names, cyto_location, n_features = 3, mode\
l_fn = cyto_fn,
                                list_of_weights = list_of_cyto_weights, image_size_x = image_size_x, image_size_y = image_size_y,
                                                                        win_x = win_cyto, win_y = win_cyto, std = False, split = True, save = \
True)



print time.clock()-t0

    win = 30

    image_size_x, image_size_y = get_image_sizes(data_location,
                                                 nuclear_channel_names)
    """
	Define model
	"""

    list_of_nuclear_weights = []
    for j in xrange(1):
        nuclear_weights = os.path.join(trained_network_nuclear_directory,
                                       nuclear_prefix + str(0) + ".h5")
        list_of_nuclear_weights += [nuclear_weights]
    """
	Run model on directory
	"""

    nuclear_predictions = run_models_on_directory(
        data_location,
        nuclear_channel_names,
        nuclear_location,
        n_features=3,
        model_fn=nuclear_fn,
        list_of_weights=list_of_nuclear_weights,
        image_size_x=image_size_x,
        image_size_y=image_size_y,
        win_x=win,
        win_y=win,
        std=True,
        split=True)
Example #6
0
list_of_nuclear_weights = []
for j in xrange(5):
    nuclear_weights = os.path.join(trained_network_nuclear_directory,
                                   nuclear_prefix + str(j) + ".h5")
    list_of_nuclear_weights += [nuclear_weights]
"""
Run model on directory
"""

cytoplasm_predictions = run_models_on_directory(
    data_location,
    cyto_channel_names,
    cyto_location,
    n_features=3,
    model_fn=cyto_fn,
    list_of_weights=list_of_cyto_weights,
    image_size_x=image_size_x,
    image_size_y=image_size_y,
    win_x=win_cyto,
    win_y=win_cyto,
    std=False,
    split=False)

# nuclear_predictions = run_models_on_directory(data_location, nuclear_channel_names, nuclear_location, model_fn = nuclear_fn,
# 	list_of_weights = list_of_nuclear_weights, image_size_x = image_size_x, image_size_y = image_size_y,
# 	win_x = win_nuclear, win_y = win_nuclear, std = False, split = False)
"""
Refine segmentation with active contours
"""

# nuclear_masks = segment_nuclei(img = None, color_image = True, load_from_direc = nuclear_location, mask_location = mask_location, area_threshold = 100, solidity_threshold = 0, eccentricity_threshold = 1)