Exemple #1
0
#
# # calculate variables from acf of each set of image chunks and append to the df
# vars_far = []
# for im in far_chunks_df['far_chunks']:
#     acf = xy_autocorr(im)
#     middle = im.shape[0]//2+1
#     acf_x = x_profile(acf)[middle:]
#     acf_y = y_profile(acf)[middle:]
#     vars_far.append(acf_variables(acf_x, acf_y))
# vars_far_df = pd.concat(vars_far, axis=1).transpose()
# vars_far_df['label'] = ['f']*vars_far_df.shape[0]
# dat_far = pd.concat([far_chunks_df, vars_far_df], axis=1)
#
vars = []
for im in dat['chunk_im']:
    acf = xy_autocorr(im)
    middle = im.shape[0] // 2 + 1
    acf_x = x_profile(acf)[middle:]
    acf_y = y_profile(acf)[middle:]
    vars.append(acf_variables(acf_x, acf_y))
vars = pd.concat(vars, axis=1).transpose()
dat = pd.concat([dat, vars], axis=1)
dat = dat.replace([np.inf, -np.inf], np.nan).dropna()

# define which of the original images are near and which are unknown
dat_near = dat[dat['distance'] <= chunk_size]
dat_near['label'] = ['n'] * dat_near.shape[0]
dat_unknown = dat[dat['distance'] > chunk_size]
# add the next part if I use the far data from the original images
dist_90pc = np.percentile(dat['distance'], 90)
dat_unknown = dat_unknown[dat_unknown['distance'] < dist_90pc]
Exemple #2
0
plot_seg = False

f = open(dat_file, 'r')
for line in f.readlines():
    if line.startswith('Image') and not line.endswith('x\n') and not line.endswith('x'):
        vals = line.split(',')
        seg_file = os.path.join(seg_folder, vals[1])

        # read in the segmented images
        seg_im = io.imread(seg_file)
        hole_bool = (seg_im != 2).ravel()
        b_val = 2
        # print(np.unique(seg_im))
        seg_im[seg_im != 2] = 0
        seg_acf = xy_autocorr(seg_im)
        ang_acf = orientation(seg_acf)['angle'][0]
        # ang_acf = get_angle(orientation(seg_acf))

        if plot_seg:
            if ang_acf < 0:
                interc = 300
            elif ang_acf > math.pi/2 and ang_acf < math.pi:
                interc = 300
            else:
                interc = 200
            pl.imshow(seg_im, origin='lower')
            abline(ang_acf, interc)
            # pl.title(vals[1].replace('_', ', '))
            save_file = vals[1].rstrip('.tif') + '_angle_acf_onimage.png'
            pl.savefig(os.path.join(save_folder, save_file))
im_file = '/Users/s1101153/OneDrive - University of Edinburgh/Files/bubbles/confocal_data/tunnels/Image73.lsm'
seg_file = '/Users/s1101153/OneDrive - University of Edinburgh/Files/bubbles/confocal_data/tunnels/region_growing/Classified_image73.tif'

im = io.imread(im_file)[0]
seg_im = io.imread(seg_file)
hole_bool = (seg_im != 2).ravel()

chunks = split_image(im=im,
                     seg_im=seg_im,
                     bijel_val=2,
                     chunk_x=chunk_size,
                     chunk_y=chunk_size,
                     shift=chunk_size)

seg_angle = seg_orientation(seg_im, hole_bool)
seg_acf = xy_autocorr(seg_im)
seg_angle = orientation(seg_acf)['angle'][0]
seg_angle

seg_save = 'Image73'

pl.imshow(seg_im)
abline(seg_angle, 300)
pl.xlim(0, 512)
pl.savefig(seg_save + '_image.png')
pl.show()

pl.imshow(seg_acf)
abline(seg_angle, 300)
pl.xlim(0, 512)
pl.savefig(seg_save + '_acf.png')