2016-11-15 47 views
0

我想獲得一個協變量圖,以便計算它的一些值。這是以前完成的工作; Quantitative Analysis of Banded Structures in Dual-Phase SteelsR中的二值圖像的協變量方法

只要閱讀第2頁,就足以瞭解該方法。

有用於示出本文件中的方法如下圖像: Covariogram

可以看到,作者在上圖中的實施例中使用的圖像,則它們獲得的曲線圖。

這裏是我使用的,作爲二進制圖像的圖像:我只想用我的形象,以獲得劇情 My Image

代碼:

setwd(".../Project/R/Workspace/Task1") 
library("EBImage", lib.loc="~/R/win-library/3.2") 
img <- readImage(".../Project/Beispielbilder/example.jpg") 
display(img, title='Image') 
M <- img_ithr 
plot(cov(M),xlim=c(0,1), ylim=c(0,300)) 

謝謝您的幫助和時間的人。

回答

1

根據您的示例文件和論文中的描述,我想出了以下內容。

library("EBImage") 

img <- readImage("https://i.stack.imgur.com/YMBQO.jpg") 

## discard color channels by collapsing to grayscale, and binarize 
bin <- channel(img, "gray") > .5 

## function calculating the overlap between the original structure 
## and the structure shifted by a vector v 
C <- function(img, v) { 
    sum(img & translate(img, v))/prod(dim(img)[1:2]-v) 
} 

h <- 1:300 

## horizontal 
C_h <- sapply(h, function(h) C(bin, c(h, 0))) 

## vertical 
C_v <- sapply(h, function(h) C(bin, c(0, h))) 

matplot(h, cbind(C_h, C_v), xlim = range(h), ylim = range(C_h, C_v), 
     ylab = "C", col = c("red", "blue"), type = "l", lty = 1) 

enter image description here

協方差在兩個垂直方向上單獨地測量。不過,我不確定在紙上的圖中如何考慮方向β

+0

謝謝您的回答!藍線是我需要檢查的垂直線。在那之後,我應該找到最大最小點並對它進行一些數學運算。 – EMI