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.

crackUtils.py 1.3KB

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