Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable reading 16bit/channel (png) images to grayscale#2924

Merged
ahojnnes merged 3 commits intocolmap:mainfrom
Ediolot:main
Nov 21, 2024
Merged

Enable reading 16bit/channel (png) images to grayscale#2924
ahojnnes merged 3 commits intocolmap:mainfrom
Ediolot:main

Conversation

@Ediolot
Copy link
Contributor

@Ediolot Ediolot commented Nov 19, 2024

Hello ! I had some issues reading 16bit per channel pngs with the feature extractor. I tracked the issue to this line returning a null pointer.

Turns out FreeImage cant transform these images directly into grayscale as described here. This happens at line 104 in the FreeImage Conversion8.cpp file:

FIBITMAP * DLL_CALLCONV
FreeImage_ConvertTo8Bits(FIBITMAP *dib) {  // Called by FreeImage_ConvertToGreyscale
	if (!FreeImage_HasPixels(dib)) {
		return NULL;
	}

	const FREE_IMAGE_TYPE image_type = FreeImage_GetImageType(dib);
	if (image_type != FIT_BITMAP && image_type != FIT_UINT16) {   // <----- Here -----
		return NULL;
	}
	...

My solution is just transforming the image to 8bits per channel before transforming to grayscale.

@ahojnnes
Copy link
Contributor

ahojnnes commented Nov 20, 2024

Thanks, this looks right to me. Ideally, we would construct a small unit test, where we use FreeImage to save a test image in 16bit and load it with our Bitmap class to check for expected pixel values. Is this something you would be able to implement?

@Ediolot
Copy link
Contributor Author

Ediolot commented Nov 20, 2024

I added a test for this while trying to mimic the workflow used in other tests

Copy link
Contributor

@ahojnnes ahojnnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, looks good to me. Thank you for adding a nice unit test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants