Possible bug with "-remap"

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
josephmartin
Posts: 2
Joined: 2019-06-17T21:41:08-07:00
Authentication code: 1152

Possible bug with "-remap"

Post by josephmartin » 2019-06-18T21:54:59-07:00

When converting a 16 bpp grayscale image into a 8 bpp grayscale image with -remap using a palette of 256 distinct shades of gray, the resulting image is only made up of no more than 64 distinct shades of gray.

The expected behavior would be the creation of an image using the full range of shades supplied by the palette.

Code to reproduce:

CODE: SELECT ALL

#!/bin/bash

# Create high color depth test image
convert -size 256x512 gradient:"black-white" "bw-gradient-int_16.png"

# Create a palette for conversion/reduction to 256 shades of gray
convert -size 256x1 gradient:"black-white" "palette.png"

# Reduce the depth from 16 to 8 bits using the palette
convert "bw-gradient-int_16.png" -remap "palette.png" -dither FloydSteinberg -depth 8 "bw-gradient-int_8.png"

# Determine the amount of distinct colors in the resulting image
convert "bw-gradient-int_8.png" -format %[k] info:

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

Re: Possible bug with "-remap"

Post by fmw42 » 2019-06-18T22:22:13-07:00

But your palette for the remap is still 16-bits. You only reduce the depth after processing. Also the -dither should come before the -remap. So I am not sure your description of the issue is compatible with what commands you used.

If I set the palette to 8-bit depth and use -dither none, it looks to me like it works correctly

convert -size 256x512 gradient:"black-white" "bw-gradient-int_16.png"
convert -size 256x1 gradient:"black-white" -depth 8 "palette.png"
convert "bw-gradient-int_16.png" -dither none -remap "palette.png" "bw-gradient-int_8.png"
convert "bw-gradient-int_8.png" -format %[k] info:
256

I think the dithering reduces the number of colors. When I sue -dither FloydSteinberg, then I only get 32 colors.

Post Reply