MKScripts for PixInsight

MK Colorize by Mask

  • Version 1.0
  • Runs in PixInsight

Tint an image through a mask with blend modes, opacity, split toning and luminance protection.

MK Colorize by Mask applies a chosen color to an image, restricted by an optional mask. Choose a blend mode and opacity, optionally map different colors to highlights and shadows with split toning, and protect the original brightness of your image with luminance preservation. The result is created as a new image, leaving the target untouched.

At a glance

  • Optional mask image to restrict where color is applied
  • Five blend modes: Multiply, Screen, Overlay, Linear Dodge and Normal
  • Blend opacity control
  • Split toning with separate highlight and shadow colors
  • Preserve Original Luminance option
  • HSV color picker with numeric RGB entry
  • Live preview with zoom, pan and a Ctrl+click before/after toggle
  • Preview-only auto-stretch for linear data and a Compact UI option
  • Adjustable render delay for large images
Current version
1.0
Menu
Script › MK Scripts › Colorize by Mask
Installed from
https://mhkastro.github.io/MKScripts/
Author
Mohammed Khalifa

The script window

The MK Colorize by Mask window with the target and mask images selected, a color picker set to orange, blend controls and the colorized preview of a nebula. (opens a larger version)
MK Colorize by Mask: pick a color and blend mode, then check the preview before applying.

Installation

Repository URL https://mhkastro.github.io/MKScripts/
  1. Open Manage Repositories. In PixInsight, choose Resources → Updates → Manage Repositories.
  2. Add the MKScripts repository. Click Add, paste the repository URL into the box and confirm.
  3. Check for updates. Choose Resources → Updates → Check for Updates and select the MKScripts packages you want.
  4. Exit PixInsight to install. The update is installed when you exit PixInsight, which then restarts automatically.

Full instructions: Installing MKScripts in PixInsight.

What the tool does#

MK Colorize by Mask applies a chosen color to an image. An optional mask restricts where the color goes. You choose how the color combines with the image (the blend mode) and how strongly (the blend opacity). Two further options are available:

  • Split toning, which maps one color to the highlights and another to the shadows.
  • Preserve Original Luminance, which keeps the image's original brightness and changes only its color.

The script always creates the result as a new image named Colorized_Image. The target image is never modified.

When to use it#

  • To add or strengthen a tint in one part of an image, through a mask, for example one made with MK Color Range Selection.
  • To give a monochrome image a color tint. A grayscale target produces an RGB result.
  • To apply a gentle overall tint. With Mask Image set to <None>, the color is applied evenly at the chosen opacity.

Requirements and input preparation#

  • PixInsight 1.9.4 or a later 1.9.x version.
  • At least one open image. Otherwise the script stops with the message "Please open at least one image to use the Colorize by Mask script."
  • Optional mask. A grayscale or RGB image with the same dimensions as the target. For an RGB mask, the script uses the average of its three channels. White areas receive the full effect and black areas none.
  • Linear data. Tick Auto-Stretch Previews to see linear images. This option changes only the preview; the result is always calculated from the actual image data.

Installation and launch#

  1. Install MKScripts from the repository: in PixInsight choose Resources → Updates → Manage Repositories → Add, paste https://mhkastro.github.io/MKScripts/, then run Resources → Updates → Check for Updates. Full steps: Installing MKScripts in PixInsight.
  2. Open the target image and, if you are using one, the mask image.
  3. Choose Script › MK Scripts › Colorize by Mask.

Basic workflow#

  1. Choose the images. Select the image to colorize in Target Image, then select a mask in Mask Image. If an open image's name contains "mask" (case does not matter), the first such image is preselected; otherwise the list starts at <None>.
  2. Stretch the preview if needed. For linear data, tick Auto-Stretch Previews (STF for Linear Data).
  3. Pick a color. Click the hue strip on the right of the color picker, then click in the large square to set saturation (left to right) and brightness (bottom to top). You can also type values from 0 to 255 in the R, G and B boxes.
  4. Choose how the color blends. Pick a Blend Mode and set Blend Opacity with the slider. The default is 20 %.
  5. Optional refinements. Tick Preserve Original Luminance to keep the original brightness. Tick Enable Split-Toning to pick separate highlight and shadow colors.
  6. Check the preview. Use the mouse wheel to zoom, drag to pan, double-click to fit, and hold Ctrl while clicking to switch between the colorized preview and the original.
  7. Create the result. Click Apply Color. A new RGB image named Colorized_Image opens.

Controls#

Images and display#

Control Default What it does
Target Image First open image The image to colorize. Changing it rebuilds the working copies and the preview.
Mask Image First image whose name contains "mask", otherwise <None> Restricts the color to the white areas of the mask. <None> applies it evenly to the whole image.
Auto-Stretch Previews (STF for Linear Data) Off Applies a temporary automatic stretch to the preview only.
Compact UI Off Reduces the maximum preview size from 850 to 550 pixels for smaller screens.

Color pickers#

Control Default What it does
Main Color Red (255, 0, 0) The color applied to the image. Its title changes to Highlight Color when split toning is on.
Shadow Color Blue (0, 0, 255) The shadow color for split toning. It appears only when Enable Split-Toning is ticked.
R, G, B boxes — Exact color values from 0 to 255. Values outside the range are clamped, and invalid entries become 0. The picker updates to match.

Blend Controls#

Control Range Default What it does
Blend Mode — Multiply How the color combines with the image (see the table below).
Blend Opacity 0–100 % 20 % Strength of the effect. Use the slider: in version 1.0, typing a value in the box next to it has no effect.
Render Delay 0.0–1.0 s 0.5 s Waiting time after a change before the preview is recalculated. Higher values keep the dialog responsive with large images.
Preserve Original Luminance Off Multiplies the colorized result by the ratio of the original lightness to the new lightness (CIE L*). Brightness stays close to the original, and the change is mainly in hue and saturation.
Enable Split-Toning (Highlights vs Shadows) Off Blends the highlight and shadow colors according to each pixel's lightness in the original image. Bright areas receive mostly the highlight color; dark areas mostly the shadow color.

Blend modes#

The formulas apply to each color channel, with values between 0 and 1.

Mode Formula (image a, color c) Typical effect
Multiply a × c Darkens and tints.
Screen 1 − (1 − a) × (1 − c) Brightens and tints.
Overlay 2·a·c where a ≤ 0.5; 1 − 2·(1 − a)·(1 − c) otherwise Tints with increased contrast.
Linear Dodge a + c Adds brightness; bright areas can clip.
Normal (Solid Paint) c Replaces the image with the solid color.

The final value is original × (1 − m) + blended × m, where m is the mask value multiplied by the blend opacity. Without a mask, m is the blend opacity alone.

Preview and buttons#

Action Result
Mouse wheel Zooms around the pointer, up to 800 %.
Left, right or middle drag Pans the preview.
Double-click Zooms to fit.
Ctrl + click Toggles between the colorized preview and the original. Any held modifier key triggers this toggle. The heading reads "Source Image (Original)" in red while the original is shown. Any setting change returns to the colorized preview.
Apply Color Recalculates with the current settings and opens the result as a new image named Colorized_Image.
Close Closes the dialog and discards the temporary working images.

Tips#

  • Change color without changing brightness: combine any blend mode with Preserve Original Luminance. The script's own tooltip recommends this option for astrophotography, to avoid blowing out stars and nebulae.
  • Soft edges: blur the mask beforehand. Hard mask edges produce hard color edges.
  • Subtle results: keep Blend Opacity low (the default is 20 %) and apply the script more than once if needed. Each run creates a new image that you can run the script on again.
  • Monochrome data: a grayscale target is copied into all three channels before blending, so the result is a color image you can continue processing.
  • Matching a mask from MK Color Range Selection: that script names its output ColorMask, which this script preselects automatically.

Troubleshooting and limitations#

Symptom Explanation and solution
The script stops with "Please open at least one image…" Open an image first, then run the script again.
An error appears after choosing a mask The mask must have the same dimensions as the target. The script does not check this before running PixelMath.
The preview is almost black The image is probably linear. Tick Auto-Stretch Previews.
Typing an opacity value does nothing Version 1.0 does not read the typed value. Use the slider.
The dialog is too large for my screen The window is not resizable. Tick Compact UI.
Clicking toggles the original unexpectedly Clicking while holding Ctrl, or any other modifier key, toggles the original view.
Bright areas clip with Linear Dodge Linear Dodge adds the color to the image. Lower the opacity, or use Screen.

Limitations:

  • The result is always a new RGB image; the script never modifies the target.
  • The script works on the main view of the target and mask images.

Version information#

Item Value
Version 1.0
Source file MK Colorize By Mask V1.0.js
Dialog title "Colorize By Mask Pro"
Menu (feature ID) Script › MK Scripts › Colorize by Mask
Installed from MKScripts repository (https://mhkastro.github.io/MKScripts/)
Repository release date 28 July 2026
PixInsight versions 1.9.4 – 1.9.x
Tested in PixInsight Not yet recorded for this guide

Release notes for each version are listed in the Releases section of this page.

Updates

New versions are delivered through the MKScripts repository: use Resources › Updates › Check for Updates in PixInsight.

License

Being publicly available does not make the scripts open source. See the terms of use.