i trying apply mathematical morphology operation on binary image. operation trying apply dilation. posting code below.
# dilation of square size a. reference (1,1) # mm_dilationsqr <- function(a,a){ c <- if(a<=1) return(c) for(i in 1:a) for(j in 1:a) { b <- mm_translation(a,1-i,1-j) c <- mm_union(c,b) } c <- mm_translation(c,a/2,a/2) return(c) }
the above dilation function calls translation , union functions posted below.
# translation of set x,y. # warning: no periodicity, watch borders! # mm_translation <- function(a,x,y){ c <- mm_zero() if((x>=-m+1) & (x<=m) & (y>=-n+1) & (y<=n)) { for(i in 1:m) for(j in 1:n) { if((i+x>=0) & (i+x<=m) & (j+y>=0) & (j+y<=n)) c[i+x,j+y] <- a[i,j] } } return(c) }
union function below:
# union (or) of sets , b # mm_union <- function(a,b){ c<-as.integer(a|b) dim(c) <- c(m,n) return(c) }
now when trying process image in array form using mm_dilation function, getting error: error in mm_union(c, b) : binary operation on non-conformable arrays
. array dimensions
dim(ta) [1] 745 691
when using subset of above given ta array of dimension given below, code working in case.
dim(a) [1] 21 21
so want know how can improve can process image of ta
dimensions.