danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
666 stars 265 forks source link

Using PlantCV pcv.segment_image_series and pcv.create_labels to do image analysis #1572

Open ariaf7 opened 3 months ago

ariaf7 commented 3 months ago

Hello! I am working with PlantCV to do image analysis of lettuce plants. I want to use the output from pcv.segment_image_series to analyze the shape and color of each of my lettuce plants. They overlap, which is why I am using pcv.segment_image_series in the first place. Here are the functions I am trying to use to do my analysis:

shape_img = pcv.analyze.size(img=img, **labeled_mask=labeled_mask**, n_labels=18)

shape_img = pcv.analyze.color(rgb_img=img, labeled_mask=labeled_mask, n_labels=18, colorspaces="RGB")

I know I need to use some sort of labeled_mask, num_plants = pcv.create_labels(mask=th_fill, rois=rois, roi_type="partial") for the labeled mask. However, I want to use the output from the pcv.segment_image_series function because it takes care of the overlap, while pcv.create_labels does not. And I can't use my output from the pcv.segment_image_series as input for pcv.create_labels or shape_img because the output isn't the right type. Sorry for not being very clear, I have very limited experience with PlantCV. I am not using the most recent version of PlantCV because I do not know how to update it as well. What do you all recommend?

HaleySchuhl commented 3 months ago

Hi @ariaf7 thanks for opening this issue. It has been brought up recently that the pcv.segment_image_series was a bit overlooked while we were updating the way PlantCV handles multi-object analysis in v4. This is something we're looking to address soon. In the meanwhile, here's how I was able to work around it. For more detail upstream of these steps, also see this GitHub issue.

...
analysis_image = pcv.segment_image_series(imgs_paths=paths_to_imgs_list, masks_paths=paths_to_masks_list, rois=valid_rois, save_labels=True, ksize=3)

lbl_mask = analysis_image[:,:,1]
shape_img = pcv.analyze.size(img=img, labeled_mask=lbl_mask, n_labels=20)
rgb_plot = pcv.analyze.color(rgb_img=img, labeled_mask=lbl_mask, n_labels=20, colorspaces="RGB")

Regarding updating your version of PlantCV, please refer to our updating doc page to see the recommendation depending on how you installed it. Please let us know if this helps.

Figure 24 Figure 87