How to make colormix by script

Viewed 33

I would like to create a colormix image. I can use RGB function to quick create the stack, for example:

image NormRGB(image src){
    image dst := src.ImageClone()
    dst -= min(dst)
    dst /= max(dst)
    dst *= 255
    
    return dst
}
image img1, img2, img3
string title = "Create RGB stack"
string prompt = "Please select three images."
if ( !GetThreeLabeledImagesWithPrompt( prompt, title, "R : ", img1, "G : ", img2, "B : ", img3 ) )
Throw( "User pressed cancel." )

number d10, d11, d20, d21, d30, d31
img1.ImageGetDimensionSizes(d10, d11)
img2.ImageGetDimensionSizes(d20, d21)
img3.ImageGetDimensionSizes(d30, d31)
if (!((d10==d20)*(d20==d30))*((d11==d21)*(d21==d31)))
Throw( "Dimensions are not matched." )

rgbimage myImage := RGBImage( "RGB Stack", 4, d10, d11 )
myImage = rgb( NormRGB(img1), NormRGB(img2), NormRGB(img3))
ShowImage( myImage )

However, the gamma setting and contrast limit will be loss? Is there a colormix function in dm-script?

enter image description here

1 Answers

No there is no supported colormix script functionality and all RGB math needs to be performed explicitly in the manner you have described in your example. If you would like to preserver gamma/contrast settings you would also have to compute the values yourself using the according equations. The RGB image is always just a three-channel 0-255 integer value image.

The contrast/gamma settings of an image display are accessible per script:

imageDisplay disp = GetFrontImage().ImageGetImageDisplay(0)
number b,c,g
disp.ImageDisplayGetContrastParameters(b,c)
g = disp.ImageDisplayGetGammaCorrection()
Result("\n Contrast  : " + c )
Result("\n Brightness: " + b )
Result("\n Gamma     : " + g )

However, the Colormix functionality of GMS does not take brightness/contrast/gamma settings of the source image display into account at all. Instead, a custom brightness/contrast setting (applied via the ColorMix UI) is used. (No gamma). These values are the ones you see serialized in the meta data tags of your screenshot.

There is one unofficial / unsupported script command related to colormix, though: It lets you take a taggroup like the one stored in the ColorMix RGB images and compute a new RGB image from it, i.e.

// Assuming the front-image is a valid RGB image
GetFrontImage().ImageGetTaggroup().CMIXCreateRGBFromTag().ShowImage()

Thus, you could build or modify such a taggroup to mimick the UI behavior.

Related