コード例 #1
0
ファイル: nuc_process.py プロジェクト: baemms/NucleoSegment
    def save_image_process_steps(self):
        """
        Save configures processing steps to csv

        :return:
        """
        # prepare processing steps for writing to file
        proc_steps = list()

        # add id to the start
        proc_steps.append(self.image_info['ID'])

        for step in self.processing_steps[1:]:
            # filter name
            proc_steps.append(step[0])

            # filter params
            if len(step) > 1:
                proc_steps[-1] += '='

                # add parameters
                for id, param in enumerate(step[1:]):
                    if id > 0:
                        proc_steps[-1] += ','

                    # is param a range? then convert
                    if isinstance(param, range):
                        param = ImageProcessing.get_param_from_range(param)

                    proc_steps[-1] += str(param)

        # write to processing file
        ImageHandler.update_exp_csv(self.image_info['ID'],
                                    cfg.file_processing,
                                    proc_steps)
コード例 #2
0
    def get_filters(image):
        """
        Retrieve filters for image from configuration

        :param image:
        :return:
        """
        # processing steps for image
        processing_steps = list()

        with open(cfg.file_processing, 'r') as csvfile:
            image_reader = csv.reader(csvfile,
                                      delimiter=cfg.CSV_DEL,
                                      quotechar=cfg.CSV_QUOT)
            # find filters for image
            for row in image_reader:
                if row[0] == ImageHandler.extract_expnum_from_ID(image['ID']):
                    for filter in range(1, len(row)):
                        # get filter and parameters
                        split_filter = row[filter].split(cfg.PROC_PARAMS)
                        # build the filter and parameter list
                        steps = list()
                        steps.append(split_filter[0])

                        # Does the filter have parameters?
                        if len(split_filter) > 1:
                            # split parameters
                            split_params = split_filter[1].split(
                                cfg.PROC_PARAMS_DEL)

                            for param in split_params:
                                # is parameter a digit?
                                if param.isdigit():
                                    param = int(param)

                                steps.append(param)

                        processing_steps.append(steps)

                    break

            csvfile.close()

        return processing_steps
コード例 #3
0
ファイル: classifier.py プロジェクト: baemms/NucleoSegment
    def train_with_exts(self):
        """
        Use extensions of experiment to train the classifier

        :return:
        """
        # get extensions from experiment
        self.ext_infos = ImageHandler.get_ext_infos_by_expnum(self.segmentation.image_info['ID'])

        # create train and target vectors
        self.train_data, self.target_data = self.create_train_target_from_ext_infos()

        # create unkown vector for image
        self.unknown_data, self.unknown_map = self.create_unknown()

        # train classifier and get probabilities
        self.nuclei_probas = self.train_and_predict()

        # add probability to nuclei
        self.add_nuclei_probas_to_params()
コード例 #4
0
    def view_images(img_list,
                    are_objects=False,
                    cmap='gray',
                    display=True,
                    save=False):
        """
        View individual images

        :param are_objects:
        :param cmap:
        :param display:
        :param save:
        :return:
        """
        if save:
            # create temporary directory to save the images
            tmp_dir = ImageHandler.create_tmp_dir()

        if display:
            # create a plot to show images
            fig, axes = plt.subplots(ncols=len(img_list),
                                     figsize=(2 * len(img_list), 2),
                                     sharex=True,
                                     sharey=True)

        for i, img in enumerate(img_list):
            if save:
                # save images in temporary directory
                plt.imsave((tmp_dir + '/Image-%i') % i, img, cmap=cmap)

            if display:
                # displat the objects
                if are_objects:
                    axes[i].imshow(img['img'], cmap='Spectral')
                    axes[i].set_title('Obj: %i' % img['label'])
                else:
                    axes[i].imshow(img, cmap=cmap)
                    axes[i].set_title('Image: %i' % i)

                axes[i].axis('off')
                axes[i].set_adjustable('box-forced')
コード例 #5
0
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt
params = {
    'axes.titlesize': cfg.fontsdict_plot['fontsize'],
    'xtick.labelsize': cfg.fontsdict_plot['fontsize'],
    'ytick.labelsize': cfg.fontsdict_plot['fontsize']
}

plt.rcParams.update(params)
selected_info_IDs = ['N1-19-9', 'N1-19-22', 'N1-19-23', 'N1-19-24']
#selected_info_IDs = ['N1-19-9', 'N1-19-23']

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

# processing steps
processing_steps = [['DIL', 'y', 2], ['CONV_BIT', 16]]

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)

for info in infos:
    seg = Segmentation(info)
    seg.load()

    img_path = seg.get_results_dir().tmp + 'contact_surface.tif'
コード例 #6
0
# show the editor to choose images
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt
params = {'axes.titlesize': cfg.fontsdict_plot['fontsize'],
          'xtick.labelsize': cfg.fontsdict_plot['fontsize'],
          'ytick.labelsize': cfg.fontsdict_plot['fontsize']}

plt.rcParams.update(params)
#selected_info_IDs = ['N1-19-9', 'N1-19-22', 'N1-19-23', 'N1-19-24']
selected_info_IDs = ['N1-19-23']

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

# processing steps
processing_steps = [['DIL', 'y', 2],
                    ['CONV_BIT', 16]]

# calculate compactness?
calc_compactness = False

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)

for info in infos:
コード例 #7
0
# update fonts
import matplotlib.pylab as plt
params = {
    'axes.titlesize': cfg.fontsdict_plot['fontsize'],
    'xtick.labelsize': cfg.fontsdict_plot['fontsize'],
    'ytick.labelsize': cfg.fontsdict_plot['fontsize']
}

plt.rcParams.update(params)

# select a specific info
selected_info_IDs = ['N1-19-9']

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)

for info in infos:
    seg = Segmentation(info)
    seg.load()

    # go through nuclei and add them to a stack with
    # nuclei_in_direction as value
    nIDs = seg.nuclei.get_nIDs(only_accepted=True)
コード例 #8
0
            if opt == '-s':
                processing['start'] = 1
            elif opt == '-p':
                processing['process'] = int(arg)
            elif opt == '-m':
                processing['merge'] = int(arg)
            elif opt == '-n':
                processing['nuclei'] = int(arg)
            elif opt == '-c':
                processing['select'] = int(arg)
    else:
        selected_info_ID = None
        processing['start'] = 1

    # load infos
    infos = ImageHandler.load_image_infos()
    selected_info = None

    for info in infos:
        if info['ID'] == selected_info_ID:
            selected_info = info

    # start
    if processing['start'] == 1:
        exp_id = None
        if selected_info_ID is not None:
            exp_id = selected_info_ID

        test_window = NucleoSegment(exp_id=exp_id)
        test_window.show()
        test_window.raise_()
コード例 #9
0
# show the editor to choose images
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt
params = {'axes.titlesize': cfg.fontsdict_plot['fontsize'],
          'xtick.labelsize': cfg.fontsdict_plot['fontsize'],
          'ytick.labelsize': cfg.fontsdict_plot['fontsize']}

plt.rcParams.update(params)
selected_info_IDs = ['N1-19-9', 'N1-19-22', 'N1-19-23', 'N1-19-24']
#selected_info_IDs = ['N1-19-9']

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)

for info in infos:
    seg = Segmentation(info)
    seg.load()

    print('LOAD', info['ID'])

    # go through nuclei and add to stack
    nIDs = seg.nuclei.get_nIDs(only_accepted=True)
コード例 #10
0
    def show_nucleus_box(fig,
                         nucleus_boxes,
                         nucleus_centroids,
                         nucleus_areas,
                         stacks,
                         reload=False):
        """
        Show a nucleus in a box

        :param fig:
        :param nID:
        :param nucleus_boxes:
        :param stacks:
        :return:
        """
        stack_boxes = Plot.get_nucleus_boxes(nucleus_boxes,
                                             nucleus_centroids,
                                             nucleus_areas,
                                             stacks,
                                             reload=reload)

        # calculate overlays
        overlay_xy = nucleus_boxes['crop_rgb'][
            round(nucleus_boxes['crop_rgb'].shape[0] / 2), :, :].copy()
        overlay_zx = nucleus_boxes['crop_rgb'][:,
                                               round(nucleus_boxes['crop_rgb'].
                                                     shape[1] / 2), :].copy()
        overlay_zy = ImageHandler.transform_rgb_img(
            nucleus_boxes['crop_rgb']
            [:, :, round(nucleus_boxes['crop_rgb'].shape[2] / 2)].copy())

        # xy image
        ax_xy = fig.add_subplot(111)
        ax_xy.imshow(stack_boxes.lamin[round(stack_boxes.lamin.shape[0] / 2)],
                     cmap='gray')
        ax_xy.imshow(overlay_xy,
                     cmap=cfg.nucleus_select_corr_nuclei_overlay_colour,
                     alpha=cfg.nucleus_select_corr_nuclei_overlay_alpha)
        divider = make_axes_locatable(ax_xy)

        axes_size = 2.5

        # zx projection
        ax_zx = divider.append_axes("bottom", axes_size, pad=0.2, sharex=ax_xy)
        ax_zx.imshow(stack_boxes.lamin[:,
                                       round(stack_boxes.lamin.shape[1] /
                                             2), :],
                     cmap='gray')
        ax_zx.imshow(overlay_zx,
                     cmap=cfg.nucleus_select_corr_nuclei_overlay_colour,
                     alpha=cfg.nucleus_select_corr_nuclei_overlay_alpha)
        ax_zx.set_ylim([stack_boxes.lamin.shape[0], 0])

        # zy projection
        ax_zy = divider.append_axes("right", axes_size, pad=0.2, sharey=ax_xy)
        ax_zy.imshow(stack_boxes.lamin[:, :,
                                       round(stack_boxes.lamin.shape[2] /
                                             2)].T,
                     cmap='gray')
        ax_zy.imshow(overlay_zy,
                     cmap=cfg.nucleus_select_corr_nuclei_overlay_colour,
                     alpha=cfg.nucleus_select_corr_nuclei_overlay_alpha)
        ax_zy.set_xlim([0, stack_boxes.lamin.shape[0]])

        return stack_boxes
コード例 #11
0
ファイル: membin.py プロジェクト: baemms/NucleoSegment
import storage.config as cfg

# show the editor to choose images
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt
params = {'axes.titlesize': cfg.fontsdict_plot['fontsize'],
          '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],
コード例 #12
0
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()

results.append(pouch_stack)

for pouch_volume in pouch_volumes:
    results.append(pouch_volume)

cmap = list()
for i in range(0, len(results)):
    cmap.append('hot')

Plot.show_stacks(stack_fig,
                 results,
                 range(0, 4, 1),
                 img_title=results_titles,
                 colour_map=cmap)

ImageHandler.save_stack_as_tiff(pouch_volumes[0],
                                work_dir + 'pouch_volume.tif')
コード例 #13
0
ファイル: nuc_process.py プロジェクト: baemms/NucleoSegment
    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()
コード例 #14
0
ファイル: heatmaps.py プロジェクト: baemms/NucleoSegment
# show the editor to choose images
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt

params = {
    'axes.titlesize': cfg.fontsdict_plot['fontsize'],
    '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-9', 'N1-19-23']
selected_infos = dict()
segs = dict()

# maps
density_map = dict()
volume_map = dict()

# lists
density_list = dict()
volume_list = dict()

min_den = -1
コード例 #15
0
        results_titles.append('Union')

        # add union to filtered
        pouch_volume_final = pouch_volume_filtered + union_pouch_volume
        pouch_volume_final[pouch_volume_final > 1] = 1

        #for i in range(20, 41, 5):
        #        final_steps[0][2] = i
        #        pouch_volumes.append(ImageProcessing.apply_filters(final_steps, pouch_volume_final, verbose=True))
        #        results_titles.append('CLS %i' % i)

        pouch_volume_final = ImageProcessing.apply_filters(final_steps, pouch_volume_final, verbose=True)

        results.append(pouch_volume_final)
        results_titles.append('Volume #%i' % i)

    if save_as_stack is True:
        ImageHandler.save_stack_as_tiff(pouch_volume_final, work_dir + ('%s_pv.tif' % pouch_files[i]))

    if show_stack is True:
        # show images
        stack_fig = plt.figure(figsize=(20, 10))

        # view the stack and the processing results

        cmap = list()
        for i in range(0, len(results)):
            cmap.append('hot')

        Plot.show_stacks(stack_fig, results, show_range, img_title=results_titles, colour_map=cmap)
コード例 #16
0
ファイル: heatmaps_rev2.py プロジェクト: baemms/NucleoSegment
for layer_param in layers_to_get:
    for layer_id in range(1, layers_to_get_count + 1):
        params_to_get.append('layer_' + layer_param + '_' + str(layer_id))

limit_nvals = 5
save_csv = True
plot_figures = True
only_centre = True

# window tiling for averaging data
tiling_dim = 50
tiling_count = 5
tiling_offset = int(tiling_dim / tiling_count)

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)
        print('TEST APPEND', info)

img_maps = dict()
val_maps = dict()
tiling_count_map = dict()
tiling_maps = dict()
limits = dict()
limit_lists = dict()
コード例 #17
0
ファイル: volume_stacks.py プロジェクト: baemms/NucleoSegment
app = QtGui.QApplication(sys.argv)

# update fonts
import matplotlib.pylab as plt
params = {
    'axes.titlesize': cfg.fontsdict_plot['fontsize'],
    'xtick.labelsize': cfg.fontsdict_plot['fontsize'],
    'ytick.labelsize': cfg.fontsdict_plot['fontsize']
}

plt.rcParams.update(params)
selected_info_IDs = ['N1-19-9', 'N1-19-22', 'N1-19-23', 'N1-19-24']
#selected_info_IDs = ['N1-19-9']

# open window to select nuclei criteria
loaded_infos = ImageHandler.load_image_infos()
infos = list()

for info in loaded_infos:
    info_ID = info['ID']
    if info_ID in selected_info_IDs:
        infos.append(info)

for info in infos:
    seg = Segmentation(info)
    seg.load()

    print('LOAD', info['ID'])

    # go through nuclei and add to stack
    nIDs = seg.nuclei.get_nIDs(only_accepted=True)