Macro control of Color Balance?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro control of Color Balance?

Bill Mohler
I'm interested in having a macro manipulate the color balance of my image.  I'm getting started by seeing what the Macro Recorder can capture for me.

Below is what I get (with some annotations as to what I've done with the mouse to elicit the recorded lines):

  run("Color Balance...");  // Chose Image>Adjust>Color Balance...

  setMinAndMax(0, 127); //  With Red as the selected color, clicked on Set and changed range to 0-127 before clicking OK in the set dialog

  resetMinAndMax();       //  Switched from Red to Green in the Selector.  The Red Channel changes were retained in the image, and the Min Max Brightness sliders all reset to default positions.

  setMinAndMax(128, 255);  //  With Green as the selected color, clicked on Set and changed range to 128-255 before clicking OK in the set dialog

  resetMinAndMax();      //  Switched from Green to Blue in the Selector.  The Red and Green Channel changes were retained in the image, and the Min Max Brightness sliders all reset to default positions.

  setMinAndMax(200, 255);   //  With Blue as the selected color, clicked on Set and changed range to 200-255 before clicking OK in the set dialog


Something appears to be missing that would make me able to re-enact these actions in a macro.  The step of selecting a color to adjust is never recorded, but it induces the recording of resetMinAndMax();.
Is there any macro command that can let me set the Min and Max on an individual color channel?

Also, once these settings have been made, is there any way to Get the Min and Max settings from the individual color channels in an RGB image?

Many thanks,
Bill
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

Wayne Rasband
> I'm interested in having a macro manipulate the color balance of my
> image.  I'm getting started by seeing what the Macro Recorder can
> capture for me.
>
> Below is what I get (with some annotations as to what I've done with
> the mouse to elicit the recorded lines):
>
>   run("Color Balance...");  // Chose Image>Adjust>Color Balance...
>
>   setMinAndMax(0, 127); //  With Red as the selected color, clicked on
> Set and changed range to 0-127 before clicking OK in the set dialog
>
>   resetMinAndMax();       //  Switched from Red to Green in the
> Selector.  The Red Channel changes were retained in the image, and the
> Min Max Brightness sliders all reset to default positions.
>
>   setMinAndMax(128, 255);  //  With Green as the selected color,
> clicked on Set and changed range to 128-255 before clicking OK in the
> set dialog
>
>   resetMinAndMax();      //  Switched from Green to Blue in the
> Selector.  The Red and Green Channel changes were retained in the
> image, and the Min Max Brightness sliders all reset to default
> positions.
>
>   setMinAndMax(200, 255);   //  With Blue as the selected color,
> clicked on Set and changed range to 200-255 before clicking OK in the
> set dialog
>
>
> Something appears to be missing that would make me able to re-enact
> these actions in a macro.  The step of selecting a color to adjust is
> never recorded, but it induces the recording of resetMinAndMax();.
> Is there any macro command that can let me set the Min and Max on an
> individual color channel?

Convert the RGB image to a 3 channel composite color stack and you will
be able to set the min and max of individual channels. Here is an
example:

   run("Lena (68K)");
   run("Make Composite");
   Stack.setChannel(1);
   setMinAndMax(59, 255);
   Stack.setChannel(2);
   setMinAndMax(0, 225);
   Stack.setChannel(3);
   setMinAndMax(37, 222);

> Also, once these settings have been made, is there any way to Get the
> Min and Max settings from the individual color channels in an RGB
> image?

You can get the min and max settings from the individual channels of a
composite image. Here is an example:

   Stack.setChannel(1);
   getMinAndMax(min, max);
   print("Red: "+min+"-"+max);
   Stack.setChannel(2);
   getMinAndMax(min, max);
   print("Green: "+min+"-"+max);
   Stack.setChannel(3);
   getMinAndMax(min, max);
   print("Blue: "+min+"-"+max);

-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

Bill Mohler
Thanks Wayne.  This will work great on standard RGB images.

...but...

I'm hoping to make changes to and read settings from the current
slice of a RGB virtual stack.  I can do this with Set
Brightness/Contrast and I then have my macro record the user-defined
Min and Max so that it can set the same Min and Max on any other
slice in the RGB VStack that I navigate to.

I was hoping to be able to do the same with Color Balance.  But it
seems the behavior is very different.  Do you or anyone else have any
ideas how to attack this?

Bill

>>I'm interested in having a macro manipulate the color balance of my
>>image.  I'm getting started by seeing what the Macro Recorder can
>>capture for me.
>>
>>Below is what I get (with some annotations as to what I've done
>>with the mouse to elicit the recorded lines):
>>
>>   run("Color Balance...");  // Chose Image>Adjust>Color Balance...
>>
>>   setMinAndMax(0, 127); //  With Red as the selected color, clicked
>>on Set and changed range to 0-127 before clicking OK in the set
>>dialog
>>
>>   resetMinAndMax();       //  Switched from Red to Green in the
>>Selector.  The Red Channel changes were retained in the image, and
>>the Min Max Brightness sliders all reset to default positions.
>>
>>   setMinAndMax(128, 255);  //  With Green as the selected color,
>>clicked on Set and changed range to 128-255 before clicking OK in
>>the set dialog
>>
>>   resetMinAndMax();      //  Switched from Green to Blue in the
>>Selector.  The Red and Green Channel changes were retained in the
>>image, and the Min Max Brightness sliders all reset to default
>>positions.
>>
>>   setMinAndMax(200, 255);   //  With Blue as the selected color,
>>clicked on Set and changed range to 200-255 before clicking OK in
>>the set dialog
>>
>>
>>Something appears to be missing that would make me able to re-enact
>>these actions in a macro.  The step of selecting a color to adjust
>>is never recorded, but it induces the recording of
>>resetMinAndMax();.
>>Is there any macro command that can let me set the Min and Max on
>>an individual color channel?
>
>Convert the RGB image to a 3 channel composite color stack and you
>will be able to set the min and max of individual channels. Here is
>an example:
>
>   run("Lena (68K)");
>   run("Make Composite");
>   Stack.setChannel(1);
>   setMinAndMax(59, 255);
>   Stack.setChannel(2);
>   setMinAndMax(0, 225);
>   Stack.setChannel(3);
>   setMinAndMax(37, 222);
>
>>Also, once these settings have been made, is there any way to Get
>>the Min and Max settings from the individual color channels in an
>>RGB image?
>
>You can get the min and max settings from the individual channels of
>a composite image. Here is an example:
>
>   Stack.setChannel(1);
>   getMinAndMax(min, max);
>   print("Red: "+min+"-"+max);
>   Stack.setChannel(2);
>   getMinAndMax(min, max);
>   print("Green: "+min+"-"+max);
>   Stack.setChannel(3);
>   getMinAndMax(min, max);
>   print("Blue: "+min+"-"+max);
>
>-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

Wayne Rasband
On Dec 4, 2008, at 2:36 PM, Bill Mohler wrote:

> Thanks Wayne.  This will work great on standard RGB images.
>
> ...but...
>
> I'm hoping to make changes to and read settings from the current slice
> of a RGB virtual stack.  I can do this with Set Brightness/Contrast
> and I then have my macro record the user-defined Min and Max so that
> it can set the same Min and Max on any other slice in the RGB VStack
> that I navigate to.
>
> I was hoping to be able to do the same with Color Balance.  But it
> seems the behavior is very different.  Do you or anyone else have any
> ideas how to attack this?

The setMinAndMax() macro function in the 1.42d daily build accepts an
optional third argument that specifies the channel(s) of an RGB image,
where 4=red, 2=green, 1=blue, 6=red+green, etc. Here is an example:

   requires("1.42d")
   run("Lena (68K)");
   setMinAndMax(59, 255, 4);
   setMinAndMax(0, 225, 2);
   setMinAndMax(37, 222, 1);

-wayne

> Bill
>
>>> I'm interested in having a macro manipulate the color balance of my
>>> image.  I'm getting started by seeing what the Macro Recorder can
>>> capture for me.
>>>
>>> Below is what I get (with some annotations as to what I've done with
>>> the mouse to elicit the recorded lines):
>>>
>>>   run("Color Balance...");  // Chose Image>Adjust>Color Balance...
>>>
>>>   setMinAndMax(0, 127); //  With Red as the selected color, clicked
>>> on Set and changed range to 0-127 before clicking OK in the set
>>> dialog
>>>
>>>   resetMinAndMax();       //  Switched from Red to Green in the
>>> Selector.  The Red Channel changes were retained in the image, and
>>> the Min Max Brightness sliders all reset to default positions.
>>>
>>>   setMinAndMax(128, 255);  //  With Green as the selected color,
>>> clicked on Set and changed range to 128-255 before clicking OK in
>>> the set dialog
>>>
>>>   resetMinAndMax();      //  Switched from Green to Blue in the
>>> Selector.  The Red and Green Channel changes were retained in the
>>> image, and the Min Max Brightness sliders all reset to default
>>> positions.
>>>
>>>   setMinAndMax(200, 255);   //  With Blue as the selected color,
>>> clicked on Set and changed range to 200-255 before clicking OK in
>>> the set dialog
>>>
>>>
>>> Something appears to be missing that would make me able to re-enact
>>> these actions in a macro.  The step of selecting a color to adjust
>>> is never recorded, but it induces the recording of
>>> resetMinAndMax();.
>>> Is there any macro command that can let me set the Min and Max on an
>>> individual color channel?
>>
>> Convert the RGB image to a 3 channel composite color stack and you
>> will be able to set the min and max of individual channels. Here is
>> an example:
>>
>>   run("Lena (68K)");
>>   run("Make Composite");
>>   Stack.setChannel(1);
>>   setMinAndMax(59, 255);
>>   Stack.setChannel(2);
>>   setMinAndMax(0, 225);
>>   Stack.setChannel(3);
>>   setMinAndMax(37, 222);
>>
>>> Also, once these settings have been made, is there any way to Get
>>> the Min and Max settings from the individual color channels in an
>>> RGB image?
>>
>> You can get the min and max settings from the individual channels of
>> a composite image. Here is an example:
>>
>>   Stack.setChannel(1);
>>   getMinAndMax(min, max);
>>   print("Red: "+min+"-"+max);
>>   Stack.setChannel(2);
>>   getMinAndMax(min, max);
>>   print("Green: "+min+"-"+max);
>>   Stack.setChannel(3);
>>   getMinAndMax(min, max);
>>   print("Blue: "+min+"-"+max);
>>
>> -wayne
>
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

Bill Mohler
Thanks so much for the quick response!

and... now can we also get similar functionality of getMinAndMax with
different color channels specified by number?

Many thanks,
Bill

>On Dec 4, 2008, at 2:36 PM, Bill Mohler wrote:
>
>>Thanks Wayne.  This will work great on standard RGB images.
>>
>>...but...
>>
>>I'm hoping to make changes to and read settings from the current
>>slice of a RGB virtual stack.  I can do this with Set
>>Brightness/Contrast and I then have my macro record the
>>user-defined Min and Max so that it can set the same Min and Max on
>>any other slice in the RGB VStack that I navigate to.
>>
>>I was hoping to be able to do the same with Color Balance.  But it
>>seems the behavior is very different.  Do you or anyone else have
>>any ideas how to attack this?
>
>The setMinAndMax() macro function in the 1.42d daily build accepts
>an optional third argument that specifies the channel(s) of an RGB
>image, where 4=red, 2=green, 1=blue, 6=red+green, etc. Here is an
>example:
>
>   requires("1.42d")
>   run("Lena (68K)");
>   setMinAndMax(59, 255, 4);
>   setMinAndMax(0, 225, 2);
>   setMinAndMax(37, 222, 1);
>
>-wayne
>
>>Bill
>>
>>>>I'm interested in having a macro manipulate the color balance of
>>>>my image.  I'm getting started by seeing what the Macro Recorder
>>>>can capture for me.
>>>>
>>>>Below is what I get (with some annotations as to what I've done
>>>>with the mouse to elicit the recorded lines):
>>>>
>>>>   run("Color Balance...");  // Chose Image>Adjust>Color Balance...
>>>>
>>>>   setMinAndMax(0, 127); //  With Red as the selected color,
>>>>clicked on Set and changed range to 0-127 before clicking OK in
>>>>the set dialog
>>>>
>>>>   resetMinAndMax();       //  Switched from Red to Green in the
>>>>Selector.  The Red Channel changes were retained in the image,
>>>>and the Min Max Brightness sliders all reset to default positions.
>>>>
>>>>   setMinAndMax(128, 255);  //  With Green as the selected color,
>>>>clicked on Set and changed range to 128-255 before clicking OK in
>>>>the set dialog
>>>>
>>>>   resetMinAndMax();      //  Switched from Green to Blue in the
>>>>Selector.  The Red and Green Channel changes were retained in the
>>>>image, and the Min Max Brightness sliders all reset to default
>>>>positions.
>>>>
>>>>   setMinAndMax(200, 255);   //  With Blue as the selected color,
>>>>clicked on Set and changed range to 200-255 before clicking OK in
>>>>the set dialog
>>>>
>>>>
>>>>Something appears to be missing that would make me able to
>>>>re-enact these actions in a macro.  The step of selecting a color
>>>>to adjust is never recorded, but it induces the recording of
>>>>resetMinAndMax();.
>>>>Is there any macro command that can let me set the Min and Max on
>>>>an individual color channel?
>>>
>>>Convert the RGB image to a 3 channel composite color stack and you
>>>will be able to set the min and max of individual channels. Here
>>>is an example:
>>>
>>>   run("Lena (68K)");
>>>   run("Make Composite");
>>>   Stack.setChannel(1);
>>>   setMinAndMax(59, 255);
>>>   Stack.setChannel(2);
>>>   setMinAndMax(0, 225);
>>>   Stack.setChannel(3);
>>>   setMinAndMax(37, 222);
>>>
>>>>Also, once these settings have been made, is there any way to Get
>>>>the Min and Max settings from the individual color channels in an
>>>>RGB image?
>>>
>>>You can get the min and max settings from the individual channels
>>>of a composite image. Here is an example:
>>>
>>>   Stack.setChannel(1);
>>>   getMinAndMax(min, max);
>>>   print("Red: "+min+"-"+max);
>>>   Stack.setChannel(2);
>>>   getMinAndMax(min, max);
>>>   print("Green: "+min+"-"+max);
>>>   Stack.setChannel(3);
>>>   getMinAndMax(min, max);
>>>   print("Blue: "+min+"-"+max);
>>>
>>>-wayne
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

Wayne Rasband
On Dec 4, 2008, at 6:25 PM, Bill Mohler wrote:

> Thanks so much for the quick response!
>
> and... now can we also get similar functionality of getMinAndMax  
> with different color channels specified by number?

You can use the setRGBWeights() and getStatistics() functions to get  
the minimum and maximum pixel values of individual channels in an RGB  
image. This example does a histogram stretch of the red, green and  
blue channels of the Lena sample image.

    run("Lena (68K)");
    setRGBWeights(1, 0, 0);
    getStatistics(area, mean, min, max);
    print("Red: "+min+"-"+max);
    setMinAndMax(min, max, 4);
    setRGBWeights(0, 1, 0);
    getStatistics(area, mean, min, max);
    print("Green: "+min+"-"+max);
    setMinAndMax(min, max, 2);
    setRGBWeights(0, 0, 1);
    getStatistics(area, mean, min, max);
    print("Blue: "+min+"-"+max);
    setMinAndMax(min, max, 1);

-wayne


>> On Dec 4, 2008, at 2:36 PM, Bill Mohler wrote:
>>
>>> Thanks Wayne.  This will work great on standard RGB images.
>>>
>>> ...but...
>>>
>>> I'm hoping to make changes to and read settings from the current  
>>> slice of a RGB virtual stack.  I can do this with Set Brightness/
>>> Contrast and I then have my macro record the user-defined Min and  
>>> Max so that it can set the same Min and Max on any other slice in  
>>> the RGB VStack that I navigate to.
>>>
>>> I was hoping to be able to do the same with Color Balance.  But  
>>> it seems the behavior is very different.  Do you or anyone else  
>>> have any ideas how to attack this?
>>
>> The setMinAndMax() macro function in the 1.42d daily build accepts  
>> an optional third argument that specifies the channel(s) of an RGB  
>> image, where 4=red, 2=green, 1=blue, 6=red+green, etc. Here is an  
>> example:
>>
>>   requires("1.42d")
>>   run("Lena (68K)");
>>   setMinAndMax(59, 255, 4);
>>   setMinAndMax(0, 225, 2);
>>   setMinAndMax(37, 222, 1);
>>
>> -wayne
>>
>>> Bill
>>>
>>>>> I'm interested in having a macro manipulate the color balance  
>>>>> of my image.  I'm getting started by seeing what the Macro  
>>>>> Recorder can capture for me.
>>>>>
>>>>> Below is what I get (with some annotations as to what I've done  
>>>>> with the mouse to elicit the recorded lines):
>>>>>
>>>>>   run("Color Balance...");  // Chose Image>Adjust>Color Balance...
>>>>>
>>>>>   setMinAndMax(0, 127); //  With Red as the selected color,  
>>>>> clicked on Set and changed range to 0-127 before clicking OK in  
>>>>> the set dialog
>>>>>
>>>>>   resetMinAndMax();       //  Switched from Red to Green in the  
>>>>> Selector.  The Red Channel changes were retained in the image,  
>>>>> and the Min Max Brightness sliders all reset to default positions.
>>>>>
>>>>>   setMinAndMax(128, 255);  //  With Green as the selected  
>>>>> color, clicked on Set and changed range to 128-255 before  
>>>>> clicking OK in the set dialog
>>>>>
>>>>>   resetMinAndMax();      //  Switched from Green to Blue in the  
>>>>> Selector.  The Red and Green Channel changes were retained in  
>>>>> the image, and the Min Max Brightness sliders all reset to  
>>>>> default positions.
>>>>>
>>>>>   setMinAndMax(200, 255);   //  With Blue as the selected  
>>>>> color, clicked on Set and changed range to 200-255 before  
>>>>> clicking OK in the set dialog
>>>>>
>>>>>
>>>>> Something appears to be missing that would make me able to re-
>>>>> enact these actions in a macro.  The step of selecting a color  
>>>>> to adjust is never recorded, but it induces the recording of  
>>>>> resetMinAndMax();.
>>>>> Is there any macro command that can let me set the Min and Max  
>>>>> on an individual color channel?
>>>>
>>>> Convert the RGB image to a 3 channel composite color stack and  
>>>> you will be able to set the min and max of individual channels.  
>>>> Here is an example:
>>>>
>>>>   run("Lena (68K)");
>>>>   run("Make Composite");
>>>>   Stack.setChannel(1);
>>>>   setMinAndMax(59, 255);
>>>>   Stack.setChannel(2);
>>>>   setMinAndMax(0, 225);
>>>>   Stack.setChannel(3);
>>>>   setMinAndMax(37, 222);
>>>>
>>>>> Also, once these settings have been made, is there any way to  
>>>>> Get the Min and Max settings from the individual color channels  
>>>>> in an RGB image?
>>>>
>>>> You can get the min and max settings from the individual  
>>>> channels of a composite image. Here is an example:
>>>>
>>>>   Stack.setChannel(1);
>>>>   getMinAndMax(min, max);
>>>>   print("Red: "+min+"-"+max);
>>>>   Stack.setChannel(2);
>>>>   getMinAndMax(min, max);
>>>>   print("Green: "+min+"-"+max);
>>>>   Stack.setChannel(3);
>>>>   getMinAndMax(min, max);
>>>>   print("Blue: "+min+"-"+max);
>>>>
>>>> -wayne
Reply | Threaded
Open this post in threaded view
|

Re: Macro control of Color Balance?

ChicoCacto94
In reply to this post by Bill Mohler
Hello, Could you fix your problem? I'm trying to do the same macro, but having the same issue and i cannot find the answers to your problem, they were deleted.