4
$\begingroup$

As shown in the picture, i want to know if it is possible to:

1) recognize the feature edge like face,nose,eyes,mouse,etc.

2) highlight the feature edge with draggable select lasso,

3) return the coordinates of each pixel lies on the lasso after the user finish dragging some of the lasso points.

Put the first part aside, Suppose i've got the points along the feature edge, how can I get a lasso selection connecting all the points together? And if I drag some of the points,leaving others fixed, how can I get all the new coordinates?

Any help would be greatly appreciated.

enter image description here

$\endgroup$

2 Answers 2

6
$\begingroup$

In Version 9, the second part of your question can be done using the FrontEnd ImageEditor tools which includes a Lasso Selection Tool.

img = ExampleData[{"TestImage", "Lena"}]

enter image description here

enter image description here

Copy the selected part:

enter image description here

and Paste in new cell:

enter image description here


You can also use the GetCoordinates tool available on the right-click menu:

enter image description here

enter image description here

Ctrl+V to paste:

enter image description here

$\endgroup$
5
  • $\begingroup$ (+1) As I understand, you have re-created the contour of the selection by the GetCoordinates tool for copying the coordinates. Is it possible to copy the coordinates of the original lasso selection? $\endgroup$ Sep 27, 2014 at 16:35
  • $\begingroup$ @Alexey, good question; i can't think of a way off the top of my head. Lasso selection tool does display coordinates, pixel values and indices, but it seems that copying works only for the selected image part. So to get the coordinates/indices/pixel values i had to use GetCoordinates; but then the draggable lasso selection is lost. $\endgroup$
    – kglr
    Sep 27, 2014 at 17:05
  • $\begingroup$ I think it should be possible because the lasso selection (at least in v10) persists even after deselecting the image: selecting the image again and choosing the lasso selection tool shows the previous selection. Initially I expected that right-clicking on the selection and choosing GetCoordinates should allow to copy the coordinates of the selection, but currently it does not do this. $\endgroup$ Sep 27, 2014 at 18:01
  • $\begingroup$ Maybe I did not clearly describe my demand. Suppose i've got the points along the feature edge, how can I get a lasso selection connecting all the points together? And if I drag some of the points,leaving others fixed, how can I get all the new coordinates? $\endgroup$
    – xibinke
    Sep 28, 2014 at 15:48
  • $\begingroup$ @xibinke, you question is clear enough:) I don't know if part 3 of your question can be done within the functionality exposed in the two interactive tools. Maybe you can use DrawingTools (also available in the right-click menu) which has a free-hand tool similar to the lasso selection tool. It allows access to individual points to drag them around; but i could not figure out know how delete selected points from a collection. $\endgroup$
    – kglr
    Sep 28, 2014 at 16:15
0
$\begingroup$

This is the "first part" of a programmatic lasso selection. At the click of the mouse, it Selects a contiguous region of a color given by the mouse position (within a selectable tolerance).

Not a serious implementation, just an experiment.

i = ImageResize[ExampleData[{"TestImage", "Lena"}], 250];

mask[i_, pt_] := If[pt == {0, 0}, Image[0 ImageData[i]], 
                    ReplacePixelValue[Image[0 ImageData[i]], pt -> RGBColor[1, 1, 1]]]
DynamicModule[{pt = {0, 0}, x = 0.5},
 Column@
  {Row@{ "Tolerance ", Slider[Dynamic[x]], Dynamic@x, 
          Button["Reset", pt = {0, 0}]},
          ClickPane[
               Dynamic@ImageAdd[i, 
                              ColorNegate@ ColorReplace[ ColorConvert[
                              Opening[ColorNegate@RegionBinarize[i, mask[i, pt], x], DiskMatrix[4]], 
                                                                    "RGB"], Black -> Red]],
               (pt = #) &]}]

Mathematica graphics

Some captured results

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.