Exemplo n.º 1
0
def main_saveandclose(event):
    global segmentation, main_last_action, inspect_last_action
    global metastasis, OoI, patch, volume, volume_vis, max_mID, DIMmetastases, metastases, removed_metastases, main_n_added
    segmentation['evaluation']['last_inspection'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M") 
    segmentation['evaluation']['last_editor'] = NameOfAnnotator 
    segmentation['metastases'] = metastases
    segmentation['dim_metastases'] = DIMmetastases
    segmentation['removed_metastases'] = removed_metastases
    segmentation['max_mID'] = max_mID
    if(segmentation['evaluation']['completed']):
        try:
            segs_outstanding.pop(segs_outstanding.index(segmentation['patch_id']))
        except:
            pass # this will happen if we overwrite an previously completed patch
        segs_completed.append(segmentation['patch_id'])
    filehandling.psave(path_segs + 'segmentation_patch_' + str(patch['id']),segmentation)
    update_sigcap(signalcap_default)
    metastasis = None
    OoI = None
    patch = None
    segmentation = None
    volume = None
    volume_vis = None
    max_mID = None
    metastases = None
    DIMmetastases = None
    removed_metastases = None
    main_n_added = None
    main_last_action = ''
    inspect_last_action = ''
    inspect_update_plot()
    inspect_update_title()
    main_update_plot()
    main_update_title()
    print('Saved all changes to segmentation file.')
Exemplo n.º 2
0
def save_to_file(event):
    filename = 'reviewed_via_GUI_by_' + NAME_OF_ANNOTATOR.replace(
        ' ', '_') + '_on_the_' + DATE_OF_TODAY + '.pickledump'
    filepath_with_filename = DATAPATH + '/mice_metadata/' + mouse + '/' + filename
    filehandling.psave(filepath_with_filename, TP_candidates)
    print()
    print('----------------------------------------------------')
    print('All decisions saved to file ', filepath_with_filename)
    print('----------------------------------------------------')
Exemplo n.º 3
0
##!!!!!!! Adjust whether you only want to cut patches from CoreOfBody <------
TumorRegion = filehandling.pload(path_region + 'region')
remaining_patches = []
for p, patch in enumerate(region['patches']):
    if (TumorRegion['patches'][p]['locationgroup'] == 'Core'
            or TumorRegion['patches'][p]['locationgroup']
            == 'Boundary'):  # <-- ADJUST AS NECESSARY!
        if (os.path.isfile(localfolder + 'patchvolume_' + str(patch['id']) +
                           '.nii') == False and file_format == 'Nifti'):
            remaining_patches.append(patch)
        elif (os.path.isfile(localfolder + 'patchvolume_' + str(patch['id']) +
                             '.tif') == False and file_format == 'TIFF'):
            remaining_patches.append(patch)

filehandling.psave(
    syncfolder + 'region',
    region)  # saving initial region file (will be updated later on)
print('Patches initialized, now segmenting volume')

#%% Function definition


def save_patch(patch):
    bb = patch['boundingbox']
    patch['volume'] = np.zeros((bb[0], bb[1], bb[2]), 'uint' + str(bitdepth))
    flist = sorted(os.listdir(sourcefolder + region['dataset']['channelname']))
    print('Patch ' + str(patch['id']) + ' was taken by ' +
          multiprocessing.current_process().name)
    for z in range(0, bb[2]):
        file = flist[patch['offset'][2] + z]
        image = cv2.imread(sourcefolder + region['dataset']['channelname'] +
segmentation_ambig_mets['dataset'] = whole_scan_metadata['dataset']
segmentation_ambig_mets['ambiguous_metastases'] = []
global_id = len(mets_of_all_patches)  # = 488
for patch in whole_scan_metadata['patches']:
    patch_seg = p_leo.load_segmentation('F15', patch['id'], load_partial=False)
    if (len(patch_seg['ambiguous_metastases']) > 0):
        print("Adding ambig_mets of patch #" + str(patch['id']))
        localpointlist = []
        for ambig_metastasis in patch_seg['ambiguous_metastases']:
            ambig_metastasis['global_id'] = global_id
            ambig_metastasis['patch_id'] = patch['id']
            segmentation_ambig_mets['ambiguous_metastases'].append(
                ambig_metastasis)
            global_id += 1

filehandling.psave(DATAPATH + 'segmentation_ambig_mets',
                   segmentation_ambig_mets)
print('Segmentations_ambig_mets merged & saved.')

#%% Step 2) For each metastasis, add all relevant meta information

for m, ambig_metastasis in enumerate(
        segmentation_ambig_mets['ambiguous_metastases']
):  # double loop as this will be needed for upcoming computations
    print('Adding information for ambig_metastasis #' +
          str(ambig_metastasis['global_id']))
    # add global location information to metastasis
    segmentation_ambig_mets['ambiguous_metastases'][m]['location'] = {}
    p_offset = np.asarray(
        whole_scan_metadata['patches'][ambig_metastasis['patch_id']]['offset'])
    segmentation_ambig_mets['ambiguous_metastases'][m]['location'][
        'offset'] = (p_offset + ambig_metastasis['offset']).tolist()
Exemplo n.º 5
0
main_w_UC = Button(main_wa_UC, "I'm not sure\nwhat this is")
main_w_UC.label.set_fontsize(buttontext_size)
main_w_UC.on_clicked(mark_as_UC)

# button: save all
main_wp_SA = [0.03 + 0.65, 0.9, 0.10, 0.08]
main_wa_SA = plt.axes(main_wp_SA)
main_w_SA = Button(main_wa_SA, 'Save all\ndecisions')
main_w_SA.label.set_fontsize(buttontext_size)
main_w_SA.on_clicked(save_to_file)

next_candidate()
plt.show(block=True)

#%%
'''
TP_candidates = TP_candidates[:-1]
filename = 'reviewed_via_GUI_by_' + NAME_OF_ANNOTATOR.replace(' ', '_') + '_on_the_' + DATE_OF_TODAY + '.pickledump'
filepath_with_filename = DATAPATH + '/mice_metadata/' + mouse + '/' + filename
filehandling.psave(filepath_with_filename, TP_candidates)
print()
print('----------------------------------------------------')
print('All decisions saved to file ', filepath_with_filename)
print('----------------------------------------------------')

DECISIONS = TP_candidates
number_of_TP_decisions  = len(dataconversions.filter_dicts(DECISIONS,'evaluation-reviewed_via_GUI','true positive'))
number_of_FP_decisions  = len(dataconversions.filter_dicts(DECISIONS,'evaluation-reviewed_via_GUI','false positive'))
number_of_UC_decisions  = len(dataconversions.filter_dicts(DECISIONS,'evaluation-reviewed_via_GUI','unclear'))
number_of_filenotfounds = len(dataconversions.filter_dicts(DECISIONS,'evaluation-reviewed_via_GUI','could not load image files'))
print('Number of true positive decisions: ', number_of_TP_decisions)
                                   '/reviewed_via_GUI.pickledump')
    for decision in decisions:
        SAMPLECARD = {}
        SAMPLECARD['sample_id'] = global_count
        SAMPLECARD['mouse'] = mouse
        SAMPLECARD['patch_id'] = decision['patch_id']
        SAMPLECARD['met_id'] = decision['id']
        try:
            SAMPLECARD['label'] = decision['evaluation']['reviewed_via_GUI']
            if not (SAMPLECARD['label'] == 'true positive'
                    or SAMPLECARD['label'] == 'false positive'):
                raise Exception(
                    'Should not be added to list because it is neither TP nor FP'
                )
        except:
            continue
        LIST_OF_SAMPLECARDS.append(SAMPLECARD)
        global_count += 1

        if SAMPLECARD['label'] == 'true positive':
            TP_count += 1
        elif SAMPLECARD['label'] == 'false positive':
            FP_count += 1
        elif SAMPLECARD['label'] == 'unclear':
            unclear_count += 1
        else:
            no_file_count += 1

filehandling.psave(
    DATAPATH + '/mice_metadata/' + 'list_of_samplecards.pickledump',
    LIST_OF_SAMPLECARDS)
Exemplo n.º 7
0
    if(len(patch_seg['metastases']) > 0):
        print("Adding metastases of patch #" + str(patch['id']))
        localpointlist = []
        for metastasis in patch_seg['metastases']:
            metastasis['global_id'] = global_id
            metastasis['patch_id'] = patch['id']
            segmentation['metastases'].append(metastasis)
            localpointlist += metastasis['points']
            global_id += 1
        localvolume, offset, bb = dataconversions.points2volume(localpointlist, offset=[0,0,0], bb=region['partitioning']['patch_size'])
        offset = patch['offset'] - region['partitioning']['cropping_offset']
        canvas[offset[0]:offset[0]+patch['boundingbox'][0],
                   offset[1]:offset[1]+patch['boundingbox'][1],
                   offset[2]:offset[2]+patch['boundingbox'][2]] = localvolume.astype(np.uint8)

filehandling.psave(pathData + 'segmentation', segmentation)
print('Segmentations merged & saved.')

print('Creating global projections...')
canvas = canvas[0:region['partitioning']['cropping_boundingbox'][0],
                0:region['partitioning']['cropping_boundingbox'][1],
                0:region['partitioning']['cropping_boundingbox'][2]]
projections = {}
projections['y'] = np.max(canvas,0).astype(np.bool)
projections['x'] = np.max(canvas,1).astype(np.bool)
projections['z'] = np.max(canvas,2).astype(np.bool)
filehandling.psave(pathData + 'segmentationprojections', projections)
del canvas
print('Segmentation projections created & saved.')