Closed friendsAI closed 4 years ago
The doc title still uses the old terminology of analyze shape
https://plantcv.readthedocs.io/en/stable/analyze_shape/
YOu don't need to use cv2.findContours()
. better to use pcv.find_objects
https://plantcv.readthedocs.io/en/stable/find_objects/ to stay within the plantcv ecosystem.
after you use pcv.find_objects()
, use pcv.analyze_object()
to get your shape characteristics. there is a center of mass entry that could be used as the central point. See the parallelization tutorial to get this running over several images. https://plantcv.readthedocs.io/en/stable/pipeline_parallel/
at the end of the tutorial you'll see you can convert the json with all the outputs into a csv.
Hi @friendsAI !
To add onto everything that @dschneiderch already said, I wanted to mention that you can also access all the data being collected by pcv.analyze_object
. We use an Outputs class from the doc page for the shape data collection function but I wanted to also point out that you can follow this example to access and manipulate the central point within your workflow (without using pcv.print_results
to print data out first). Please let us know if this resolves your question!
Thank you for your help @dschneiderch I tried ,but failed. The following is the code: img_file='maize.jpg' #this is the original RGB image. mask_file='blackwhite.png' #this is the binary image of img_file. img=cv2.imread(img_file) mask=cv2.imread(mask_file,0) id_objects, obj_hierarchy = pcv.find_objects(img, mask) central_img=pcv.analyze_object(img,id_objects,mask) Here error occurs: analyze_object.py in analyze_object(img, obj, mask) 50 51 # Convex Hull ---> 52 hull = cv2.convexHull(obj) 53 hull_vertices = len(hull) 54 # Moments
TypeError: Expected Ptr
I would guess you need to try object composition Try following the VIS tutorial: https://plantcv.readthedocs.io/en/stable/vis_tutorial/ Where it says after Fig 13: The isolated objects now should all be plant material. There can be more than one object that makes up a plant since sometimes leaves twist making them appear in images as separate objects. Therefore, in order for shape analysis to perform properly the plant objects need to be combined into one object using the combine objectshttps://plantcv.readthedocs.io/en/stable/object_composition/ function.
From: friendsAI notifications@github.com Sent: Monday, April 13, 2020 19:18 To: danforthcenter/plantcv plantcv@noreply.github.com Cc: Schneider, Dominik dominik.schneider@wsu.edu; Mention mention@noreply.github.com Subject: Re: [danforthcenter/plantcv] How to get the central point of seedlings by using plantcv? (#563)
Thank you for your help @dschneiderchhttps://urldefense.com/v3/__https:/github.com/dschneiderch__;!!JmPEgBY0HMszNaDT!9t4TcBWQ2qaP8OX4d2rBReluTx-Jh_rHJasBwxRXsyD1CN6bvkM_zjBsS7IcSACx5wfKQQ$ I tried ,but failed. The following is the code: img_file='maize.jpg' #this is the original RGB image. mask_file='blackwhite.png' #this is the binary image of img_file. img=cv2.imread(img_file) mask=cv2.imread(mask_file,0) id_objects, obj_hierarchy = pcv.find_objects(img, mask) central_img=pcv.analyze_object(img,id_objects,mask) Here error occurs: analyze_object.py in analyze_object(img, obj, mask) 50 51 # Convex Hull ---> 52 hull = cv2.convexHull(obj) 53 hull_vertices = len(hull) 54 # Moments
TypeError: Expected Ptrcv::UMat for argument 'points'
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https:/github.com/danforthcenter/plantcv/issues/563*issuecomment-613189003__;Iw!!JmPEgBY0HMszNaDT!9t4TcBWQ2qaP8OX4d2rBReluTx-Jh_rHJasBwxRXsyD1CN6bvkM_zjBsS7IcSAAdXsanyw$, or unsubscribehttps://urldefense.com/v3/__https:/github.com/notifications/unsubscribe-auth/ABY5SZI4Q5CMZOMIJL3MUZDRMPBWRANCNFSM4MG2VWMA__;!!JmPEgBY0HMszNaDT!9t4TcBWQ2qaP8OX4d2rBReluTx-Jh_rHJasBwxRXsyD1CN6bvkM_zjBsS7IcSAD7ri3tyg$.
Well, I'm confused. There are many seedlings in the image, I want to automatically identify these seedlings and use dots to represent each seedling. First, I use pcv.find_objects() to get contour of every seedling as I use cv2.findContours(). Then, I use pcv.analyze_object() to get central point of each seedling.
Hi @friendsAI, I think something like the multi-plant tutorial is what you are looking for: https://plantcv.readthedocs.io/en/stable/multi-plant_tutorial/. In the tutorial we use the pcv.cluster_contours
method to identify separate plants, but pcv.roi.multi
is another way to achieve this. Alternatively, if seedlings can be identified individually as single contours each, then you might not need either of those methods.
But whichever route you take, you will need to loop over the individual plant contours and do pcv.object_composition
on each before doing any of the analyze functions. The pcv.object_composition
function groups separate contours into a single object, but this changes the format of the contour. The analyze functions expect this format, so even if you have a single contour it needs to be reformatted by this function.
I have a demo notebook that shows how to do this: https://github.com/nfahlgren/shared_jupyter_notebooks/blob/master/arabidopsis-multiplant.ipynb
Thank you all! I solved my problem.
I want to get the central point of seedlings which photoed above.
After I use cv2.findContours(), I got some contours, then I use pcv.analyze_object() to get each point from every seedling. But its usage confused me. I also can't find any help from https://plantcv.readthedocs.io/ by seaching the keyword analyze_object().