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 am trying to search for the black areas along a line (the horizontal line shown below). Though it is straight in this picture, it could be of irregular shape in other cases. It seems that the ImageTake function can only take rectangle areas. Can anyone tell me how to limit the processing within the line neighborhood area, and mark the black area in the left part?

enter image description here

Update: Several raw images without red marks: enter image description here enter image description here enter image description here

Update2: Other cases with bigger black area somewhere else enter image description here

share|improve this question
Please post one (or a few if you can) images without the red label for us to be able to test some approaches – Dr. belisarius Apr 4 '13 at 2:33
up vote 18 down vote accepted
i = {"", 
i1 = Import /@ i;

i2 = ColorNegate /@ Binarize /@ i1;

m = Dilation[#, 10]&/@ (Binarize[#, .8]&/@ ImageAdjust/@ DistanceTransform /@ i2);

Grid@{i1, ColorCombine[ {#1, #1, #2}] & @@@ Transpose[{i1, m}]}

Mathematica graphics

share|improve this answer
Oh fantastic! Thank you so much! That's exactly what I wanna achieve – zhengbli Apr 4 '13 at 3:14
I seriously need to learn functional programming. – jmlopez Apr 4 '13 at 3:52
@jmlopez Well, that make us two – Dr. belisarius Apr 4 '13 at 3:58
I've been trying to get a book on this (Power Programming With Mathematica) but I just can't find it. I guess I'll just learn by reading all the clever answers in here. – jmlopez Apr 4 '13 at 4:15
@jmlopez Get the book for free here ... courtesy of a fellow user :) – Dr. belisarius Apr 5 '13 at 2:52

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.