Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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}]
share|improve this question
1  
Does the image needs to be that large? Can another image available online be used so we can all test the code coherently? –  Vitaliy Kaurov Feb 7 at 1:24
    
Here is a version using a smaller image pulled from the web. –  abwatson Feb 7 at 2:24
    
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}] –  abwatson Feb 7 at 2:25

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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