2011-03-06 3 views
1

다음과 같이 단순화 한 이미지 처리 문제를 다루고 있습니다. 세 개의 10x10 행렬이 있는데 각 행마다 각 셀에 1 또는 -1 값이 있습니다. 각 행렬에는 어딘가에이라는 불규칙한 객체가 있으며 행렬에 약간의 노이즈가 있습니다. 나는 그들의 평균을 얻을 수 있도록 객체를 정렬 할 수있는 행렬의 최적 정렬을 찾는 방법을 찾고 싶습니다.시끄러운 이가 진수의 최적 겹침을 찾는 방법

1/-1 코딩의 경우, 곱셈 된 두 셀 사이에 일치가있는 경우 1을, 두 곱한 셀 사이에 일치가있는 경우 요소가있는 곱셈을 사용하면 1을 얻을 수 있습니다. 불일치로 인해 제품의 합이 중첩의 척도가됩니다. 이것으로, 나는 최적의 오버랩을 산출하는 것을 찾기 위해 두 매트릭스의 모든 가능한 정렬을 시도 할 수 있다는 것을 알고 있지만, 3 매트릭스 (또는 그 이상 - 실제로 실제 데이터에서 20+ 이상을 갖는 방법) 세트). 매스 매 티카의 프로그램이 당신이 원하는 않는다는 것입니다 여기에

#set up the 3 matricies 
m1 = c(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1) 
m1 = matrix(m1,10) 

m2 = c(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1) 
m2 = matrix(m2,10) 

m3 = c(-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,1,1,1,1,-1,-1,-1,-1,-1,-1,-1,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1) 
m3 = matrix(m3,10) 

#show the matricies 
image(m1) 
image(m2) 
image(m3) 
#notice there's a "+" shaped object in each 

#create noise 
set.seed(1) 
n1 = sample(c(1,-1),100,replace=T,prob=c(.95,.05)) 
n1 = matrix(n1,10) 
n2 = sample(c(1,-1),100,replace=T,prob=c(.95,.05)) 
n2 = matrix(n2,10) 
n3 = sample(c(1,-1),100,replace=T,prob=c(.95,.05)) 
n3 = matrix(n3,10) 

#add noise to the matricies 
mn1 = m1*n1 
mn2 = m2*n2 
mn3 = m3*n3 

#show the noisy matricies 
image(mn1) 
image(mn2) 
image(mn3) 

답변

1

: 문제를 명확히하는 데 도움하려면

, 여기에 내가 다루고있어 matricies의 종류를 설정 R에 기록 된 일부 코드이다 (나는 생각한다).

필요한 경우 자세히 설명해 드리겠습니다.

(*define temp tables*) 
r = m = Table[{}, {100}]; 
(*define noise function*) 
noise := Partition[RandomVariate[BinomialDistribution[1, .05], 100], 
    10]; 
For[i = 1, i <= 100, i++, 
(*generate 100 10x10 matrices with the random cross and noise added*) 
w = RandomInteger[6]; h = w = RandomInteger[6]; 
m[[i]] = (ArrayPad[CrossMatrix[4, 4], {{w, 6 - w}, {h, 6 - h}}] + 
    noise) /. 2 -> 1; 

(*Select connected components in each matrix and keep only the biggest*) 
id = [email protected] 
    Commonest[ 
    [email protected](mf = 
     MorphologicalComponents[m[[i]], CornerNeighbors -> False]), 2]; 
d = mf /. {id -> x, x_Integer -> 0} /. {x -> 1}; 
{minX, maxX, minY, maxY} = 
    {[email protected][g[#]] /. g -> First, 
    [email protected][g[#]] /. g -> First, 
    [email protected][g[#]] /. g -> Last, 
    [email protected][g[#]] /. g -> Last} &@Position[d, 1]; 

(*Trim the image of the biggest component *) 
r[[i]] = d[[minX ;; maxX, minY ;; maxY]]; 
] 
(*As the noise is low, the more repeated component is the image*) 
MatrixPlot @@ [email protected] 

결과 :

enter image description here