9
$\begingroup$

I am trying to extract the outer edge of the attached image. Could you please advice me how to do it?

Image

$\endgroup$
  • $\begingroup$ Have you tried anything? Is it about Mathematica at all? $\endgroup$ – Kuba Feb 3 at 14:04
  • $\begingroup$ Yes I have tried it with Mathematica. The problem is that I don't know how to extract the outer contour only. $\endgroup$ – Florin Feb 3 at 14:23
  • 1
    $\begingroup$ @Florin In the future, it would be really great if you could include what you have done, as a code snippet. This is an interesting problem; what is this shape for? Interfaces between liquids? $\endgroup$ – dearN Feb 3 at 16:02
  • $\begingroup$ @Florin If your question has been answered, please consider marking one of the answers as Accepted! $\endgroup$ – Carl Lange Feb 4 at 8:15
  • $\begingroup$ Hi drN! OK! It is indeed an interface. However I am a real beginner. Not yet able to share codes. I am learning the ABC. $\endgroup$ – Florin Feb 7 at 19:24
15
$\begingroup$

Assuming the question is about Mathematica...

SelectComponents[
 MorphologicalPerimeter@MorphologicalBinarize@i, "Count", -2]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you Carl !! Thank you very much! $\endgroup$ – Florin Feb 3 at 14:41
10
$\begingroup$

One method to isolate the outer edge in Mathematica is to use the EdgeDetect[] function.

Note: I hand tuned the program for this image (it will not work for other images).

img = Import["https://i.stack.imgur.com/0wc6Q.jpg"];
EdgeDetect[img, 1, .43] - EdgeDetect[img, 1, .45]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Thank you Conor !! I have tried with EdgeDetect but I did not know about using it this way. Thank you very much! $\endgroup$ – Florin Feb 3 at 14:42
  • 1
    $\begingroup$ @ConorCosnett 👋Always nice to see another Irish Mathematica user! $\endgroup$ – Carl Lange Feb 3 at 14:53
  • $\begingroup$ Haha thanks, unfortunately we are a rare breed. (Everyone seems to be wasting their time, reinventing the wheel, in MATLAB and C in these parts.) $\endgroup$ – Conor Cosnett Feb 3 at 15:49
  • $\begingroup$ @ConorCosnett Tell me about it. If you're in Dublin feel free to give me a shout and we can grab a coffee/pint and chat about how much better us Mathematica users are than our peers 😅 $\endgroup$ – Carl Lange Feb 3 at 16:53
  • $\begingroup$ Certainly. I couldn't turn down an opportunity to do that 😂. $\endgroup$ – Conor Cosnett Feb 3 at 17:45
8
$\begingroup$

An approach that doesn't need too much tweaking is to use LocalAdaptiveBinarize followed by the selection of the largest component:

img = Import["https://i.stack.imgur.com/0wc6Q.jpg"];
object = ColorNegate@DeleteSmallComponents[LocalAdaptiveBinarize[img, 30]]
MorphologicalPerimeter@SelectComponents[object, "Count", -1]

enter image description here

$\endgroup$
  • $\begingroup$ Thank you Bill! Thank you very much! $\endgroup$ – Florin Feb 7 at 19:24

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.