apply a mask on 4-bit BMP image files without changing the colormap

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Posts: 1
Joined: 2019-02-06T16:23:59-07:00
Authentication code: 1152

apply a mask on 4-bit BMP image files without changing the colormap

Post by RolJP4 »

I’m working with 4-bit BMP image files. These image files all have the same colormap, consisting of 16 entries, though most of the images use less than these 16 colors.
The colormaps must not be altered during the process, as the whole system relies on these colors, and this gives me kind of a headache.
What I’m trying to do is apply a mask of the same dimensions as the input images. This mask is build of just two colors, white (pixel value 0) and black (pixel value 1). The mask file contains the same colormap as the input images:

0: (255,255,255,255) #FFFFFFFF white
1: ( 0, 0, 0,255) #000000FF black
2: (110,250, 70,255) #6EFA46FF srgba(110,250,70,1)
3: ( 80, 50,230,255) #5032E6FF srgba(80,50,230,1)
4: ( 80, 80,250,255) #5050FAFF srgba(80,80,250,1)
5: (225,110, 10,255) #E16E0AFF srgba(225,110,10,1)
6: (240, 0, 0,255) #F00000FF srgba(240,0,0,1)
7: (170, 50,240,255) #AA32F0FF srgba(170,50,240,1)
8: (240, 0, 50,255) #F00032FF srgba(240,0,50,1)
9: (190, 0, 0,255) #BE0000FF srgba(190,0,0,1)
10: (200, 0, 0,255) #C80000FF srgba(200,0,0,1)
11: (170, 0, 0,255) #AA0000FF srgba(170,0,0,1)
12: (150, 0, 0,255) #960000FF srgba(150,0,0,1)
13: (130, 0, 0,255) #820000FF srgba(130,0,0,1)
14: (100, 0, 0,255) #640000FF srgba(100,0,0,1)
15: (200,100,100,255) #C86464FF srgba(200,100,100,1)

I want a pixel in the input image file to get the value of 0 (index of white in the colormap) where the masks image’s pixel has the value of 0, and all the other pixels (mask pixel color is 1 - black) remain their color value.

I’m working on a Windows 7 system, ImageMagick version is
7.0.3-1 ImageMagick-7.0.3-1-Q16-x64-dll.exe

Here are links to some images I have constructed to illustrate what I’m doing.
[example][ ... itZ0n2K5d/]

This is a mask image:
[mask][ ... glHaabAgr/]

And this would be the result, that I edited in a hex editor, but what I’m trying to achieve with ImageMagick:
[result][ ... 696EeViyT/]

To give some background information, these images are 1-channel images representing one channel of a CMYK printing process, so for printing the image there are four image files for every single picture. This mask is used after channel separation to leave some areas white on a channel basis ie. no cyan color in certain areas of the printed product. The colormap is used to display the images on a monitor, though the printer only uses the actual pixel values for color intensity. That’s why it’s important that the colormap must not be altered.

Any help is greatly appreciated!
Thanks a lot!
Post Reply