Possible remap bug

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Possible remap bug

Post by spongemonkey »

Q16 6.8.0-7 64bit on Windows

Remapping this image with this colour map results in an image which contains a colour that doesn't appear in the colour map (namely rgb(101,4,1))

commands used were:

Code: Select all

convert.exe InputImage.tif -remap ColourMap.tif Remapped.tif
convert.exe ColourMap.tif -unique-colors txt:- > map_colours.txt
convert.exe Remapped.tif -unique-colors txt:- > remapped_colours.txt
This isn't right is it? Let me know if those links are no good and I'll find somewhere else to upload them to, or I can email the files if not.

Thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Possible remap bug

Post by fmw42 »

add +dither to turn off dithering

see
http://www.imagemagick.org/Usage/quantize/#remap
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible remap bug

Post by snibgo »

Should dithering create a difference in the colours chosen? I can't see that. Besides, I've tested this with and without dithering, and the same problem occurs.

As far as I can see, the OP is doing this correctly, and yes, it creates a colour srgb(101,4,1) (out of 65535) that isn't in the map. The closest map colour is srgb(100,0,0). The other colours look ok, but I haven't done a thorough search.

I tested in Windows 7, IM v6.7.9 and 6.8.1-10.

I notice from the documentation (http://www.imagemagick.org/script/comma ... .php#remap ) that "the closest color (in RGB colorspace) is selected to replace that pixel in the image". Perhaps this means that both the image and map are converted from sRGB to RGB before mapping, and the result is converted back to sRGB afterwards. Perhaps this conversion has a bug at these very low values.
snibgo's IM pages: im.snibgo.com
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Re: Possible remap bug

Post by spongemonkey »

Does anyone in authority have any comment on this? I'm working on a project predicated on the notion that the colours are preserved, and will have to rethink the design radically if this assumption is unfounded :-?

Cheers
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible remap bug

Post by magick »

As you might imagine, your bug report is not our only one. When we find the time to properly investigate, we will comment. Perhaps by the end of this weekend.
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Re: Possible remap bug

Post by spongemonkey »

Thanks, I don't mean to sound impatient
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible remap bug

Post by magick »

We need your images to reproduce the problem but the links do not work. Post new links or e-mail the images to bugs at imagemagick dot org.
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Re: Possible remap bug

Post by spongemonkey »

Emailed images

Thanks
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible remap bug

Post by magick »

Remapping limits the colormap to 8-bits of precision. The mapping process utilizes an octree which is limited to 8-bits to limit resource consumption. For 16-bit images, some colors (those deeper than 8-bits) are coalesced into the same node. When that happens, the mean color-cube is returned and that color is used in the remapping process. Note the original image can be any depth but the colormap must be at most 8-bit. To get the expected results you need to ensure your colormap is at most 8-bits in depth. Try these commands:
  • convert ColourMap.tif -depth 8 map.tif
    convert InputImage.tif -map map.tif Remapped.tif
spongemonkey
Posts: 20
Joined: 2012-10-08T13:42:11-07:00
Authentication code: 67789

Re: Possible remap bug

Post by spongemonkey »

I have everything working now. I'm using Magick++ and was making no progress for a long time as I was using

Code: Select all

image.depth(8);
instead of

Code: Select all

image.modulusDepth(8);
I guess this doesn't really belong in bugs then? Or would you prefer it stayed here and I marked it as [INVALID] or something?

Thank you!!
Post Reply