class Segmentation():
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/models_local/background_weighting_with_custom_function/Unet_andy_Unet_class_weight_like_cw0_01_20201110-041226.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size

    def segmentation(self, img):
        if len(img.shape) == 3:
            img = img[:, :, 0]
        img = (img - np.mean(img)) / np.std(img).astype(np.float32)
        prob_map = self.unet.predict(img[None, :, :, None])[0, :, :, 0]
        prediction_mask = prob_map > 0.5
        cells = mask_to_cells(prediction_mask, img, self.config, self.r_min,
                              self.frame_data, self.edge_dist)
        return prediction_mask, cells, prob_map
コード例 #2
0
    def __init__(self,
                 network_path=None,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 edge_only=False,
                 return_mask=True,
                 d=8,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=d)
        #network_path ="/home/user/Desktop/2020_Deformation_Cytometer/models_local/weights_andy_transfer_learning1/andyUnet_andy_transfer_long_n200__20201006-155443.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
        self.edge_only = edge_only
        self.return_mask = return_mask
コード例 #3
0
class Segmentation():
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Software/Deformation_Cytometer/deformationcytometer/detection/includes/v0.3/Unet_transfer_immune_cells.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size

    def segmentation(self, img):
        if len(img.shape) == 3:
            img = img[:, :, 0]
        img = (img - np.mean(img)) / np.std(img).astype(np.float32)
        prob_map = self.unet.predict(img[None, :, :, None])[0, :, :, 0]
        prediction_mask = prob_map > 0.5
        cells = mask_to_cells(prediction_mask, img, self.config, self.r_min,
                              self.frame_data, self.edge_dist)
        return prediction_mask, cells, prob_map
コード例 #4
0
class Segmentation():
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Downloads/andyUnet_andy_bens_network_long_n300_20201027-082115_checkpoint.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size

    def segmentation(self, img):
        if len(img.shape) == 3:
            img = img[:, :, 0]
        img = (img - np.mean(img)) / np.std(img).astype(np.float32)
        prob_map = self.unet.predict(img[None, :, :, None])[0, :, :, 0]
        prediction_mask = prob_map > 0.5
        cells = mask_to_cells(prediction_mask, img, self.config, self.r_min,
                              self.frame_data, self.edge_dist)
        return prediction_mask, cells, prob_map
コード例 #5
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/andreas/Software/Deformation_Cytometer/deformationcytometer/detection/includes/v0.4/Unet_edge_only_immune.h5"
        #/home/user/Desktop/2020_Deformation_Cytometer/local_training/Unet_continued2_edge_only_n200_20201124-013322.h5
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #6
0
    def __init__(self, img_shape=None, pixel_size=None, r_min=None, frame_data=None, edge_dist=15, channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1), 1, d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/models_local/Unet_0-0-5_fl_RAdam_20200610-141144.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #7
0
    def __init__(self, img_shape=None, pixel_size=None, r_min=None, frame_data=None, edge_dist=15, channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1), 1, d=8)
        network_path ="/home/user/Downloads/Unet_andy_Unet_2_everywhere_filters_n200_20201102-155546.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
    def __init__(self, img_shape=None, pixel_size=None, r_min=None, frame_data=None, edge_dist=15, channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1), 1, d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/models_local/background_weighting_with_custom_function/Unet_andy_Unet_class_weight_like_cw0_3_20201109-215523.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #9
0
class Segmentation():
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/local_training/Unet_test_reproducability_1_20201203-104240.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size

    def segmentation(self, img):
        if len(img.shape) == 3:
            img = img[:, :, 0]
        img = (img - np.mean(img)) / np.std(img).astype(np.float32)
        prob_map = self.unet.predict(img[None, :, :, None])[0, :, :, 0]
        prediction_mask = prob_map > 0.5
        cells, prediction_mask = mask_to_cells_edge(prediction_mask,
                                                    img,
                                                    self.config,
                                                    self.r_min,
                                                    self.frame_data,
                                                    self.edge_dist,
                                                    return_mask=True)
        return prediction_mask, cells, prob_map
コード例 #10
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/models_local/weights_fixed_filters/andyUnet_andy_fixed_gauss_laplace_n200__20201023-132945.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #11
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Downloads/andyUnet_andy_bens_network_long_n300_20201027-082115_checkpoint.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #12
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/models_local/weights_andy_spatial/andyUnet_andy_binary_focal_ref_n1504_custom_acc__20201024-222444.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #13
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Desktop/2020_Deformation_Cytometer/local_training/Unet_test_reproducability_1_20201203-104240.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #14
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Downloads/Unet_transfer_immune_cells_n1504_20201117-205645.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #15
0
    def __init__(self,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=8)
        network_path = "/home/user/Software/Deformation_Cytometer/deformationcytometer/detection/includes/v0.3/Unet_transfer_immune_cells.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
コード例 #16
0
class Segmentation():
    def __init__(self,
                 network_path=None,
                 img_shape=None,
                 pixel_size=None,
                 r_min=None,
                 frame_data=None,
                 edge_dist=15,
                 channel_width=0,
                 edge_only=False,
                 return_mask=True,
                 d=8,
                 **kwargs):
        # rmin in µm
        # channel_width in pixel ?
        # pixel_size in m / not in mµ!!
        self.unet = UNet().create_model((img_shape[0], img_shape[1], 1),
                                        1,
                                        d=d)
        #network_path ="/home/user/Desktop/2020_Deformation_Cytometer/models_local/weights_andy_transfer_learning1/andyUnet_andy_transfer_long_n200__20201006-155443.h5"
        self.unet.load_weights(network_path)

        self.pixel_size = pixel_size
        self.r_min = r_min
        self.frame_data = frame_data if frame_data is not frame_data else {}
        self.edge_dist = edge_dist
        self.config = {}
        self.config["channel_width_px"] = channel_width
        self.config["pixel_size_m"] = pixel_size
        self.edge_only = edge_only
        self.return_mask = return_mask

    def search_cells(self, prediction_mask, img):

        if self.edge_only:
            if self.return_mask:
                cells, prediction_mask = mask_to_cells_edge(
                    prediction_mask,
                    img,
                    self.config,
                    self.r_min,
                    self.frame_data,
                    self.edge_dist,
                    return_mask=self.return_mask)
            else:
                cells = mask_to_cells_edge(prediction_mask,
                                           img,
                                           self.config,
                                           self.r_min,
                                           self.frame_data,
                                           self.edge_dist,
                                           return_mask=self.return_mask)
        else:
            cells = mask_to_cells(prediction_mask, img, self.config,
                                  self.r_min, self.frame_data, self.edge_dist)

        return prediction_mask, cells

    def segmentation(self, img):
        # image batch
        if len(img.shape) == 4:
            img = preprocess_batch(img)
            prediction_mask = self.unet.predict(img) > 0.5
            cells = []
            for i in range(prediction_mask.shape[0]):
                _, cells_ = self.search_cells(prediction_mask[i, :, :, 0],
                                              img[i, :, :, 0])
                cells.extend(cells_)
            prediction_mask = None
        # single image
        elif len(img.shape) == 2:

            img = (img - np.mean(img)) / np.std(img).astype(np.float32)
            prediction_mask = self.unet.predict(img[None, :, :, None])[0, :, :,
                                                                       0] > 0.5
            prediction_mask, cells = self.search_cells(prediction_mask, img)
        else:
            raise Exception("incorrect image shape: img.shape == " +
                            str(img.shape))
        return prediction_mask, cells