GreycLab / gmic

GREYC's Magic for Image Computing: A Full-Featured Open-Source Framework for Image Processing
Other
66 stars 11 forks source link

Wrong output when using 16 bit color depth #59

Closed Redo11 closed 1 month ago

Redo11 commented 1 month ago

When I put a filter on a 16 bit image, the output gets overblown and generally just white.

16 bit image input: input_16bit

applied

gmic input $1  \
fx_custom_transform "i","i","i","i","i","i",0 \
output[0] $1.out.png

Output: input_16bit png out

8 bit image input: input

applied

gmic input $1  \
fx_custom_transform "i","i","i","i","i","i",0 \
output[0] $1.out.png

Output: input png out

Redo11 commented 1 month ago

Possible problems with higher depths as well. Gmic_qt has no problem with higher than 8 bit depths.

dtschump commented 1 month ago

When reading a 16bits/channel image in G'MIC, the value range you get for your image is [0,65535]. Most of the command/filters in G'MIC are implemented for a value range in [0,255], so it's not so surprising that the outcome of these commands is not what is expected. When reading a 16bits/channel image, I suggest you first divide your image values by 257 before applying the processing command, like:

$ gmic input16.png div 257 fx_custom_transform "i","i","i","i","i","i",0 mul 257 output output16.png

You won't lose any precision as images in G'MIC are stored in float-valued format.

Redo11 commented 1 month ago

When reading a 16bits/channel image in G'MIC, the value range you get for your image is [0,65535]. Most of the command/filters in G'MIC are implemented for a value range in [0,255], so it's not so surprising that the outcome of these commands is not what is expected. When reading a 16bits/channel image, I suggest you first divide your image values by 257 before applying the processing command, like:

$ gmic input16.png div 257 fx_custom_transform "i","i","i","i","i","i",0 mul 257 output output16.png

You won't lose any precision as images in G'MIC are stored in float-valued format.

I have a mix of 32 bit, 16 bit and 8 bit images. I want to apply a watermark and cause degradation to these images, to upload online. How am I supposed to do that consistently?

dtschump commented 1 month ago

I have a mix of 32 bit, 16 bit and 8 bit images. I want to apply a watermark and cause degradation to these images, to upload online. How am I supposed to do that consistently?

A simple solution is to first store the min/max values of your images into a variable, normalize your image to [0,255], apply the filter, then renormalize back to the originel values:

$ gmic inputXX.png m,M:=im,iM normalize 0,255 fx_custom_transform "i","i","i","i","i","i",0  normalize \$m,\$M output outputXX.png
Redo11 commented 1 month ago

thanks a lot