algorithm - How to find optimal overlap of noisy bivalent matricies -


i'm dealing image processing problem i've simplified follows. have 3 10x10 matrices, each values 1 or -1 in each cell. each matrix has irregular object located somewhere, , there noise in matrix. i'd figure out how find optimal alignment of matrices let me line objects can average.

with 1/-1 coding, know product of 2 matrices (using element-wise multiplication, not matrix multiplication) yield 1 if there match between 2 multiplied cells , -1 if there mismatch, sum of products yields measure of overlap. this, know can try out possible alignments of 2 matrices find yields optimal overlap, i'm not sure how 3 matrices (or more - have 20+ in actual data set).

to clarify problem, here code, written in r, sets sort of matricies i'm dealing with:

#set 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 matricies image(m1) image(m2) image(m3) #notice there's "+" 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 matricies mn1 = m1*n1 mn2 = m2*n2 mn3 = m3*n3  #show noisy matricies image(mn1) image(mn2) image(mn3) 

here program in mathematica want (i think).

i may explain in more detail, if need.

(*define temp tables*) r = m = table[{}, {100}]; (*define noise function*) noise := partition[randomvariate[binomialdistribution[1, .05], 100],     10]; for[i = 1, <= 100, i++,  (*generate 100 10x10 matrices random cross , 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 , keep biggest*)  id = last@    commonest[     flatten@(mf =         morphologicalcomponents[m[[i]], cornerneighbors -> false]), 2];  d = mf /. {id -> x, x_integer -> 0} /. {x -> 1};  {minx, maxx, miny, maxy} =   {min@thread[g[#]] /. g -> first,      max@thread[g[#]] /. g -> first,      min@thread[g[#]] /. g -> last,      max@thread[g[#]] /. g -> last} &@position[d, 1];   (*trim image of biggest component *)  r[[i]] = d[[minx ;; maxx, miny ;; maxy]];  ] (*as noise low, more repeated component image*) matrixplot @@ commonest@r   

result:

enter image description here


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -