Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we use 16-bit RGB image as input without converting into 8-bit RGB(by libpng)? #93

Open
Starry-lei opened this issue Jan 1, 2023 · 3 comments

Comments

@Starry-lei
Copy link

Hi, I think the code here:
" image->SetSize(width, height);
png_bytep* row_pointers = new png_bytep[height];
for (u32 y = 0; y < height; ++ y) {
row_pointers[y] = reinterpret_cast<png_bytep>(image->row(y));
}
png_read_image(png_ptr, row_pointers);
"

will convert 16-bit RGB image into 8-bit RGB right?

The libpng api: void PNGAPI
png_read_image(png_structrp png_ptr, png_bytepp image) require png_bytepp( uchar pointer pointer).

Is there any easy way to change the above code so that it supports 16-bit RGB image as input?

@puzzlepaint
Copy link
Collaborator

The PNG loading code is written such that it always tries to convert the file's format to the format of the Image object which the file is loaded into. So, if that works as intended, with a 3-channel 16-bit Image used as output, loading the images might already work.

However, to actually use 16-bit RGB images in the SLAM algorithm would require adjusting other places in the code. As a start, this definition has Vec3u8 (a 3-channel 8-bit unsigned char vector) hard-coded as color type and would need to be adjusted to something like Eigen::Matrix<u16, 3, 1>:

RGBDVideo<Vec3u8, u16> rgbd_video;

And then any potential other places that might assume that the color is 8 bits per channel need to be adjusted. For example, the color storage in keyframes:

CUDABuffer<uchar4> color_buffer_;

@Starry-lei
Copy link
Author

Starry-lei commented Jan 6, 2023

I adjusted a lot of places that assume the color image is 8-bit RGB along the dirction of data flow, but I got stuck here:

template class CUDABuffer_<uchar4>;

Once I extend the "template class CUDABuffer_<uchar4>;" to "template class CUDABuffer_<ushort4>;", an error

""Invalid operands to binary expression ('ushort4' and 'float')" "

occurs at :

buffer(y, x) = factor * tex2D<float>(texture, x + 0.5f, y + 0.5f);

How do you think I should adjust this?
Hmm, does that mean I should override operator "*"? Does it make sense for next steps?

@puzzlepaint
Copy link
Collaborator

No, look here instead:

// Avoid compilation of some functions for some types by declaring but not

This list contains an entry for uchar4:

template<> void CUDABuffer_<uchar4>::SetToReadModeNormalized(cudaTextureObject_t texture, cudaStream_t stream);

So it probably makes sense to add an entry for ushort4 there as well. This should cause the function containing line 89 not to be compiled for that type.

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

No branches or pull requests

2 participants