danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
655 stars 264 forks source link

Find Branch/Junction Points in a skeletonized image not working properly #691

Closed researcherys closed 3 years ago

researcherys commented 3 years ago

Describe the bug Running pcv.morphology.find_branch_pts does not find every Branch/Junction point in the skeletonized image. It took twice to run it to complete disjunction of all branches in the attached image.

To Reproduce img = cv2.imread("Initial.jpg", 0) binary = img >= 250 skeleton = pcv.morphology.skeletonize(mask=binary) plt.imshow(skeleton, interpolation='nearest') prunedskeleton, , _ = pcv.morphology.prune(skel_img=skeleton, size=10) br_points = pcv.morphology.find_branch_pts(skel_img=pruned_skeleton)

new_skel = pruned_skeleton - br_points plt.imshow(new_skel, interpolation='nearest') br_points = pcv.morphology.find_branch_pts(skel_img=new_skel) new_skel = new_skel - br_points plt.imshow(new_skel, interpolation='nearest') plt.show()

  1. Starting with image 'Initial.jpg' Initial
  2. Continue with image after skeletonization: 'beforeBranch.jpg' beforeBranch
  3. Continue with image after subtraction of the first find_branch_pts: 'after1Branch.jpg' after1Branch
  4. And final image after subtraction of the second find_branch_pts: 'after2Branch.jpg' after2Branch

Local environment (please complete the following information):

HaleySchuhl commented 3 years ago

Hi @researcherys , Thanks for opening a descriptive issue! The images you've provided make it clear what you're talking about. However, you don't need to manually subtract the branch points from your skeleton, as we already have a function pcv.morphology.segment_skeleton which you can use to break skeletons into their segments. Within this function, we dilate the branch points before subtracting in order to ensure disjunction will only take one step (in the majority of cases at least). Additionally, if you wish to both disjoint the skeleton and sort them into primary & secondary ranked segments, our pcv.morphology.segment_sort will do this in one step.

Please let us know if this helps you achieve your desired result, or if you have any related things come up!