R/ImageJ: Measuring shortest distance between points and curves

一笑奈何 提交于 2019-12-04 09:40:34

EDIT: Doing this is now possible using sclero package. The package is currently available on GitHub and the procedure is described in detail in the tutorial. Just to illustrate, I use an example from the tutorial:

library(devtools)
install_github("MikkoVihtakari/sclero", dependencies = TRUE)
library(sclero)
path <- file.path(system.file("extdata", package = "sclero"), "shellspots.zip")
dat <- read.ijdata(path, scale = 0.7812, unit = "um") 
shell <- convert.ijdata(dat)
aligned <- spot.dist(shell)
plot(aligned)

It is also possible to add sample spot sizes using the functions provided by the sclero package. Please see Section 2.5 in the tutorial.

There's a tool for edge detection written for Image J that might help you first find the holes and the lines, and clarify them. You find it at

http://imagejdocu.tudor.lu/doku.php?id=plugin:filter:edge_detection:start

Playing around with the settings for the tresholding and the hysteresis can help in order to get the lines and holes found. It's difficult to tell whether this has much chance of working without seeing your actual photographs, but a colleague of mine had good results using this tool on FRAP images. I programmed a ImageJ tool that can calculate recoveries in FRAP analysis based on those images. You might get some ideas for yourself when looking at the code (see: http://imagejdocu.tudor.lu/doku.php?id=plugin:analysis:frap_normalization:start )

The only way I know you can work with images, is by using EBImage that's contained in the bioconductor system. The package Rimage is orphaned, so is no longer maintained.

To find the shortest distance: once you have the coordinates of the lines and holes, you can go for the shotgun approach : calculate the distances between all points and the line, and then take the minimum. An illustration about that in R :

x <- -100:100
x2 <- seq(-70,-50,length.out=length(x)/4)

a.line <- list(x = x,
               y = 4*x + 5) 

a.hole <- list(
  x = c(x2,rev(x2)),
  y = c(200 + sqrt(100-(x2+60)^2),
        rev(200 - sqrt(100-(x2+60)^2)))
  )

plot(a.line,type='l')
lines(a.hole,col='red')

calc.distance <- function(line,hole){

  mline <- matrix(unlist(line),ncol=2)
  mhole <- matrix(unlist(hole),ncol=2)

  id1 <- rep(1:nrow(mline),nrow(mhole))
  id2 <- rep(1:nrow(mhole), each=nrow(mline))

  min(
    sqrt(
      (mline[id1,1]-mhole[id2,1])^2 + 
      (mline[id1,2]-mhole[id2,2])^2
    )
  )
}

Then :

> calc.distance(a.line,a.hole)
[1] 95.51649

Which you can check mathematically by deriving the equations from the circle and the line. This goes fast enough if you don't have millions of points describing thousands of lines and holes.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!