Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a 2D image as shown here and need to extract the spatial information about the curves in between each cell division. I have been able to analyze the image and output $\;(x,y)\;$ coordinates where the brightest values (1.0) are located in the grid of pixels.

How might I be able to process the image to remove noise (inside the cells) leaving only the lines describing the cell outlines?

enter image description here

share|improve this question
up vote 10 down vote accepted

There are a number of nonlinear filters that are possible. One that might help is the RidgeFilter

ImageAdjust[RidgeFilter[img, 5]]

enter image description here

Let's now clean it up a bit:

Pruning[Thinning[SelectComponents[Binarize[ImageAdjust[RidgeFilter[img, 5]], 0.094], 
        "Count", # > 800 &]]]

enter image description here

The above binarizes the output of the ridge filter. This leaves the desired edges plus some junk in the middle. SelectComponents then removes all the small components, leaving just the desired edges. The result contains the edges but they have become fat; the Thinning function trims them down. The final pruning (as suggested by halirutan) removes a couple of dangling edges.

share|improve this answer
Thank you for the assistance. This is exactly the push I needed! – rjd Nov 26 '13 at 14:38

Common functions you should look at are EdgeDetect, Thinning and Pruning. With the already mentioned RidgeFilter this gives

img = Import[""];
border = Pruning[Thinning@Closing[EdgeDetect[
  ImageAdjust@RidgeFilter[img, 7], 1], 5], 500];
ColorCombine[{img, img, border}]

Mathematica graphics

share|improve this answer
What about doing an initial TotalVariationFiltering with Method->"Poisson"? – UDB Nov 20 '13 at 11:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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