Beispiel #1
0
    def active_nuclei(self):
        '''Return binary image with active nuclei'''

        x_max, y_max = self.shape
        nuclei_peaces = []

        for cur_cell in self.active_cells():
            nuclei_peaces.append(peace(cur_cell.nucleus, cur_cell.coords))

        return join_peaces(nuclei_peaces, x_max, y_max)
Beispiel #2
0
    def get_all_pics(self, nuclei_color = 0.66, foci_color = 0.33, seed_circles = False):
        '''Return all calculated pics'''

        if self.number_of_cells() == 0:
            print "No cells found in " + self.dir_path

#            return (None, None, None, None, None)

        rescaled_nuclei_peaces = []
        rescaled_foci_peaces   = []
        seed_peaces            = []
        foci_bin_peaces        = []

        pic_nuclei = self.get_source_pic_nuclei()

        x_max, y_max = self.nuclei.shape

        for cur_cell in self.active_cells():

            coords = cur_cell.coords

            rescaled_nuclei_peaces.append(peace(cur_cell.rescaled_nucleus_pic, coords))
            rescaled_foci_peaces.append(peace(cur_cell.rescaled_foci_pic, coords))
            seed_peaces.append(peace(cur_cell.foci_seeds, coords))
            foci_bin_peaces.append(peace(cur_cell.foci_binary, coords))


        rescaled_nuclei_pic = join_peaces(rescaled_nuclei_peaces, x_max, y_max, dtype = np.uint8)
        rescaled_foci_pic   = join_peaces(rescaled_foci_peaces, x_max, y_max, dtype = np.uint8)
        foci_binary         = join_peaces(foci_bin_peaces, x_max, y_max)

        seeds               = self.get_merged_pic(nuclei_color, foci_color, seeds = True)

        nuclei_colored = self.get_pic_with_nuclei_colored()
        merged = self.get_merged_pic(nuclei_color, foci_color)

        return (rescaled_nuclei_pic, nuclei_colored, rescaled_foci_pic, seeds, merged)
Beispiel #3
0
    def get_merged_pic(self, nuclei_color = 0.66, foci_color = 0.33, seeds = False):
        '''Return merged pic with foci and nuclei'''

        x_max, y_max = self.nuclei.shape

        active_cells = self.active_cells()

        cell_number = len(active_cells)

        if cell_number == 0:

            return np.zeros((x_max, y_max, 3), dtype = np.uint8)

        merged_pic_peaces = []

        nuclei_rgb_koef = hsv2rgb(np.array([nuclei_color, 1., 1.]).reshape((1,1,3))).reshape(3)

        foci_rgb_koef = hsv2rgb(np.array([foci_color, 1., 1.]).reshape((1,1,3))).reshape(3)

        for cur_cell in active_cells:

            if seeds:
                foci = cur_cell.foci_seeds
            else:
                foci = cur_cell.foci_binary

            nucleus_only = cur_cell.nucleus - foci

            pic_foci_enhanced = 255 - np.floor((255 - cur_cell.pic_foci)*0.6)

            pic_foci_enhanced = foci*pic_foci_enhanced

            pic_nucleus_only = cur_cell.pic_nucleus*nucleus_only

            pic_foci_enhanced_3d = np.dstack((pic_foci_enhanced, pic_foci_enhanced, pic_foci_enhanced))

            pic_nucleus_only_3d = np.dstack((pic_nucleus_only, pic_nucleus_only, pic_nucleus_only))

            pic_foci_rgb = pic_foci_enhanced_3d*foci_rgb_koef

            pic_nucleus_only_rgb = pic_nucleus_only_3d*nuclei_rgb_koef

            pic_merged_rgb = np.floor(pic_foci_rgb + pic_nucleus_only_rgb).astype(np.uint8)

            merged_pic_peaces.append(peace(pic_merged_rgb, cur_cell.coords))

        merged_pic = join_peaces_3d(merged_pic_peaces, x_max, y_max, dtype = np.uint8)

        return merged_pic
Beispiel #4
0
    def get_pic_with_nuclei_colored(self):
        '''Return pic with colored nuclei'''

        pic_nuclei = self.get_source_pic_nuclei()

        x_max, y_max = self.shape

        cell_number = len(self.cells)

        if cell_number == 0:

            return np.dstack((pic_nuclei, pic_nuclei, pic_nuclei))

        hue_step = 0.29

        colored_nuclei_peaces = []

        for cur_cell, cur_num in zip(self.cells, range(cell_number)):

            if not cur_cell.is_active: continue

            pic_nucleus = cur_cell.pic_nucleus

            pic_nucleus_3d = np.dstack((pic_nucleus, pic_nucleus, pic_nucleus))

            rgb_koef = hsv2rgb(np.array([hue_step*cur_num, 0.5, 1.]).reshape((1,1,3))).reshape(3)

            colored_nuclei_peaces.append(peace(np.floor(pic_nucleus_3d*rgb_koef).astype(np.uint8),cur_cell.coords))

        pic_bg = pic_nuclei*(self.active_nuclei() == 0)

        pic_bg_3d = np.dstack((pic_bg, pic_bg, pic_bg))

        colored_nuclei_only = join_peaces_3d(colored_nuclei_peaces, x_max, y_max, dtype = np.uint8)

        colored_nuclei = pic_bg_3d + colored_nuclei_only

        return colored_nuclei