Page 1 of 1

Possible bug with "-remap"

Posted: 2019-06-18T21:54:59-07:00
by josephmartin
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:

Re: Possible bug with "-remap"

Posted: 2019-06-18T22:22:13-07:00
by fmw42
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.