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 am learning Mathematica and the Image Processing functions. I have the following Manipulate procedure which works fine:

helix = Import["/Users/dmcleod/imgs/helix_spitzer_720.jpg"];

Manipulate[
 w = ImageAdjust[helix, {contrast, brightness, gamma}],
 {{contrast, 0}, -1, 5, 0.01, Appearance -> "Labeled"},
 {{brightness, 0}, -1, 5, 0.01, Appearance -> "Labeled"},
 {{gamma, 1}, 1, 10, 1, Appearance -> "Labeled"},
 Delimiter,
 "Histogram",
 Dynamic[ImageHistogram[w, Appearance -> "Separated", 
   ImageSize -> 250]],
 ControlPlacement -> Left
 ]

My question is: In addition to ImageAdjust how can I add a slider to perform Sharpen[], and another slider to perform GaussianFilter[]. Both functions (i.e. Sharpen, and GaussianFilter) must update the image helix.

Is this possible? Can someone provide a simple example how to do this? Sorry, I just don't see how to add the additional sliders that call separate functions.

share|improve this question

2 Answers 2

Since I don't have access to your image I'll use the built in ExampleData test image "Lena". The following should accomplish what you want.

helix = ExampleData[{"TestImage", "Lena"}];

Manipulate[
 w = GaussianFilter[
   Sharpen[ImageAdjust[helix, {contrast, brightness, gamma}], 
    sharpen], gfilter], {{contrast, 0}, -1, 5, 0.01, 
  Appearance -> "Labeled"}, {{brightness, 0}, -1, 5, 0.01, 
  Appearance -> "Labeled"}, {{gamma, 1}, 1, 10, 1, 
  Appearance -> "Labeled"}, {{sharpen, 1}, 1, 15, 
  Appearance -> "Labeled"}, {{gfilter, 1}, 1, 15, 
  Appearance -> "Labeled"}, Delimiter, "Histogram", 
 Dynamic[ImageHistogram[w, Appearance -> "Separated", 
   ImageSize -> 250]], ControlPlacement -> Left]

Notice that the functions are added just by nesting them. This could probably be accomplished in a variety of ways but this seems most direct. The added controls are nearly verbatim to the pre-existing ones.

Here is what it produces...

enter image description here

share|improve this answer
    
Thanks Andy!!!!! that did it. I see the light !!!!! thanks again. I have been wrestling with this for some time. –  Dennis McLeod Feb 28 '12 at 3:33

A fully customizable DynamicModule version (using Andy's solution as foundation).

After a certain point into dynamic interactivity, you will realize that Manipulate is often not enough, because what you want to do, cannot be done in Manipulate. The below code shows a general method how to extend Manipulate for specific requirements. I use such DynamicModule constructs almost all the time (heck, I don't even know anymore how to use Manipulate!). It has various advantages over a simple Manipulate, most importantly: it is fully customizable, you can define complex controller-interdependencies, and you can easily update dynamically only those parts that are necessary to be updated, to improve response time.

DynamicModule[{
  contrast, brightness, gamma, sharpen, gauss, size, image, temp, 
  original = ExampleData[{"TestImage", "Lena"}],
  updateImageAdjust, updateSharpen, updateGaussianFilter, reset},
 Panel@Grid[{
    {Style["Image manipulation", FontFamily -> "Times", Italic, 18], 
     SpanFromLeft},
    {Grid[{
       {},
       {Item[Button["Reset", reset[]], Alignment -> Left]},
       {"contrast", 
        Slider[Dynamic[
          contrast, {(contrast = #; updateImageAdjust[]) &, 
           image = temp}], {-1, 10}], Dynamic@contrast},
       {"brightness", 
        Slider[Dynamic[
          brightness, {(brightness = #; updateImageAdjust[]) &, 
           image = temp}], {-1, 10}], Dynamic@brightness},
       {"gamma", 
        Slider[Dynamic[
          gamma, {(gamma = #; updateImageAdjust[]) &, 
           image = temp}], {0.0001, 10}], Dynamic@gamma},
       {"sharpen", 
        Slider[Dynamic[
          sharpen, {(sharpen = #; updateSharpen[]) &, 
           image = temp}], {0, 15}], Dynamic@sharpen},
       {"gaussian blur", 
        Slider[Dynamic[
          gauss, {(gauss = #; updateGaussianFilter[]) &, 
           image = temp}], {0, 15}], Dynamic@gauss},
       {"size", Slider[Dynamic@size, {50, 1000, 1}], Dynamic@size}
       }, Alignment -> {{Right, Left, Left}, Center}, 
      ItemSize -> {{Automatic, Automatic, 4}, Automatic}],
     Panel@Dynamic@Show[temp, ImageSize -> size]
     }}, Alignment -> {Left, Top}],

 Initialization :> (
   reset[] := (temp = image = original; contrast = 0; brightness = 0; 
     gamma = 1; sharpen = 0; gauss = 0; size = 250);
   updateImageAdjust[] := (temp = 
      ImageAdjust[image, {contrast, brightness, gamma}]);
   updateSharpen[] := (temp = Sharpen[image, sharpen]);
   updateGaussianFilter[] := (temp = GaussianFilter[image, gauss]);
   reset[];
   )]

Mathematica graphics

share|improve this answer
    
+1 but Gaussian and sharpen should start at zero, and gamma should be able to go below one. –  Mr.Wizard Feb 28 '12 at 16:46
    
@Mr.Wizard I just copied Andy's values. Updated and fixed some errors, thanks for pointing them out. –  István Zachar Feb 28 '12 at 17:22

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.