在R中的EBImage中绘制特征数量 [英] Plotting numbers of features in EBImage in R

查看:211
本文介绍了在R中的EBImage中绘制特征数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对EBImage的computeFeatures函数有疑问.我使用以下代码来计算功能.

I have a question regarding the computeFeatures function of EBImage. I used the following code to compute the features.

biocLite("EBImage")
library (EBImage)
Image <- readImage("test.jpg")
Image3<-getFrame(Image,3)
x = thresh(Image3, w=15, h=15, offset=0.05) 
x = opening(x, makeBrush(5, shape='disc')) 
x = bwlabel(x) 
fts = computeFeatures.shape(x) 

这给了我一系列计算出的特征.但是,这是39个功能的列表,我仅对其中一些功能感兴趣.因此,我想知道哪个computeFeatures对应于图像中的每个特征.

This gives me a list of the computed features. However, this is a list of 39 features, and I am only interested in a few of them. Thus I would like to know which of the computeFeatures correspond to each features in the image.

http://www上提出了一种解决方案. bricol.net/research/leafranks/11-01MS/EBImage-introduction.pdf 通过使用以下代码:

> nmask = thresh(nuc, 10, 10, 0.05) 
> nmask = opening(nmask, makeBrush(5, shape='disc')) 
> nmask = fillHull(nmask) 
> nmask = bwlabel(nmask) Cell bodies are segmented using propagate. 
> ctmask = opening(cel>0.1, makeBrush(5, shape='disc')) 
> cmask = propagate(cel, nmask, ctmask)
> res = paintObjects(cmask, img, col='#ff00ff') 
> res = paintObjects(nmask, res, col='#ffff00')
> xy = lapply(hullFeatures(cmask), function(hf) hf[, c('g.x', 'g.y')]) 
> labels = lapply(xy, function(z) as.character(1:nrow(z))) 
> font = drawfont(weight=600, size=16) 
> res = drawtext(res, xy=xy, labels=labels , font=font, col="white")

在图像上绘制与特征相对应的数字. 但是,功能hullFeatures不再可用.

Which plots numbers corresponding to the features on the Image. However, the function hullFeatures is no longer available.

因此,还有其他方法可以绘制图像中的特征或对象的数量吗?

Thus, is there an other way to plot the number of the features or objects in the Image?

推荐答案

函数hullFeaturesdrawtext已失效. hullFeatures已由computeFeatures.shape代替.现在,需要使用computeFeatures.moment查找每个对象的位置.基本的text函数现在用于将文本添加到以光栅模式绘制的图像中.

The functions hullFeatures and drawtext are defunct. hullFeatures has been replaced by computeFeatures.shape. Now one needs to use computeFeatures.moment to find the position of each object. The base text function is now used to add text to an image plotted in raster mode.

EBImage的详细概述可以在插图中找到:vignette("EBImage-introduction", package = "EBImage").但是,在版本4.22.1中,小插图不再显示如何对分割的对象进行编号.这是Pau,Sklyar和Huber于2010年4月22日发布的PDF示例的重演.

A great overview of EBImage can be found in the vignette: vignette("EBImage-introduction", package = "EBImage"). However, with version 4.22.1, the vignette no longer shows how to number the segmented objects. Here's a recreation of the example from the PDF dated April 22, 2010 by Pau, Sklyar and Huber.

为了稍微澄清一下术语,computeFeatures函数家族返回尺寸为n x p的矩阵,其中n是分段的对象(行)的数量,而p功能(列)的数量.在此示例中,每个对象都是一个单元格. computeFeatures.moment返回的功能是m.cx, m.cy, m.majoraxis, m.eccentricitym.theta.该位置由前两个功能指定.

To clarify the nomenclature a bit, the computeFeatures family of functions return a matrix of dimension n x p where n is the number of segmented objects (rows) and p is the number of features (columns). In this example, each object is a cell. The features returned by computeFeatures.moment are m.cx, m.cy, m.majoraxis, m.eccentricity and m.theta. The position is specified by the first two features.

# Starting from EBImage
  if (!require(EBImage)) {
    source("http://bioconductor.org/biocLite.R")
    biocLite("EBImage")
    library(EBImage)
  }

# Use example nuclei and cells, make colorized composite
  nuc <- readImage(system.file('images', 'nuclei.tif', package='EBImage'))
  cel <- readImage(system.file('images', 'cells.tif', package='EBImage'))
  img <- rgbImage(green=1.5*cel, blue=nuc)

# Recreate nuclear and cell masks, add border to color composite
  nmask <- thresh(nuc, 10, 10, 0.05)
  nmask <- opening(nmask, makeBrush(5, shape='disc')) 
  nmask <- fillHull(nmask) 
  nmask <- bwlabel(nmask)
  ctmask <- opening(cel>0.1, makeBrush(5, shape='disc')) 
  cmask <- propagate(cel, nmask, ctmask)
  res <- paintObjects(cmask, img, col='#ff00ff') 
  res <- paintObjects(nmask, res, col='#ffff00')

# Determine position (center of mass) of each object in 'cmask'
  M <- apply(cmask, 3, computeFeatures.moment) # list of length 4 returned
  xy <- lapply(M, function(m) m[,c("m.cx", "m.cy")])

# Create labels and plot in 'raster' mode 
  labels <- lapply(xy, function(z) as.character(1:nrow(z)))
  plot(getFrame(res, 3, type = "render")) # or plot(res[,,,3])

# Add labels by text function
  text(xy[[3]], labels[[3]], col = "white")

这篇关于在R中的EBImage中绘制特征数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆