5
$\begingroup$

I have read earlier discussions of changing Locator appearance in Manipulate. I would like to change the rendered size of the locator object based on one of the manipulate variables. I can't get anything to work.

Here is an attempt. source is an image, with dimensions {3716,3449}

isize = 240;
dim = ImageDimensions[source]
height = dim[[2]];
Manipulate[(
  locator = 
   Graphics[{Red, FaceForm[Opacity[.1]], 
     EdgeForm[Directive[Thin, Red]], Rectangle[]}, 
    ImageSize -> (isize size/height)];
  sub = ImageTake[source, height - (pt[[2]] - {0, size - 1}), 
    pt[[1]] + {0, size - 1}];
  Row[{Image[source, ImageSize -> isize], 
    Image[sub, ImageSize -> isize]}])
 , {{pt, {820, 1810}}, Locator, Appearance -> locator}
 , {{size, 100}, 10, 1000}]
$\endgroup$
  • 1
    $\begingroup$ Does the image needs to be that large? Can another image available online be used so we can all test the code coherently? $\endgroup$ – Vitaliy Kaurov Feb 7 '14 at 1:24
  • $\begingroup$ Here is a version using a smaller image pulled from the web. $\endgroup$ – abwatson Feb 7 '14 at 2:24
  • $\begingroup$ source = ColorConvert[ Import["vision.arc.nasa.gov/images/otto_shade_award3.jpg"], "GrayScale"]; isize = 240; {width, height} = ImageDimensions[source]; Manipulate[( locator = Graphics[{Red, FaceForm[Opacity[.1]], EdgeForm[Directive[Thin, Red]], Rectangle[]}, ImageSize -> (isize size/height)]; sub = ImageTake[source, height - (pt[[2]] - {0, size - 1}), pt[[1]] + {0, size - 1}]; Row[{Image[source, ImageSize -> isize], Image[sub, ImageSize -> isize]}]) , {{pt, {100, 100}}, Locator, Appearance -> locator} , {{size, 30}, 1, 30}] $\endgroup$ – abwatson Feb 7 '14 at 2:25
8
$\begingroup$

In this implementation, the function locator[x] takes the slider value as input. You can move the red box around as a locator and change its size with the slider.

source = Import["ExampleData/rose.gif"]; 
locator[x_] := SetAlphaChannel[Image[Graphics[{Red, Rectangle[]}], ImageSize -> 10 x], 0.2];
Manipulate[Image[source, ImageSize -> 500], 
 {{pt, {100, 100}}, Locator, Appearance -> locator[size]}, {{size, 10}, 1, 30}]

enter image description here

The opacity is done by setting the alpha channel in an image created from the red rectangle rather than by using the opacity command in the Graphics command.

$\endgroup$

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.