I have a picture,and I want to get a special curve in this picture ,than draw the line in a new picture.inbut I can't do this . Like this: example

The picture is this enter image description here

Anybody have an idea?


A complete solution that gives essentially the result you want is the following:

image = Import["http://i.stack.imgur.com/coBQa.jpg"];

img = ImageResize[image, 300];(*scale down to speed up calculation*)
ImageAdjust[img, {4, 0.2}](*increase contrast*)
ColorReplace[%, White -> Black, 0.05](*"remove" the black text*)
MedianFilter[%, 5](*remove small speckles*)
EdgeDetect[%](*find edges*)
SetAlphaChannel[#, Binarize[#]] &[Colorize[MorphologicalComponents[%], 
ColorRules -> {2 -> Red, _ -> Black}]](*Make the right edge red and the rest transparent*)
ImageCompose[img, %](*compose the original image and the red line*)

To get it to work with the full size image you might need to play with the parameters.


enter image description here

  • $\begingroup$ +1, I've added the link, I hope you don't mind :) $\endgroup$
    – Kuba
    Apr 15 '14 at 10:55
  • $\begingroup$ Oh,thank you very much!! $\endgroup$
    – czp
    Apr 15 '14 at 13:09

This method is mainly based on the CurvatureFlowFilter function, which can preserve the shape of the area according to the gradient of the graylevel.

img = Import["http://i.stack.imgur.com/coBQa.jpg"] // ColorConvert[#, "Grayscale"] &;

The threshold of the first Binarize can be determined by checking the graylevel of some sample points of the interested area:

imgBi = Binarize[img, {0.38, 0.48}]


CurvatureFlowFilter is used here to smooth imgBi while keeping the edges relatively unchanged (Note: this function is very time-consuming):

imgSeg = CurvatureFlowFilter[imgBi, 10, 5]


MorphologicalBinarize is useful for excluding small irrelevant areas:

imgMorphBi = MorphologicalBinarize[imgSeg, {.4, .99}]


Use any edge extraction method to extract the edges:

imgEdges = GradientFilter[imgMorphBi, 1] // ImageAdjust // Binarize


HighlightImage[img, imgEdges]

highlighted img

  • $\begingroup$ nice to see use of CurvatureFlowFilter. $\endgroup$
    – s.s.o
    Apr 15 '14 at 18:34
  • $\begingroup$ @s.s.o Thanks. It's a very good function, just a bit slow :( $\endgroup$
    – Silvia
    Apr 16 '14 at 2:40
  • $\begingroup$ A nice answer too.Thank you !! $\endgroup$
    – czp
    Apr 16 '14 at 8:09
  • $\begingroup$ @czp Glad to help :) $\endgroup$
    – Silvia
    Apr 16 '14 at 10:59

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.