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

  • $\begingroup$ Please post one (or a few if you can) images without the red label for us to be able to test some approaches $\endgroup$ – Dr. belisarius Apr 4 '13 at 2:33
i = {"http://i.stack.imgur.com/KjTp9.png", 
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

  • $\begingroup$ Oh fantastic! Thank you so much! That's exactly what I wanna achieve $\endgroup$ – zhengbli Apr 4 '13 at 3:14
  • $\begingroup$ I seriously need to learn functional programming. $\endgroup$ – jmlopez Apr 4 '13 at 3:52
  • $\begingroup$ @jmlopez Well, that make us two $\endgroup$ – Dr. belisarius Apr 4 '13 at 3:58
  • $\begingroup$ 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. $\endgroup$ – jmlopez Apr 4 '13 at 4:15
  • 1
    $\begingroup$ @jmlopez Get the book for free here mathematica.stackexchange.com/a/22724/193 ... courtesy of a fellow user :) $\endgroup$ – Dr. belisarius Apr 5 '13 at 2:52

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.