hsnr-gamera / gamera-4

Gamera 4 for Python 3
GNU General Public License v2.0
10 stars 8 forks source link

image.to_grey16() outputs fully black images #48

Closed EMZEDI closed 2 years ago

EMZEDI commented 2 years ago

name: 🐞Bug about: Conversion .to_grey16() method title: '.to_grey16() outputs fully black images'

Current Behavior:

I am using Gamera4 to convert RGB images to Greyscale16 format. I have tried more than 10 datasets and all output fully black images using the .to_grey16() method in the image conversions. The same thing happens with Gamera3. I am wondering where this problem is coming from and if this has ever happened previously.

Expected Behavior:

The method is supposed to return a black and white image in a greyscale16 format but it is not.

Steps To Reproduce:

In a python3.7 environment:

from gamera.core import *

def test(image):
    img = load_image(image)
    img2 = img.to_grey16()
    img2.save_PNG("out.png")

if __name__ == "__main__":
    image = "TODO: EDIT THE INPUT_PATH"
    init_gamera()
    test(image)

You can try testing the script using the following input RGB image. ConvertRGBImageToGrayscaleImageExample_01

Environment:

cdalitz commented 2 years ago

Strangely, the image is displayed correctly in the gamera_gui, even after saving it to a file and reloading that file. There seems to be some wrong usage of libpng in Gamera, maybe setting the header wrong. We must have a look into this.

cdalitz commented 2 years ago

It turned out this was an endianness issue while writing GRAY16 PNG images. The problem should be fixed in the latest git version.