You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
1.2KB

  1. import numpy as np
  2. from skimage.morphology import medial_axis
  3. def Crack_measure(_mask_cv_gray,dsx=(123-30)*1000/35*0.004387636):
  4. '''裂缝实际尺寸测量'''
  5. '''输入:单个裂缝分割图像
  6. 过程:。
  7. 返回:最终绘制的结果图、最终落水人员(坐标、类别、置信度),
  8. '''
  9. # 图像转化
  10. ###READ
  11. img = np.array(_mask_cv_gray.astype(np.int32))
  12. image0 = binary = img
  13. ###SKELETONIZATION
  14. img_skeletonized, distance = medial_axis(image0, return_distance=True)
  15. #print(img_skeletonized)
  16. img_skeletonized = np.array(img_skeletonized.astype(np.int32))
  17. ###COMPUTING WIDTH
  18. dist_on_skel = distance * img_skeletonized
  19. width = dist_on_skel[dist_on_skel != 0] * 2
  20. for i in range(len(width)):
  21. if width[i] <= 2.0:
  22. width[i] = width[i]
  23. else:
  24. width[i] = width[i] - 2
  25. ###OUTPUT
  26. real_length = np.count_nonzero(img_skeletonized) *dsx # Each pixel remaining after
  27. real_mean_width = np.mean(width)*dsx
  28. real_max_width = np.max(width)*dsx
  29. real_min_width = np.min(width)*dsx
  30. return real_length,real_mean_width,real_max_width,real_min_width