This program provides an easy way to recolor parts of an image. If you have the color masks defined, you can simply set colors in the "Colors" image and run the script to apply the colors to the image. This is intended to be used for game modding (hence the use of DDS textures).
Here's a quick demo of what it can do. We start with the diffuse image, the color mask map (CMM) and the selected color image. We also have a ColorMasks.txt file to set what images to use. When we run the code, we get the output image shown.

All the end user has to do is change the colors file (just 3 pixels) and they can change what colors get applied
It looks a but underwhelming when applied to a plain image, but can be very powerful when used for coloring model textures

If you downloaded a mod that uses this, all you need to do is change the colors of the selected colors file(s) and run the ApplyColorMask.exe or ApplyColorMask.py. The three colors will determine what color gets applied to the image. If you look at the CMM file, the first color will be applied to the red section, second to green, and third to blue. If you set the color to pure white (255,255,255) the color will not be applied to that section. This means if you want the section to be white, it needs to be slightly off-white.
If you want to make a mod using this, you need to get ApplyColorMask.exe from the releases section or ApplyColorMask.py. You the need to put texconv.exe into the same folder. You can the make a CMM using whatever image editing app you want. Finally you will need to make a file called "ColorMasks.txt" in the same folder as the program. This file will define what image gets used and where it is written to. Here is a quick example:
"Input.dds Output.dds CMM.png Colors.png"
In this case, we're taking Input.dds, changing it using CMM.png and Colors.png, and writing to Output.dds. You can specify multiple lines in a single ColorMasks.txt file and each line can have more pairs of CMM and selected color if you want to apply more than 3 colors. In this case it would look like this:
"Input.dds Output.dds CMM1.png Colors1.png CMM2png Colors2.png
It's also important to note that this code uses BC7 SRGB dds files with mip maps enabled. If you don't want your textures configured this way, you can pretty easily edit the code to do that
EXE files can be a huge security risk if you don't trust where they came from. If you want to use this without an EXE, you can just run the Python file instead. Mods using this should provide the Python file for anyone who doesn't want to use EXEs. To run the Python file, you will need to install Python and the packages Numpy and ImageIO. Then you should be able to run it just like the EXE. You can also build the EXE yourself using Pyinstaller and running the build.bat file.
The program basically just reads in the image as an array and does the following on it for each area based on the CMM:
-Calculates the intensity (average of RGB) of the masked area and the intensity of the selected color
-Desaturates the area so the average intensity afterwards would be the same as the intensity of the selected color
-Multiply the image by the selected color in the masked area
-Use texconv to write it as a BC7_UNORM_SRGB DDS file
Feel free to use this project for whatever you want with or without credit. This was like 90% made from just forcing the ChatGPT to code it for me.
Special thanks to the Anime Game Modding Group Discord for helping me mod a certain game!