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

Clipping with CV_16U to CV_16S conversion #31

Open
GxHam opened this issue Jun 23, 2020 · 2 comments
Open

Clipping with CV_16U to CV_16S conversion #31

GxHam opened this issue Jun 23, 2020 · 2 comments

Comments

@GxHam
Copy link

GxHam commented Jun 23, 2020

Hi Daniel!

Thank you for the great program! I am having major issues with segmentation as the higher intensities are getting clipped. Since my images are CV_16U, they get converted to CV_16S, but the higher values are clipped instead of getting shrunk. On the left is the image from imshow() and on the right from window explorer. The contrast only starts changing when I go below 32768.

image (1)

Here is the output in the console:
image (2)

I think there might be a bug with the CV_16U conversion. I tried re-saving my image using raster, and manged to regain the dynamic range to 65536, but the file format changed to CV_32F_5. The code is as follows:

{
  library(raster)
  library(rgdal)
  tictoc::tic("Time Taken")
  r_im <- raster(test_im)
  writeRaster(r_im, conv, format="GTiff", overwrite=T)
  tictoc::toc(log=TRUE)
}

Is there a way to fix this bug or do I have to re-save all my images using raster? Re-conversion via raster is quite inefficient, and I am not sure if there would be any downstream issues, hence I am pretty reluctant to use it.

Best Regards,
Gao Xiang Ham

@tractatus
Copy link
Owner

Hi Gao,

Yes this looks like a type conversion bug. Let me see if it can be type casted directly to 16 bit unsigned.

@GxHam
Copy link
Author

GxHam commented Jun 24, 2020

Hi Danial,

Yup, however I am not sure if the bug is with OpenCV or your src code, since OpenCV has some reported issues when reading tiff files as well. Currently I am using Rvision to just load and rescale my data to fit within 32768, since it is faster then raster. However, it would be great if I could directly load 16 bit unsigned. Thank you so much for helping!

Sincerely,
Gao Xiang Ham

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