zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[pliman] 点点点就能准确识别病状特征

2023-03-07 09:47:14 时间

日常逛推的时候,一个新鲜的推文抓住了我的眼球

这是什么好东西!看样子可以在R中识别图片的不同区域。刚好最近在做叶部病害,让我们来看看该如何操作以及效果如何。

R4PDE

检索一下它的帮助文档[1],

R for Plant Disease Epidemiology (R4PDE) is a book project in the early stage of development. It is based on the teaching notes of my graduate course, FIP 602 - Plant Disease Epidemiology, offered every year for students of the Graduate Program in Plant Pathology of the Universidade Federal de Viçosa.

简单来说R4PDE(R for Plant Disease Epidemiology)是「Emerson M. Del Ponte教授」为了给研究生授课做的一个课程笔记,我们看到的这个功能在4 Image analysis[2]部分。

「发病面积百分比」是表示植物病害严重程度最常见的方法之一,特别是做叶部病害相关的实验时。通常衡量一种病害的发病情况,有两种衡量标准,即

  • 定量
  • 定性

定量(From R4PDE)

定性 (Scott and Hollins 1974)

为了评估植物病害严重程度的视觉估计是否足够准确,需要实际的严重程度值。在准备标准面积图(standard area diagrams, SAD)时也需要这些,SAD是在视觉评估之前或期间用作辅助的严重程度值的图解表示,以标准化并在不同评估者之间产生更准确的结果(Del Ponte 等,2017)。「简单来说,SAD就是一个标准发病图」

SAD定义为:a generic term for a pictorial or graphic representation (drawing or true-color photo) of selected disease severities on plants or plant parts (leaves, fruit, flowers, etc.) generally used as an aid for more accurate visual estimation (on the percentage scale) or classification (using an ordinal scale) of severity on a specimen.

SAD的一个示例(González-Domínguez et al. 2014)

更多的SAD可以查看SADBank[3]数据库,目前(221020)包含了174个SAD,其中来自63个寄主,118个病原菌。

通过检索可以看到,玉米的SAD有11个。

实际的严重程度值通常使用图像分析来近似化,根据发病植物的不同状态对图像的每个像素进行标记:

  • 有症状
  • 健康
  • 背景(图像中非植物部分)

发病面积与单位总面积之间的比率(乘以100时)即为发病面积百分比。研究人员已经使用了几种不同的专有或开源软件,根据对标准面积图的计算来确定实际的严重程度(Del Ponte等人,2017)。

在这个project中,Emerson教授使用R包「pliman(PLant IMage ANalysis)」(Olivoto 2022)中的函数「measure_disease()」 来测量患病面积的比例。同时,将该软件包与其他软件进行了比较,以确定五种不同的植物病害的严重程度,结果显示在大多数情况下都能产生较为准确的结果。

pliman包

pliman包的使用,其帮助文档[4]解释的很清楚。

使用原理很简单,你提供color pelettes,告诉它各个颜色都是代表什么,剩下的pliman会帮你识别。它可以做到:

  • 测量叶面积;
  • 测量疾病严重程度;
  • 计算病变的数量;
  • 获得病变的形状;
  • 制作标准面积图;
  • 对图像中的对象进行计数;
  • 获取对象特征(面积、周长、半径、圆度、偏心度、坚固度);
  • 获取图像中每个对象的RGB值;
  • 获取对象坐标;
  • 获取对象轮廓;
  • Get convex hulls(这个不知道该怎么翻译好,希望懂的朋友可以一起探讨一下);
  • 隔离对象;
  • 绘制对象度量值。

安装

## Install the latest stable version of pliman from CRAN with:
install.packages("pliman")

## The development version of pliman can be installed from GitHub with:
devtools::install_github("TiagoOlivoto/pliman")

# To build the HTML vignette use
devtools::install_github("TiagoOlivoto/pliman", build_vignettes = TRUE)

基本用法

Analyze objects

函数analyze_objects()[5]可用于「计算图像中的叶子、谷物、豆荚和花粉等对象的数量」。下面的示例计算具有30个谷物的图像的大豆谷物的特征。

比如使用以下代码计算出大豆的数量和特征

library(pliman)
img <-image_pliman("soybean_touch.jpg", plot = TRUE)
soy <- analyze_objects(img, marker = "id")
soy$statistics
#        stat      value
# 1         n    30.0000
# 2  min_area  1366.0000
# 3 mean_area  2057.3667
# 4  max_area  2445.0000
# 5   sd_area   230.5574
# 6  sum_area 61721.0000

Disease severity

正如前面提到的,通过给pliman提供color pelettes,分别告诉它健康部位、发病部位和背景的颜色,它就会识别出发病和健康部位的面积。

识别单张图

img <-image_pliman("sev_leaf.jpg")
healthy <-image_pliman("sev_healthy.jpg")
symptoms <-image_pliman("sev_sympt.jpg")
background <-image_pliman("sev_back.jpg")
image_combine(img, healthy, symptoms, background, ncol = 4)

当你导入自己的图片的时候需要使用image_import()。

sev <- 
  measure_disease(img = img,
                  img_healthy = healthy,
                  img_symptoms = symptoms,
                  img_background = background)
sev$severity
#    healthy symptomatic
# 1 89.04464    10.95536

识别多张图

在识别之前我们需要定义图片所在的文件夹,如果用户想要保存已处理的图片结果,则需要将save_image参数设置为TRUE,并且定义保存图像的目录。

Emerson教授在他的project中以10张大豆锈病发病的图为例子。

pliman <- measure_disease(
  pattern = "img",
  dir_original = "imgs/originals" ,
  dir_processed = "imgs/processed",
  save_image = TRUE,
  img_healthy = healthy,
  img_symptoms = symptoms,
  img_background = background,
  show_image = FALSE
)

severity <- pliman$severity; severity
     img  healthy symptomatic
1  img11 70.80072  29.1992835
2  img35 46.96430  53.0357002
3  img37 60.49390  39.5060986
4  img38 79.14737  20.8526306
5  img46 93.15143   6.8485680
6   img5 20.53977  79.4602312
7  img63 97.15698   2.8430190
8  img67 99.83723   0.1627709
9  img70 35.58683  64.4131683
10 img75 93.04517   6.9548329

图片也被以"proc"为前缀重命名保存到设定的文件夹中。

已被分析过的图像的一个示例

多图识别的效果怎么样?

在进行pliman识别之前,Emerson教授也使用了QUANT软件测量了这10张图的严重程度,并以此结果作为参考。

通过作相关性分析能够发现相关性系数超过了0.99(在R4PDE中有详细的计算过程)。

The coefficient is greater than 0.99 (1.0 is perfect concordance), suggesting an excellent agreement!

交互式识别

前面提到的都是自动识别,pliman也提供了「measure_disease_iter()」 函数用于交互识别,通过鼠标点点点去选中背景、健康和发病部位,进而识别出更准确的特征。

经过Emerson教授的同意,我将其在Youtube上的交互识别的例子下载下来,供大家学习。

总结一下,「基于调色板的方法(based on image palettes)最关键的一步是参考图像调色板的定义」。图片最好有对比鲜明的背景,且对于一些图片,可能需要多次调试,用户所做的选择会影响最终结果。

实战

刚好最近在做玉米的叶部病害,我们挑一张还热乎的病状图试试。

library(pliman)
img = image_import("img.JPG")
measure_disease_iter(img)

看起来效果非常不错!以下是结果信息

> measure_disease_iter(img)
Use the first mouse button to pick up BACKGROUND colors. Press Est to exit
Use the first mouse button to pick up LEAF colors. Press Est to exit
Use the first mouse button to pick up DISEASE colors. Press Est to exit
Are the selection correct? (y/n) y
$results
$severity
   healthy symptomatic
1 53.11424    46.88576

$shape
NULL

$statistics
NULL

attr(,"class")
[1] "plm_disease"

$leaf
Image 
  colorMode    : Color 
  storage.mode : double 
  dim          : 100 100 3 
  frames.total : 3 
  frames.render: 1 

imageData(object)[1:5,1:6,1]
          [,1]      [,2]      [,3]      [,4]      [,5]      [,6]
[1,] 0.2117647 0.2117647 0.2117647 0.2117647 0.2050000 0.1969608
[2,] 0.2149216 0.2149734 0.2151583 0.2153432 0.2142090 0.2128263
[3,] 0.2261765 0.2264132 0.2272574 0.2281015 0.2470412 0.2693902
[4,] 0.2374314 0.2378530 0.2393564 0.2408597 0.2798733 0.3259541
[5,] 0.2568039 0.2552323 0.2496289 0.2440256 0.2645408 0.2899769

$disease
Image 

我也测试了使用ImageJ去测量,可能是我ImageJ用的还不太好,我觉得操作有些繁琐,效果也不是很好。

参考资料

[1]

R4PDE的帮助文档: https://r4pde.netlify.app/data-sads.html#designing-sads-in-r

[2]

4 Image analysis: https://r4pde.netlify.app/data-actual-severity.html

[3]

SADBank: https://emdelponte.github.io/sadbank/

[4]

pliman帮助文档: https://tiagoolivoto.github.io/pliman/index.html

[5]

analyze_objects()的详细用法: https://tiagoolivoto.github.io/pliman/reference/analyze_objects.html