danforthcenter / plantcv

Plant phenotyping with image analysis
Mozilla Public License 2.0
634 stars 259 forks source link

Add circular crop? #1561

Open k034b363 opened 3 weeks ago

k034b363 commented 3 weeks ago

Is your feature request related to a problem? Please describe. A few times recently it has seemed like cropping to a circle would be useful, but I'm not sure how hard it would be. One specific example involves X-ray images of seeds inside of a Petri dish. The dish is very bright, so being able to crop to everything inside, even if it means just zero-ing out some padding around the outside to keep displaying a rectangle, would I think help some downstream analysis.

Describe the solution you'd like A separate function like the current crop, but that takes a center point and radius as input for cropping.

nfahlgren commented 3 weeks ago

Hi Keely, would this approach work for you?

from plantcv import plantcv as pcv
# Read image
img, _, _ = pcv.readimage(filename="2017-01-18_1510_ch129-pos01.jpg")
# Create circle ROI
roi = pcv.roi.circle(img=img, x=1300, y=1200, r=200)
# Convert ROI to a mask
roimask = pcv.roi.roi2mask(img=img, roi=roi)
# Mask the input image
masked = pcv.apply_mask(img=img, mask=roimask, mask_color="black")

2017-01-18_1510_ch129-pos01 Figure 7

k034b363 commented 3 weeks ago

Yes, thank you! That's what Pavan ended up doing, and it works great. Maybe for the sake of redundancy (and since it's only 3 steps), it doesn't make sense to have a separate function.