r - 使用 Multi Spec 和 R 进行批量图像分析

标签 r batch-processing imaging

是否可以使用 R 使一批图像通过 Multi Spec(或任何其他程序 - 不包括 ImageJ)运行,而不是单个图像分析?

如果是的话怎么办?

我使用以下链接附上了我正在寻找的图片: “http://figshare.com/s/f81b92ea474f11e5b78d06ec4bbcf141” "http://figshare.com/s/463ec4ce475011e5909106ec4b8d1f61 "

“编辑”图像是“ms485_a7c5,c3aR 40x gm 1.tif”的副本,其中突出显示了我要搜索的内容。

蓝色圆圈周围的黑框是我正在寻找的一组数据,特别是它们在图像中的数量以及它们覆盖的图像面积百分比。 合并的蓝色和棕色区域周围的红色框也是我特别要寻找的东西,其所需的值与上述相同。 最后,图像的棕色区域也是我要寻找的,但仅限于图像中覆盖的 % 区域。

我能够在 Multi-Spec 上对 1 张图像进行分析,但我需要对 1000 多张图像进行分析,但我无法执行此操作,因为我不熟悉 R 或其他编码程序。

提前致谢

最佳答案

所以,我不知道这会让你走多远,但在你的内存限制内一次处理每张图像应该是可行的。概述的方法是应用于图像的最基本的阈值处理。可以应用更复杂的方法:

library(raster)

i <- brick("./data/ms485_a7c5_c3aR_40x_gm_1.tif")
names(i) <- c("r", "g", "b")

##  Plot image:
plotRGB(i)

enter image description here

##  Here you could use a more sophisticated classification method:
#k <- kmeans(i[], centers=4, iter.max = 100, nstart = 4)
#c <- raster(i)
#c[] <- c$cluster

##  Instead we'll just set some simple thresholds:
c1 <- (i$r < 170 & i$g < 140 & i$b > 150)*1  ## Blues
c2 <- (i$r > 150 & i$g > 150 & i$b > 150)*2  ## Lights
c3 <- (i$r < 170 & i$g < 150 & i$b < 140)*3  ## Darks

##  Plot the classified data so you see what you're summarizing below:
plot(c, add=T, legend=F, col=c(
  rgb(255, 255, 255, maxColorValue=255),
  rgb(100, 100, 180, maxColorValue=255),
  rgb(220, 220, 220, maxColorValue=255),
  rgb(120, 100, 90, maxColorValue=255)
))

enter image description here

##  And calculate your summary stats by class:

t <- table(c[])
names(t) <- c("Unclassified", "Blues", "Lights", "Darks")
t

##  Unclassified        Blues       Lights        Darks 
##        283887       220042      4475129       376942

##  Or we can calculate those cell counts as percentages of pixels:
t/ncell(c) * 100

##  Unclassified        Blues       Lights        Darks 
##      5.300355     4.108327    83.553566     7.037752 

现在,由于您尚未使用可以准确识别蓝色区域的技术对图像进行分割或阈值处理,因此您将不得不找出最适合您的方法。获得分类图像后,您可以使用 SDMTools 包来计算图像中出现的不同 block 等的数量。

##  To summarize distinct patches within your classified "Blues":
library(SDMTools)

##  Calculate stats, and count all patches for "Blues":
class_stats <- ClassStat(c1, cellsize=1, bkgd=0)
class_stats$n.patches

##  [1] 1858

##  Only count patches larger than 10 pixels:
image_clusters <- ConnCompLabel( c1 )
patch_stats <- PatchStat(image_clusters, cellsize=1)
sum(patch_stats[patch_stats$patchID>0,]$n.cell > 10)

##  [1] 462

关于r - 使用 Multi Spec 和 R 进行批量图像分析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32074992/

相关文章:

windows - 批处理文件复制文件

python 3.5 : Moving files to folder based on filenames

linux - 在 BASH 中使用特殊字符从文件名中批量删除子字符串

python - 如何使用 pydicom 创建 JPEG 压缩 DICOM 数据集?

opencv - 加快拼接 2 张图像?

r - 具有设定起点和终点的旅行推销员 (TSP)

r - 当另一列等于 0 时将特定列更改为 NA

r - R 中使用 brm 的负二项式回归在使用多核时会导致错误

r - 日历热图俄罗斯方 block 图表

wpf - 将 wpf 图像控件保存到文件的最简单方法