|
- from PIL import Image, ImageDraw
- import h5py
- import numpy as np
- import matplotlib.pyplot as plt
- from skimage.feature import peak_local_max
- from skimage.filters import gaussian
-
-
- def draw_feature_img(feature):
- res = {}
- plt.imshow(feature)
- plt.show()
- img = Image.fromarray(feature * 255 * 1.5)
- draw = ImageDraw.Draw(img)
- # gt_file = h5py.File("BCData/annotations/test/negative/0.h5")
- # res['H'] = np.asarray(gt_file['coordinates'])
- #
- # gt_file = h5py.File("BCData/annotations/test/positive/0.h5")
- # res['DAB'] = np.asarray(gt_file['coordinates'])
-
- # res["DAB"] = list(np.load("pos.npy"))
- # res["H"] = list(np.load("neg.npy"))
- cors = peak_local_max(feature - feature.mean(), min_distance=41, exclude_border=False)
- r = 5
- _target = np.zeros(shape=(640, 640), dtype=np.float16)
- for index in cors:
- x, y = index
- _target[int(x), int(y)] = 1
- draw.ellipse((x - r, y - r, x + r, y + r), fill=255)
- # for index in res['H']:
- # x, y = index
- # draw.ellipse((x - r, y - r, x + r, y + r), (0, 0, 255), (0, 0, 255))
- # _target = gaussian(_target.astype(np.uint32), sigma=8)
- # peak_local_max(temp_dm, min_distance=21, exclude_border=False)
- plt.imshow(img)
- plt.show()
-
- if __name__ == '__main__':
- feature = np.load("p.npy")
- draw_feature_img(feature)
|