文档服务地址:http://47.92.0.57:3000/ 周报索引地址:http://47.92.0.57:3000/s/NruNXRYmV

Commit dedd9c69 by 王肇一

sns plot barchart and scatter

parent 779e4979
......@@ -45,9 +45,10 @@ def step_1(net, args, device, list, position):
def step_2(list, position):
for dir in list:
for num, dir in enumerate(list):
df = pd.DataFrame(columns = ('ug', 'iter', 'id', 'size', 'area_mean', 'back_mean'))
for name in tqdm(filter(lambda x: x!='.DS_Store', os.listdir('data/imgs/'+dir)),position = position):
names = [x for x in filter(lambda x: x != '.DS_Store', os.listdir('data/imgs/' + dir))]
for name in tqdm(names, desc = f'Period{num+1}/{len(list)}', position = position):
match_group = re.match('.*\s([dD]2[oO]|[lL][bB]|.*ug).*\s(.+)\.tif', name)
img = cv.imread('data/imgs/' + dir + '/' + name, 0)
mask = cv.imread('data/masks/' + dir + '/' + name, 0)
......@@ -57,12 +58,13 @@ def step_2(list, position):
'ug') else str.lower(match_group.group(1))
tmp_df['iter'] = str.lower(match_group.group(2))
df = df.append(tmp_df, ignore_index = True, sort = True)
df['pure'] = df['area_mean'] - df['back_mean']
df['Intensity (a. u.)'] = df['area_mean'] - df['back_mean']
df.sort_values('ug',inplace = True)
baseline = df[df['ug']=='d2o']['pure'].mean()*0.62
baseline = df[df['ug']=='d2o']['Intensity (a. u.)'].mean()*0.62
sns.set_style("darkgrid")
sns.catplot(x = 'ug', y = 'pure', kind = 'bar', data = df)
sns.lineplot(x = 'ug', y=baseline,data = df)
sns.catplot(x = 'ug', y = 'Intensity (a. u.)', kind = 'bar', palette = 'vlag', data = df)
sns.swarmplot(x = "ug", y = "Intensity (a. u.)", data = df, size = 2, color = ".3", linewidth = 0)
plt.axhline(y=baseline)
plt.savefig('data/output/'+dir+'.png')
......@@ -108,11 +110,10 @@ if __name__ == '__main__':
elif args.step == 2:
dir = [x for x in filter(lambda x: x != '.DS_Store', os.listdir('data/imgs/'))]
sep_dir = divide_list(dir,args.process)
step_2(dir,0)
# pool = Pool(args.process)
# for i, list in enumerate(sep_dir):
# pool.apply_async(step_2, args = (list, i))
# pool.close()
# pool.join()
sep_dir = divide_list(dir, args.process)
pool = Pool(args.process)
for i, list in enumerate(sep_dir):
pool.apply_async(step_2, args = (list, i))
pool.close()
pool.join()
......@@ -20,10 +20,10 @@ def save_img(img_list, dir, name):
plt.title(title)
plt.imshow(img, 'gray')
try:
os.makedirs('data/output/' + dir + '/graph')
os.makedirs('data/output/' + dir)
except:
logging.info('Existing dir: data/output/' + dir)
plt.savefig('data/output/' + dir + '/graph/' + name[:-4] + '.png')
plt.savefig('data/output/' + dir + '/' + name[:-4] + '.png')
plt.close()
......@@ -42,6 +42,7 @@ def get_subarea_info(img, mask):
pos = [(group[0][k], group[1][k]) for k in range(len(group[0]))]
area_points = np.array([mask[x, y] if (x, y) in pos else 0 for x in range(200) for y in range(200)],dtype = np.uint8).reshape([200,200])
#cv.imwrite('mask.png',area_points)
kernel = np.ones((15, 15), np.uint8)
bg_area_mask = cv.erode(area_points, kernel)
surround_bg_mask = cv.bitwise_xor(bg_area_mask, 255 - area_points)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment