Find tracing/plotting stacked bands/lines in an image I have images with lines/bands, the bands/lines are parallel but can be of different gray levels, I want to extract or trace the lines/bands as single line, all lines/bands are parallel.

Source:

Output Plot:

The source image contain sine wave lines (10 pixels in amplitude) that are stacked on top on of each other forming what looks like bands. I used the location of the max of the cross-correlation of the first column with other columns of the image. 

I am looking for other approaches as cross correlation is too expensive and very sensitive to noise.
Why not try just summing the columns of the image?



Well, you could try smoothing the image first, but that will have the same effect as just smoothing the output.



R code for this is below the first lot.

Here's the extra image, processed.





R Code Below

# 26593
# install.packages("png")

file &lt;- "Q26593_original.png"

library(png)

img &lt;- readPNG(file)

d &lt;- dim(img)

par(mfrow=c(2,1))
plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y")
lim &lt;- par()
rasterImage(img, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])

plot(colSums(img[,,1]), type="l")




R Code #2 Below

# 26593
# install.packages("png")
# install.packages("EBImage") --- Didn't work.
# ## try http if https is not available
# source("http://bioconductor.org/biocLite.R")
# biocLite("EBImage")

file &lt;- "Q26593_original.png"

library(png)
library(EBImage)

img &lt;- readPNG(file)

d &lt;- dim(img)

#xx &lt;- (0:(d[2]-1) - d[2]/2)/d[2]
#yy &lt;- (0:(d[1]-1) - d[1]/2)/d[1]
#sigma &lt;- 0.2

#w &lt;-  exp(-yy*yy/sigma) %*%  t(exp(-xx*xx/sigma)) 
#w1 &lt;- exp(-yy*yy/sigma) %*% t(rep(1,d[2]))

f &lt;- makeBrush(11, shape='disc', step=FALSE)
imgf &lt;- filter2(img, f)
imgf &lt;- imgf/max(imgf)

par(mfrow=c(3,1))
plot(1:2, type='n', main="Filtered Image", xlab="x", ylab="y")
lim &lt;- par()
rasterImage(imgf, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])

#plot(1:2, type='n', main="Window Function", xlab="x", ylab="y")
#lim &lt;- par()
#rasterImage(w1, lim$usr[1], lim$usr[3], lim$usr[2], lim$usr[4])

plot(colSums(imgf[,,1]), type="l", main="Column sum of filtered image")

plot(filter(colSums(img[,,1]), rep(1,11)), type="l", main="Column sum of unfiltered image, filtered")