0
点赞
收藏
分享

微信扫一扫

获取二值掩膜内各图斑的内部点

诗远 2022-06-28 阅读 95

结果

话不多说,直接上结果,获取的点为圆心。
获取二值掩膜内各图斑的内部点_#import

代码

# -*- coding:utf-8 -*-
import cv2
import numpy as np
import gdalTools
from scipy import ndimage as ndi

import matplotlib.pyplot as plt
####################################################################################


if __name__ == '__main__':

#import Image
im_proj, im_geotrans, im_width, im_height, im = gdalTools.read_img('data/image.tif')
im = im.transpose((1, 2, 0))
image = im.copy()
_, _, _, _, mask = gdalTools.read_img('data/seed.tif')
markers = ndi.label(mask, output=np.uint32)[0]
unis = np.unique(markers)
point_color = (0, 0, 255) # BGR
for uni in unis:
if uni == 0:
continue
pointsX, pointsY = np.where(markers==uni)
pointX, pointY = pointsX[0], pointsY[0]
cv2.circle(image, (pointY, pointX), 5, point_color, 2)
im_shape = im.shape
height = im_shape[0]
width = im_shape[1]

plt.subplot(131)
plt.imshow(im)
plt.subplot(132)
plt.imshow(image)
plt.subplot(133)
plt.imshow(mask)
plt.show()


举报

相关推荐

0 条评论