1
$\begingroup$

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:source image

Output Plot:plot of the solution

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.

$\endgroup$
  • $\begingroup$ Well, due to the gray scale variations, Have you tried to apply a simple gradient to you image and extract the positions of all values greater than 0 (considering any noise is affecting your image) ? $\endgroup$ – Alexander Leon VI Oct 22 '15 at 15:57
  • $\begingroup$ I tried using a sobel filter (vertically and/or horizontally), but the results is too noisy and I am unable to get rid of the top and bottom edge effects. Also I am not able to isolate a single line. $\endgroup$ – Mohan Baro Oct 22 '15 at 16:22
  • $\begingroup$ Ok, maybe you can smooth the image before apply the sobel filter $\endgroup$ – Alexander Leon VI Oct 22 '15 at 19:04
  • $\begingroup$ I have a question, due to all lines are 'parallel', do you really need all the bands or just one is enough? $\endgroup$ – Alexander Leon VI Oct 23 '15 at 14:28
  • 1
    $\begingroup$ Correlation method seems to be giving the best answer. The simple summation method fails in the presence of noise. $\endgroup$ – Mohan Baro Nov 25 '15 at 18:01
0
$\begingroup$

Why not try just summing the columns of the image?

enter image description here

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

enter image description here

R code for this is below the first lot.

Here's the extra image, processed.

enter image description here


R Code Below

# 26593
# install.packages("png")

file <- "Q26593_original.png"

library(png)

img <- readPNG(file)

d <- dim(img)

par(mfrow=c(2,1))
plot(1:2, type='n', main="Plotting Over an Image", xlab="x", ylab="y")
lim <- 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 <- "Q26593_original.png"

library(png)
library(EBImage)

img <- readPNG(file)

d <- dim(img)

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

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

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

par(mfrow=c(3,1))
plot(1:2, type='n', main="Filtered Image", xlab="x", ylab="y")
lim <- 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 <- 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")
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you @Peter, I had tried the summation and averaging methods, as you have shown it does work at the conceptual level, but the issue is the edge artifacts (kinks in the curve that you have plotted). I believe is coming from the edges (top and bottom boundary). It looks ok with this image, but when I have more complicated source images the summation method fails. I am glad though you also came up with the summation idea. Any suggestions on how I could get rid of the edge artifacts? $\endgroup$ – Mohan Baro Oct 23 '15 at 13:34
  • $\begingroup$ @MohanBaro: Just filter it! :-) $\endgroup$ – Peter K. Oct 23 '15 at 15:24
  • $\begingroup$ Thank you very much @Peter, can you please try this source image imgur.com/D4D0NLm with your R code. I am not familiar with R and I have not gotten around to converting your code. $\endgroup$ – Mohan Baro Oct 23 '15 at 22:07
  • $\begingroup$ @MohanBaro : Done. $\endgroup$ – Peter K. Oct 24 '15 at 0:31
  • 1
    $\begingroup$ Thank you @Peter K, it does seem work good. As soon I complete testing I will post the expect resulted for the source image 2, I was expecting it to have more correspondence with the observed semi-circular curved sections.. $\endgroup$ – Mohan Baro Oct 25 '15 at 5:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.