2

So I got some kind of cross section picture in jpg format I want to work with. For better understanding I just drew a picture, hopefully symbolising well enough kinda how the real pictures will look like:

enter image description here

At the top of the picture is material A, at the bottom material B.

Goal: I want to get the Pixels of the boundary line between both materials.

My way so far:

  • I already know how to read pictures with package called EBImage
  • I also know, that this will result in a matrix with a color value for every pixel.
  • I thought it would be better to convert the jpeg into a binary picture with only black and white colors.
  • I thought filling up the black part below (Material B) and reducing the noise would be nice, so I could use column sums (a sum of 1's) to find the row number where material A touches material B, which should be my searched boundary line (right?).

Problems:

  • I don't find filters which fill up the black parts intelligently, in the real pictures, there will be much more noise, which will complicate things even further...
  • I am not sure if all this is even necessary, and there is a more efficient way to reach my goal of finding the boundary line

Thank you very much for every tip in advance!

jbaums
  • 27,115
  • 5
  • 79
  • 119
Mmadsen
  • 21
  • 1

2 Answers2

1

Answers will always be vague when there's no example to work with. I would normally use ImageJ for a task like this but EBImage has the commands that I would use.

From EBImage I would make binary and then erode , dilate, and fill holes (fillHull).

Michael_A
  • 488
  • 1
  • 5
  • 17
  • I do not have the data yet, so it is also vague for me. I am just doing some preperation work. I tried: kern = makeBrush(10, shape='diamond') x= erode(x, kern) x= dilate(x, kern) display(x) and it already gave me a very good output for my self drawn picture. I havent even used the fillHull yet. z=c(320-rowSums(x)) plot (z) gave me what i wanted. Hopefully this will work as expected with the real data once i get it. Thank you very much for the help, i am going to try the svm approach from @Greg Snow to see how well it will work :) – Mmadsen Oct 28 '14 at 22:59
0

Your picture looks like it might be a candidate for a support vector machine. There are a couple of packages for R with svm functions, one is e1071.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110
  • I just tried to run the unedited code from the package description of the svm function on the binary picture too see what happens: svm=svm(x, y = NULL, scale = TRUE, type = NULL, kernel = "radial", degree = 3, gamma = if (is.vector(x)) 1 else 1 / ncol(x), coef0 = 0, cost = 1, nu = 0.5, class.weights = NULL, cachesize = 40, tolerance = 0.001, epsilon = 0.1, shrinking = TRUE, cross = 0, probability = FALSE, fitted = TRUE, subset, na.action = na.omit) suprisingly works but object svm after it is a "list of 30", since i want a vector which is the boundary line, what is this list auf 30?! – Mmadsen Oct 28 '14 at 22:05
  • ok: i guess you get suporting vectors which are some of the searched pixels and then you have to decide which method you wanna use to "connect the dots" right?! – Mmadsen Oct 28 '14 at 23:29
  • @Mmadsen, the `xspline` function may be of use for connecting the dots, at least for graphing. Finding a functional form of the line that connects will require thought about what functional forms you are willing to work with. – Greg Snow Oct 29 '14 at 15:55