I am trying to extract the outer edge of the attached image. Could you please advice me how to do it?
-
$\begingroup$ Have you tried anything? Is it about Mathematica at all? $\endgroup$– Kuba ♦Feb 3, 2019 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$– FlorinFeb 3, 2019 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$– dearNFeb 3, 2019 at 16:02
-
$\begingroup$ @Florin If your question has been answered, please consider marking one of the answers as Accepted! $\endgroup$– Carl LangeFeb 4, 2019 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$– FlorinFeb 7, 2019 at 19:24
3 Answers
Assuming the question is about Mathematica...
SelectComponents[
MorphologicalPerimeter@MorphologicalBinarize@i, "Count", -2]
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]
-
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$– FlorinFeb 3, 2019 at 14:42
-
1$\begingroup$ @ConorCosnett 👋Always nice to see another Irish Mathematica user! $\endgroup$ Feb 3, 2019 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$– conorFeb 3, 2019 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$ Feb 3, 2019 at 16:53
-
$\begingroup$ Certainly. I couldn't turn down an opportunity to do that 😂. $\endgroup$– conorFeb 3, 2019 at 17:45
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]