neighbour_nIDs.remove(nID) # add nuclei to stack stack_tmp_self = seg.nuclei.add_nucleus_to_stack(nID, stack_tmp_self, nucleus_value=1) for neighbour_nID in neighbour_nIDs: seg.nuclei.set_nucleus_colour(neighbour_nID, neighbour_nID) stack_tmp_others = seg.nuclei.add_nuclei_to_stack(stack_tmp_others, nIDs=neighbour_nIDs) # dilate and combine stack_tmp_contact = np.logical_and( ImageProcessing.apply_filters(processing_steps, stack_tmp_self), ImageProcessing.apply_filters(processing_steps, stack_tmp_others)) neighbours_stack = (stack_tmp_others * stack_tmp_contact) neighbours = set(neighbours_stack.ravel().tolist()) if len(neighbours) > 0: neighbours.remove(0) #print('NEIGHBOURS', neighbours) # get contact surface contact_surface = np.sum(stack_tmp_contact) nucleus_surface = seg.nuclei.get_nucleus_surface(nID) compactness = contact_surface / nucleus_surface
['FILL'], ['OPN', 'bin', 2], # checked ['CONV_BIT', 16, '3D'], ['LABEL', 1, 'no3D'] ] check_params = True results_titles = list() results_titles.append('Original') pouch_volumes = list() if check_params is True: for i in range(0, 51, 10): processing_steps[1][2] = i pouch_volumes.append(ImageProcessing.apply_filters(processing_steps, pouch_stack, verbose=True)) results_titles.append('THR %i' % i) else: pouch_volumes.append(ImageProcessing.apply_filters(processing_steps, pouch_stack, verbose=True)) results_titles.append('Processed') # go through labels and filter small ones pouch_volume_filtered = np.zeros_like(pouch_volumes[0]) union_pouch_volume = np.zeros_like(pouch_volumes[0]) dilate_step = [ ['DIL', 'bin', 50] ] for z in range(0, pouch_volumes[0].shape[0]): print('get props for z: %i' % z)
'xtick.labelsize': cfg.fontsdict_plot['fontsize'], 'ytick.labelsize': cfg.fontsdict_plot['fontsize']} plt.rcParams.update(params) # open window to select nuclei criteria infos = ImageHandler.load_image_infos() # select a specific info selected_info_IDs = ['N1-19-24'] for info in infos: if info['ID'] in selected_info_IDs: seg = Segmentation(info) seg.load() processing_steps = [ ['EQU'], ['THR', 'OTSU', 100, 'no3D'], ['CLS', 'bin', 2], ['FILL'], ['OPN', 'bin', 2], ['CONV_BIT', 16, '3D'] ] # apply processing steps seg.stacks.membin = ImageProcessing.apply_filters( processing_steps, seg.stacks.membrane, verbose=cfg.general_verbose) ImageHandler.save_stack_as_tiff(seg.stacks.membin, seg.get_results_dir().tmp + cfg.file_stack_membin)
['CONV_BIT', 16, '3D'], ['LABEL', 1, 'no3D'] ] check_params = True results_titles = list() results_titles.append('Original') pouch_volumes = list() if check_params is True: for i in range(0, 51, 10): processing_steps[1][2] = i pouch_volumes.append( ImageProcessing.apply_filters(processing_steps, pouch_stack, verbose=True)) results_titles.append('THR %i' % i) else: pouch_volumes.append( ImageProcessing.apply_filters(processing_steps, pouch_stack, verbose=True)) results_titles.append('Processed') # show images stack_fig = plt.figure(figsize=(20, 10)) # view the stack and the processing results results = list()
def apply_image_process_steps(self): """ Go through the select image processing steps and apply and show results :return: """ # update processing steps self.update_image_process_steps() # update range self.update_image_range() # rebuild filtered stack self.stacks.filtered = list() # reset figures and canvas self.fig_processing_steps = list() self.cnv_processing_steps = list() # get through filters and apply for step, filter in enumerate(self.processing_steps): if len(self.stacks.filtered) > 0: image = self.stacks.filtered[-1][0] else: image = self.stacks.lamin # get zoom box for image image = Plot.get_zoom_box(image.copy(), self.image_zoom) # build up filter list filters = list() titles = list() # is the current filter parameter a range? for param_id, param in enumerate(filter[1:]): if isinstance(param, range): for param_value in param: filter_range = filter.copy() filter_range[param_id + 1] = param_value filters.append(filter_range.copy()) titles.append('%s %i' % (filter[0], param_value)) if len(filters) == 0: filters.append(filter) titles.append(filter[0]) # apply filters filtered_images = list() colour_map = list() for x in filters: filtered_images.append(ImageProcessing.apply_filters([x], image)) colour_map.append('hot') self.stacks.filtered.append(filtered_images) # prepare figure and canvas self.fig_processing_steps.append(plt.figure( figsize=(len(filtered_images) * cfg.image_processing_image_size, len(list(self.image_range)) * cfg.image_processing_image_size) )) self.cnv_processing_steps.append(FigureCanvas(self.fig_processing_steps[-1])) self.ctn_image_process_results.addWidget(self.cnv_processing_steps[-1], 2, step) # adjust width of column and stretch self.ctn_image_process_results.setColumnMinimumWidth(step, len(filtered_images) * cfg.image_processing_image_size * 150) self.ctn_image_process_results.setColumnStretch(step, 0) # update canvas Plot.show_stacks(self.fig_processing_steps[step], filtered_images, self.image_range, titles, colour_map, 1) self.cnv_processing_steps[step].draw() self.ctn_image_process_results.setColumnStretch(len(self.processing_steps), 1)
def __init__(self, image_info, silent_processing=False, parent=None): super(NucleoProcess, self).__init__(parent) # load image infos self.image_info = image_info # load image image_stack = ImageHandler.load_image(image_info) # focus on lamin signal self.stacks = Stack() self.stacks.lamin = image_stack[ImageHandler.CHN_LAMIN] # init processing steps self.processing_steps = list() self.reset_processing_steps() # build filtered list self.stacks.filtered = list() # apply filters self.stacks.filtered.append( [ImageProcessing.apply_filters(self.processing_steps, self.stacks.lamin)]) # edit boxes for range self.edt_image_range_start = QtGui.QLineEdit() self.edt_image_range_stop = QtGui.QLineEdit() self.edt_image_range_int = QtGui.QLineEdit() self.edt_image_zoom = QtGui.QLineEdit() # calculate educated guesses for range take the middle range_start = round(self.stacks.lamin.shape[0]/2) - cfg.image_processing_default_range_offset range_stop = round(self.stacks.lamin.shape[0]/2) + cfg.image_processing_default_range_offset if range_start < 0: range_start = 0 if range_stop > self.stacks.lamin.shape[0]: range_stop = self.stacks.lamin.shape[0] self.image_range = range(range_start, range_stop, cfg.image_processing_default_range_int) self.image_int = cfg.image_processing_default_range_int self.image_zoom = cfg.image_processing_default_zoom # set layout for processing results self.ctn_image_process_results = QtGui.QGridLayout() # set combolist for filtering methods and the methods chosen self.sel_image_process_steps = list() self.filter_mapping = ImageProcessing.get_filter_mapping() # buttons to submit processing steps self.btn_image_process_reset = QtGui.QPushButton(gui_labels.btn_reset) self.btn_image_process_load = QtGui.QPushButton(gui_labels.btn_load) self.btn_image_process_save = QtGui.QPushButton(gui_labels.btn_save) self.btn_image_process = QtGui.QPushButton(gui_labels.btn_process) self.btn_close = QtGui.QPushButton(gui_labels.btn_close) # set main layout self.setLayout(self.prep_ctn_image_process()) # silent processing if silent_processing is True: # load processing steps self.load_image_process_steps(False) # process image self.process_image() else: # load settings and apply self.load_image_process_steps()