def set_line_area(self, line_image, area_image, steps=20, verbose=False): drawn_binary = np.zeros(self.shape) if os.path.exists(line_image): drawn_binary = read_tiff_stack(line_image)[0]['raw_image'] drawn_binary = make_binary_image_array(drawn_binary) elif verbose: sys.stderr.write( "Skipping the invasive margin since there is none present.\n") image_id1 = uuid4().hex self._images[image_id1] = drawn_binary area_binary = read_tiff_stack(area_image)[0]['raw_image'] area_binary = make_binary_image_array(area_binary) image_id2 = uuid4().hex self._images[image_id2] = area_binary df = pd.DataFrame({ 'custom_label': ['Drawn', 'Area'], 'image_id': [image_id1, image_id2] }) df.index.name = 'db_id' self.set_data('custom_images', df) grown = binary_image_dilation(drawn_binary, steps=steps) processed_image = self.get_image(self.processed_image_id).astype( np.uint8) margin_binary = grown & processed_image tumor_binary = (area_binary & (~grown)) & processed_image stroma_binary = (~( (tumor_binary | grown) & processed_image)) & processed_image d = { 'Margin': margin_binary, 'Tumor': tumor_binary, 'Stroma': stroma_binary } self.set_regions(d) return d
def _read_seg_images(self, memb_seg_image_file, nuc_seg_image_file): segmentation_names = [] memb = make_binary_image_array( read_tiff_stack(memb_seg_image_file)[0]['raw_image']) memb_id = uuid4().hex self._images[memb_id] = memb.astype(int) segmentation_names.append(['Membrane', memb_id]) nuc = read_tiff_stack(nuc_seg_image_file)[0]['raw_image'] nuc_id = uuid4().hex self._images[nuc_id] = nuc.astype(int) segmentation_names.append(['Nucleus', nuc_id]) #_mask_key = pd.DataFrame(mask_names,columns=['mask_label','image_id']) #_mask_key.index.name = 'db_id' #self.set_data('mask_images',_mask_key) _segmentation_key = pd.DataFrame( segmentation_names, columns=['segmentation_label', 'image_id']) _segmentation_key.index.name = 'db_id' self.set_data('segmentation_images', _segmentation_key)
def set_area(self, area_image, custom_mask_name, other_mask_name, verbose=False): area_binary = read_tiff_stack(area_image)[0]['raw_image'] area_binary = make_binary_image_array(area_binary) image_id = uuid4().hex self._images[image_id] = area_binary df = pd.DataFrame({'custom_label': ['Area'], 'image_id': [image_id]}) df.index.name = 'db_id' self.set_data('custom_images', df) processed_image = self.get_image(self.processed_image_id).astype( np.uint8) #margin_binary = grown&processed_image tumor_binary = area_binary & processed_image stroma_binary = (~(tumor_binary & processed_image)) & processed_image d = {custom_mask_name: tumor_binary, other_mask_name: stroma_binary} self.set_regions(d) return d
def _read_seg_image(self, mibi_cell_labels_tif_path, generate_processed_area_image, processed_area_image_steps): # Do our segmentation first cell_labels = read_tiff_stack( mibi_cell_labels_tif_path)[0]['raw_image'] image_id = uuid4().hex self._images[image_id] = cell_labels segmentation_names = [['Membrane', image_id]] _segmentation_key = pd.DataFrame( segmentation_names, columns=['segmentation_label', 'image_id']) _segmentation_key.index.name = 'db_id' self.set_data('segmentation_images', _segmentation_key) # make the cell map to be a copy of the membrane segmentation cell_map_id = uuid4().hex self._images[cell_map_id] = cell_labels.copy() increment = self.get_data('segmentation_images').index.max() + 1 extra = pd.DataFrame( pd.Series( dict({ 'db_id': increment, 'segmentation_label': 'cell_map', 'image_id': cell_map_id }))).T extra = pd.concat( [self.get_data('segmentation_images'), extra.set_index('db_id')]) self.set_data('segmentation_images', extra) # make the edge map incrementally edge_map_id = uuid4().hex self._images[edge_map_id] = image_edges(cell_labels) increment = self.get_data('segmentation_images').index.max() + 1 extra = pd.DataFrame( pd.Series( dict({ 'db_id': increment, 'segmentation_label': 'edge_map', 'image_id': edge_map_id }))).T extra = pd.concat( [self.get_data('segmentation_images'), extra.set_index('db_id')]) self.set_data('segmentation_images', extra) image_id = uuid4().hex mask_names = [['ProcessRegionImage', image_id]] processed = make_binary_image_array(np.ones(cell_labels.shape)) self._images[image_id] = processed if self.verbose: sys.stderr.write("size of image: " + str(processed.sum().sum()) + "\n") if generate_processed_area_image: if self.verbose: sys.stderr.write( "Creating approximate processed_image_area by watershed.\n" ) processed = binary_image_dilation( make_binary_image_array(cell_labels), steps=processed_area_image_steps) self._images[image_id] = processed _mask_key = pd.DataFrame(mask_names, columns=['mask_label', 'image_id']) _mask_key.index.name = 'db_id' self.set_data('mask_images', _mask_key) self.set_processed_image_id(image_id) self._images[self.processed_image_id] = processed.astype(np.int8) if self.verbose: sys.stderr.write("size of processed image: " + str(processed.sum().sum()) + "\n")