|
|
@@ -137,8 +137,8 @@ def trans_datasets_format():
|
|
|
|
|
|
# non_zero_coords = np.nonzero(inm.reshape(width,height).T)
|
|
|
# coords_list = list(zip(non_zero_coords[0], non_zero_coords[1]))
|
|
|
- # # print(f'mask:{mask[0,333]}')
|
|
|
- # print(f'mask pixels:{coords_list}')
|
|
|
+ # # print(f'ins:{ins[0,333]}')
|
|
|
+ # print(f'ins pixels:{coords_list}')
|
|
|
#
|
|
|
#
|
|
|
# for coord in coords_list:
|
|
|
@@ -150,7 +150,7 @@ def trans_datasets_format():
|
|
|
writer.close()
|
|
|
print(f'label:{label}')
|
|
|
# plt.imshow(img)
|
|
|
- # plt.imshow(mask, cmap='Reds', alpha=0.3)
|
|
|
+ # plt.imshow(ins, cmap='Reds', alpha=0.3)
|
|
|
# plt.show()
|
|
|
|
|
|
|
|
|
@@ -168,17 +168,17 @@ def compute_mask(row, shape):
|
|
|
mask[s:s + l] = 255
|
|
|
mask = mask.reshape((width, height)).T
|
|
|
|
|
|
- # mask = np.flipud(np.rot90(mask.reshape((height, width))))
|
|
|
+ # ins = np.flipud(np.rot90(ins.reshape((height, width))))
|
|
|
return label, mask
|
|
|
|
|
|
def cluster_dbscan(mask,image):
|
|
|
- # 将 mask 转换为二值图像
|
|
|
+ # 将 ins 转换为二值图像
|
|
|
_, mask_binary = cv2.threshold(mask, 127, 255, cv2.THRESH_BINARY)
|
|
|
|
|
|
- # 将 mask 一维化
|
|
|
+ # 将 ins 一维化
|
|
|
mask_flattened = mask_binary.flatten()
|
|
|
|
|
|
- # 获取 mask 中的前景像素坐标
|
|
|
+ # 获取 ins 中的前景像素坐标
|
|
|
foreground_pixels = np.argwhere(mask_flattened == 255)
|
|
|
|
|
|
# 将像素坐标转换为二维坐标
|
|
|
@@ -219,14 +219,14 @@ def cluster_dbscan(mask,image):
|
|
|
return unique_labels,clustered_points
|
|
|
|
|
|
def show_cluster_dbscan(mask,image,unique_labels,clustered_points,):
|
|
|
- print(f'mask shape:{mask.shape}')
|
|
|
- # 将 mask 转换为二值图像
|
|
|
+ print(f'ins shape:{mask.shape}')
|
|
|
+ # 将 ins 转换为二值图像
|
|
|
_, mask_binary = cv2.threshold(mask, 127, 255, cv2.THRESH_BINARY)
|
|
|
|
|
|
- # 将 mask 一维化
|
|
|
+ # 将 ins 一维化
|
|
|
mask_flattened = mask_binary.flatten()
|
|
|
|
|
|
- # 获取 mask 中的前景像素坐标
|
|
|
+ # 获取 ins 中的前景像素坐标
|
|
|
foreground_pixels = np.argwhere(mask_flattened == 255)
|
|
|
# print(f'unique_labels:{unique_labels}')
|
|
|
# 创建一个空的图像来保存聚类结果
|
|
|
@@ -326,11 +326,11 @@ def test_mask():
|
|
|
# points = np.array([[float(parts[i]), float(parts[i + 1])] for i in range(1, len(parts), 2)])
|
|
|
# mask_resized = cv2.resize(points, (1600, 256), interpolation=cv2.INTER_NEAREST)
|
|
|
print(f'points:{points}')
|
|
|
- # mask[points[:,0],points[:,1]]=255
|
|
|
+ # ins[points[:,0],points[:,1]]=255
|
|
|
for p in points:
|
|
|
mask[p] = 255
|
|
|
- # cv2.fillPoly(mask, points, color=(255,))
|
|
|
- cv2.imshow('mask', mask)
|
|
|
+ # cv2.fillPoly(ins, points, color=(255,))
|
|
|
+ cv2.imshow('ins', mask)
|
|
|
for row in df.itertuples():
|
|
|
img_name = name + '.jpg'
|
|
|
if img_name == getattr(row, 'ImageId'):
|
|
|
@@ -391,7 +391,7 @@ def show_img_mask(img_path):
|
|
|
# mask_3channel = cv2.merge([np.zeros_like(img_mask), np.zeros_like(img_mask), img_mask])
|
|
|
# masked_image = cv2.addWeighted(test_img, 1, mask_3channel, 0.6, 0)
|
|
|
|
|
|
- # cv2.imshow('cv2 mask img', masked_image)
|
|
|
+ # cv2.imshow('cv2 ins img', masked_image)
|
|
|
# cv2.waitKey(0)
|
|
|
plt.show()
|
|
|
|
|
|
@@ -459,7 +459,7 @@ def show_dataset():
|
|
|
masks=targets[0]['masks']
|
|
|
boxes = targets[0]['boxes']
|
|
|
print(f'boxes:{boxes}')
|
|
|
- # mask[mask == 255] = 1
|
|
|
+ # ins[ins == 255] = 1
|
|
|
# img = np.array(imgs[2].permute(1, 2, 0)) * 255
|
|
|
show_boxes_masks( imgs, boxes,masks)
|
|
|
|
|
|
@@ -471,14 +471,14 @@ def show_boxes_masks(imgs, boxes,masks):
|
|
|
print(f'masks shape:{masks.shape}')
|
|
|
print(f'img shape:{img.shape}')
|
|
|
print(f'img shape:{img.shape}')
|
|
|
- # print(f'mask:{mask.shape}')
|
|
|
+ # print(f'ins:{ins.shape}')
|
|
|
# mask_3channel = cv2.merge([np.zeros_like(masks[0]), np.zeros_like(masks[0]), masks[0]])
|
|
|
# print(f'mask_3channel:{mask_3channel.shape}')
|
|
|
img_tensor = torch.tensor(imgs[0], dtype=torch.uint8)
|
|
|
boxed_img = draw_bounding_boxes(img_tensor, boxes).permute(1, 2, 0).contiguous()
|
|
|
masked_img = draw_segmentation_masks(img_tensor, masks).permute(1, 2, 0).contiguous()
|
|
|
plt.imshow(imgs[0].permute(1, 2, 0))
|
|
|
- # plt.imshow(mask, cmap='Reds', alpha=0.5)
|
|
|
+ # plt.imshow(ins, cmap='Reds', alpha=0.5)
|
|
|
plt.imshow(masked_img, cmap='Reds', alpha=0.3)
|
|
|
plt.imshow(boxed_img, cmap='Greens', alpha=0.5)
|
|
|
plt.show()
|