我正在尝试使用 R 计算叶片损伤百分比。我能够使用 pliman 包进行图像分割和面积计算,遵循以下文档:https://cran.r-project.org/web/packages/pliman/vignettes/pliman_start.html
我正在使用以下 R 代码。我放置了一个1cm的正方形作为参考尺度。可以在此处下载样本分割图像here:
#...........................Load image...........................
library(pliman)
img_segm <- pliman::image_import("C:/Users/sando/Desktop/test/imgseg/imgseg.jpg")
#.........................Analize leaves.........................
layout(t(1:2))
meas <- analyze_objects(img_segm, index = "BIM", marker = "id", invert= F,show_image=T, parallel=T, watershed= T, fill_hull= F,
tolerance = 30, object_size = "large")
# Measures area in pixels
area1 <- get_measures(meas)[,c(1,4)]
area1
# Correct the measures using an object in cm
real.area <- get_measures(meas, id = 1, area ~ 1)[,c(1,4)]
real.area
#........................Analize contour.........................
# Draw a convex hull around the objects.
cont_meas <- analyze_objects(img_segm,
watershed = T,
marker = "id",
show_chull = TRUE,index = "BIM", invert= F,show_image=T, parallel=T, fill_hull= F, tolerance = 30, object_size = "large") # shows the convex hull
# Measures area
real.area2 <- get_measures(cont_meas, id = 1, area ~ 1 )[,c(1,4)]
然而,我无法获取受损区域,并且无法使用颜色分割,因为背景是白色的。我希望能够:
- 单独识别每片叶子
- 使用某种凸包检测或ROI来预测或选择缺失的叶子边缘。
- 计算受损面积(红色)和总面积(叶子+红色)。
我知道可以进行一些二进制转换。所以我尝试了以下代码:
#### detect contours in red
library(imager)
img_segm2 <- imager::as.cimg(img_segm)
plot(img_segm2)
# isoblur, greyscale
img_segm3 <- isoblur(grayscale(img_segm2),2) > .60
plot(img_segm3)
px <- img_segm3 > 0.1
ct <- imager::contours(px,nlevels=3)
plot(px)
#Add contour lines
purrr::walk(ct,function(v) lines(v$x,v$y,col="red",lwd=1.5))
有没有一种半自动的方法可以让我获取这个? 我知道可以在ImageJ和一些软件(如leafbyte或bioleaf)中完成,但我希望能够在R或Python中分析这些图像。谢谢您的时间。