2
$\begingroup$

This is probably a very simple thing, but I could not figure it out.

I am trying to create a window were I can display an image while being able to zoom, pan and scroll while adjusting contrast and brightness dynamic way.

In the simplified example below I can have the two parts separately:

img = ExampleData[{"TestImage", "House"}];
sliderC = Slider[Dynamic[c], {-5, 5, .01}, Appearance -> "Labeled"]
sliderB = Slider[Dynamic[b], {-5, 5, .01}, Appearance -> "Labeled"]
adjustedImg = Dynamic[ImageAdjust[img, {c, b}]]
dynamicImg = DynamicImage[img]

But

final = DynamicImage[adjustedImg]

Cannot work because the argument of the function at this point is not an image any more

And if I use Setting to retrieve the image in the dynamic adjusted image, then final2 is not dynamically updated any more

final2 = DynamicImage[Setting[adjustedImg]]

I tried to use Pane instead of DynamicImage, but I could only set scrollbars and not the zoom (and I really need it).

Thank you for the help

$\endgroup$
1

1 Answer 1

2
$\begingroup$

When I tried to do something similar I ended up creating my own version of DynamicImage. It was easier in the end. Here's the code I used, I'm sure it can be easily modified to meet your needs:

DynamicModule[{img2, mag = 1, 
  img = ExampleData[{"TestImage", "House"}], left = 0, right = 0, 
  bottom = 0, top = 0, dim},
 dim = ImageDimensions[img];
 Column[{
   Grid[{
     {"Magnification: ",
      Row[{Button["-", If[mag > .1, mag = mag - .1, mag = .1]], 
        Button["+", If[mag < 2, mag = mag + .1, mag = 2]]}],
      Dynamic[mag]},
     {"Left: ", Slider[Dynamic[left], {0, -dim[[1]]/2 + 1}], 
      Dynamic[left]},
     {"Right: ", Slider[Dynamic[right], {0, -dim[[1]]/2 + 1}], 
      Dynamic[right]},
     {"Top: ", Slider[Dynamic[top], {0, -dim[[2]]/2 + 1}], 
      Dynamic[top]},
     {"Bottom: ", Slider[Dynamic[bottom], {0, -dim[[2]]/2 + 1}], 
      Dynamic[bottom]}
     }],
   Dynamic[img2 = ImagePad[
      Image[img, Magnification -> mag],
      {{left, right}, {bottom, top}}]]
   ,
   Button["Print values", 
    Print["Magnification: " <> ToString[mag] <> "\nDimensions: " <> 
      ToString[ImageDimensions@img2]]]
   }
  , Frame -> True]
 ]
$\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.