1
$\begingroup$

I would like to ask you if it is possible to get the coordinates or a couple of numbers that can give me the positions of the highlights points (selected using HighlightImage function) in an image. I know that there is the possibility to select "get coordinates" by clicking on the image, but I am looking for something that can automate the selection/generation of the points and can remove the image once selected the highlights. It would be great if the border could be selected (at least the most external points where the shape 'changes').

Any suggestion will be welcomed.

enter image description here

$\endgroup$
  • 1
    $\begingroup$ What is a highlighted point? $\endgroup$ – C. E. Sep 22 '19 at 18:57
  • $\begingroup$ I am using the HighlightImage function. This function should select specified regions of interest by dots. $\endgroup$ – Val Sep 22 '19 at 19:01
  • $\begingroup$ Right/click on the image and choose "Get coordinates" from the drop/down menu. Then determine the coordinates of the highlighted points. $\endgroup$ – Alexei Boulbitch Sep 22 '19 at 19:08
  • $\begingroup$ Thanks Alexei. I know that there is this possibility, but I would like to take only the highlights without using the tool, but a function. $\endgroup$ – Val Sep 22 '19 at 19:11
  • 1
    $\begingroup$ As always, some example data is necessary here. Please. $\endgroup$ – Henrik Schumacher Sep 22 '19 at 19:20
3
$\begingroup$

If you used HighlightImage, then you should be able to extract the points directly.

Using the first example in HighlightImage (and the more robust code from @kglr):

points = Cases[HighlightImage[i, ImageCorners[i, 1, .001, 5]], Point[x_]:>x
(* {{84.5, 75.5}, {116.5, 68.5}, {141.5, 112.5}, {104.5, 86.5}, {154.5, 87.5}, 
    {79.5, 61.5}, {157.5, 78.5}, {163.5, 87.5}, {108.5, 75.5}, {113.5, 44.5},
    {107.5, 39.5}, {94.5, 81.5}, {157.5, 41.5}, {77.5, 67.5}, {147.5, 49.5}, 
    {145.5, 31.5}, {81.5, 48.5}, {167.5, 69.5}, {97.5, 62.5}, {142.5, 96.5},
    {114.5, 59.5}, {48.5, 18.5}, {36.5, 78.5}, {61.5, 110.5}, {92.5, 51.5},
    {74.5, 6.5}, {46.5, 27.5}, {127.5, 15.5}, {133.5, 118.5}, {39.5, 46.5}, 
    {130.5, 3.5}, {33.5, 68.5}, {102.5, 127.5}, {67.5, 21.5}, {138.5, 33.5},
    {128.5, 22.5}, {149.5, 80.5}, {105.5, 112.5}, {146.5, 103.5}, {72.5, 105.5},
    {82.5, 99.5}, {87.5, 124.5}, {163.5, 34.5}, {87.5, 108.5}, {139.5, 19.5}, 
    {61.5, 32.5}, {112.5, 3.5}, {75.5, 121.5}, {132.5, 107.5}, {75.5, 114.5}, 
    {111.5, 116.5}, {53.5, 25.5}, {87.5, 44.5}, {74.5, 87.5}, {149.5, 73.5}, 
    {154.5, 20.5}, {93.5, 107.5}, {41.5, 64.5}, {44.5, 96.5}, {112.5, 14.5},
    {82.5, 1.5}, {33.5, 59.5}, {56.5, 16.5}, {69.5, 50.5}, {82.5, 13.5},
    {91.5, 27.5}, {67.5, 95.5}, {50.5, 38.5}, {55.5, 101.5}, {63.5, 4.5}, 
    {62.5, 60.5}, {117.5, 123.5}, {62.5, 44.5}, {81.5, 23.5}, {61.5, 66.5},
    {122.5, 53.5}} *)

Show[i, ListPlot[points, PlotStyle -> Red]]

Points in image

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ slightly shorter: points=Cases[HighlightImage[i, ImageCorners[i, 1, .001, 5]], Point[x_]:>x, All][[1]]; $\endgroup$ – kglr Sep 23 '19 at 4:09
  • $\begingroup$ @kglr Thanks! I have some mental block about understanding Cases and patterns no matter how many times I read the documentation so I end up attempting figuring out what Part it is I'm trying to grab. $\endgroup$ – JimB Sep 23 '19 at 4:29
  • $\begingroup$ Thank you to both! Wow! Finally it works! I have a question for you, if I may ask: if the number of points that I wanted to use was fixed, how could I change the HighlightImage function? I thought using ImageCorners[i, MaxFeatures -> 30] but it is wrong $\endgroup$ – Val Sep 23 '19 at 16:56
  • $\begingroup$ You'll need to ask that as a separate specific question. I have no idea about that. $\endgroup$ – JimB Sep 23 '19 at 17:00
  • $\begingroup$ Ok. Thanks JimB $\endgroup$ – Val Sep 23 '19 at 18:26

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.