199 lines
6.0 KiB
Python
199 lines
6.0 KiB
Python
import os
|
|
import cv2
|
|
import glob
|
|
import json
|
|
import numpy as np
|
|
import pandas as pd
|
|
import matplotlib.pyplot as plt
|
|
|
|
from tqdm import tqdm
|
|
from PIL import Image
|
|
from core.data import load_data_v2_plot,load_data_v2_plot_jj,load_data_v2_plot_cz,load_data_v2_plot_kw
|
|
from sklearn.metrics import accuracy_score, f1_score, recall_score, precision_score, confusion_matrix
|
|
|
|
|
|
def plot1(json_path, psize=24, img_size=2048):
|
|
bg = np.zeros((img_size, img_size)) + 255
|
|
bg[0, 0] = 0
|
|
|
|
points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=28)
|
|
|
|
mask_pd = np.zeros((img_size, img_size))
|
|
mask_pd[points[:, 0], points[:, 1]] = 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
|
|
plt.figure(figsize=(9, 9))
|
|
plt.imshow(bg, cmap='gray')
|
|
h, w = np.where(mask_pd != 0)
|
|
plt.scatter(points[:, 1], points[:, 0], s=16, c='#8EB9D9', zorder=2)
|
|
#
|
|
for idx, (s, e) in enumerate(edge_index.T):
|
|
s = points[s]
|
|
e = points[e]
|
|
plt.plot([s[1], e[1]], [s[0], e[0]], linewidth=1, c='#C0C0C0', zorder=1)
|
|
|
|
plt.axis('off')
|
|
|
|
plt.tight_layout()
|
|
|
|
|
|
def plot2(img_path, json_path, json_path2, json_path3, json_path4, psize=40):
|
|
# c = ['red', 'green', 'yellow']
|
|
# c = [ '#dfc8a0', '#84aad0','#93ba66']
|
|
|
|
# c = [ '#dfc8a0','#debd97', '#84aad0']
|
|
|
|
# c = ['#9BB6CF', '#9BB6CF', '#9BB6CF']
|
|
# c = ['#83a2c1', '#9BB6CF', '#9BB6CF']
|
|
|
|
# points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=25)
|
|
c = ['#dfc8a0', '#84aad0', '#93ba66']
|
|
points, edge_index, labels, _ = load_data_v2_plot(json_path,max_edge_length=28)
|
|
|
|
# points, edge_index, labels, _ = load_data_v2_plot_jj(json_path,max_edge_length=31)
|
|
|
|
# mask_pd = np.zeros((2048, 2048))
|
|
|
|
mask_pd = np.zeros((512, 512)) + 256
|
|
mask_pd[points[:, 0], points[:, 1]] = labels + 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
|
|
plt.figure(figsize=(9, 9))
|
|
|
|
img = np.array(Image.open(img_path))
|
|
# bg = np.zeros_like(img) + 255
|
|
# bg[0, 0] = 0
|
|
# plt.imshow(bg, cmap='gray')
|
|
|
|
|
|
|
|
# for idx, (s, e) in enumerate(edge_index.T):
|
|
# s = points[s]
|
|
# e = points[e]
|
|
# plt.plot([s[1], e[1]], [s[0], e[0]], linewidth=1, c='#C0C0C0', zorder=1)
|
|
|
|
# for i in range(3):
|
|
# h, w = np.where(mask_pd == i + 1)
|
|
# plt.scatter(w, h, s=psize, c=c[i])
|
|
#
|
|
# plt.imshow(img, cmap='gray')
|
|
# plt.axis('off')
|
|
# plt.tight_layout()
|
|
# plt.show()
|
|
|
|
# xj_points = points
|
|
|
|
# c = ['#84aad0', '#92b964', '#84aad0']
|
|
|
|
|
|
# #
|
|
# for idx, (s, e) in enumerate(edge_index.T):
|
|
# s = points[s]
|
|
# e = points[e]
|
|
# plt.plot([s[1], e[1]], [s[0], e[0]], linewidth=1, c='#C0C0C0', zorder=1)
|
|
|
|
|
|
|
|
|
|
# c = [ '#84aad0','#92b964','#92b964']
|
|
#debd97 黄 92b964 绿 84aad0 蓝
|
|
# c = [ '#92b964','#debd97','#debd97']
|
|
c = [ '#debd97','#84aad0','#debd97']
|
|
points, edge_index, labels, _ = load_data_v2_plot_jj(json_path2, max_edge_length=28)
|
|
|
|
AA = np.where(labels == 0)[0]
|
|
|
|
VV = np.where(labels == 1)[0]
|
|
labelsv = labels[VV]
|
|
pointsv = points[VV]
|
|
mask_pd = np.zeros((512, 512)) + 256
|
|
mask_pd[pointsv[:, 0], pointsv[:, 1]] = labelsv + 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
for i in range(3):
|
|
h, w = np.where(mask_pd == i + 1)
|
|
plt.scatter(w, h, s=psize, c=c[i])
|
|
|
|
# VV = np.where(labels == 2)[0]
|
|
labels = labels[AA]
|
|
points = points[AA]
|
|
mask_pd = np.zeros((512, 512)) + 256
|
|
mask_pd[points[:, 0], points[:, 1]] = labels + 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
for i in range(3):
|
|
h, w = np.where(mask_pd == i + 1)
|
|
plt.scatter(w, h, s=psize, c=c[i])
|
|
|
|
# plt.imshow(img, cmap='gray')
|
|
# plt.axis('off')
|
|
# plt.tight_layout()
|
|
# plt.show()
|
|
c = ['#84aad0', '#92b964', '#ff5b5b']
|
|
points, edge_index, labels, _ = load_data_v2_plot_kw(json_path4, max_edge_length=28)
|
|
|
|
VV = np.where(labels == 1)[0]
|
|
labels = labels[VV]
|
|
points = points[VV]
|
|
mask_pd = np.zeros((512, 512)) + 256
|
|
mask_pd[points[:, 0], points[:, 1]] = labels + 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
for i in range(3):
|
|
h, w = np.where(mask_pd == i + 1)
|
|
plt.scatter(w, h, s=psize, c=c[i])
|
|
|
|
|
|
c = ['#84aad0', '#ff5b5b', '#ff5b5b']
|
|
# points, edge_index, labels, _ = load_data_v2_plot_jj(json_path2, max_edge_length=28)
|
|
points, edge_index, labels, _ = load_data_v2_plot_cz(json_path3, max_edge_length=28)
|
|
|
|
# a = []
|
|
# b = []
|
|
#
|
|
# for i in points:
|
|
# if i not in xj_points:
|
|
# print(i)
|
|
VV = np.where(labels == 1)[0]
|
|
labels = labels[VV]
|
|
points = points[VV]
|
|
|
|
mask_pd = np.zeros((512, 512)) + 256
|
|
mask_pd[points[:, 0], points[:, 1]] = labels + 1
|
|
mask_pd = np.array(mask_pd, np.uint8)
|
|
for i in range(3):
|
|
h, w = np.where(mask_pd == i + 1)
|
|
plt.scatter(w, h, s=psize, c=c[i])
|
|
|
|
# plt.imshow(img, cmap='gray')
|
|
# plt.axis('off')
|
|
# plt.tight_layout()
|
|
|
|
|
|
|
|
#
|
|
#
|
|
|
|
plt.imshow(img, cmap='gray')
|
|
plt.axis('off')
|
|
plt.tight_layout()
|
|
|
|
plt.savefig('49.jpg', dpi=300)
|
|
plt.show()
|
|
|
|
|
|
# json_path4 = '/home/gao/mouclear/detect_40/40/39/jj_v2/after_test_v2/39.json'
|
|
# img_path4 = '/home/gao/mouclear/detect_40/40/39/jj_v2/after_test_v2/39.jpg'
|
|
# json_path1 = '/home/gao/mouclear/detect_40/40/39/cz/v1/39.json'
|
|
# img_path1 = '/home/gao/mouclear/detect_40/40/39/cz/v1/39.jpg'
|
|
# json_path3 = '/home/gao/mouclear/detect_40/40/39/smo/raw/39.json'
|
|
# img_path3 = '/home/gao/mouclear/detect_40/40/39/smo/raw/39.jpg'
|
|
# json_path2 = '/home/gao/mouclear/detect_40/40/39/xj_28/v2/39.json'
|
|
# img_path2 = '/home/gao/mouclear/detect_40/40/39/xj_28/v2/39.jpg'
|
|
|
|
json_path1 = '/home/gao/mouclear/cc/final_todo/fig_50/xj_result/raw/49.json'
|
|
img_path1 = '/home/gao/mouclear/cc/final_todo/fig_50/xj_result/raw/49.jpg'
|
|
json_path2 = '/home/gao/mouclear/cc/final_todo/fig_50/jj_result/raw/49.json'
|
|
json_path3 = '/home/gao/mouclear/cc/final_todo/fig_50/cz_result/raw/49.json'
|
|
json_path4 = '/home/gao/mouclear/cc/final_todo/kw_49_v2/49.json'
|
|
|
|
|
|
|
|
plot2(img_path1,json_path1, json_path2, json_path3, json_path4) |