Is there any filter method keeping the 16-bit image? [closed]

asked 2018-06-06 00:41:39 -0600

neppie gravatar image

updated 2018-10-28 20:44:56 -0600

Hello,

I am trying to filter the 16bit grayscale image with 16bit grayscale PSF. I tried cv::filter2D(inputImage, outputImage, -1, psf) where inputImage and psf are originally 16bit grayscale tiff files. But when I tried to convert outputImage using imwrite, it is unexpectedly compressed into 8bit image.

Did I do anything wrong? How can I filter the 16bit grayscale image with keeping 16bit grayscale?

My environment is OpenCV 3.4.1 and Visual Studio 2015.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2018-10-28 20:45:26.553718

Comments

https://docs.opencv.org/master/d4/d86...

can you addyour code to the question ?

berak gravatar imageberak ( 2018-06-06 00:45:15 -0600 )edit

Here is very simlified my implementation.

auto inputImage = cv::imread(inputFile, IMREAD_ANYDEPTH);
input.convertTo(inputImage, CV_64F);

auto psf = cv::imread(psfFile, IMREAD_ANYDEPTH);
psf.convertTo(outputImage, CV_64F);

cv::Mat outputImage;
cv::filter2D(inputImage, outputImage, -1, psf);

cv::imwrite(outputFile, outputImage);
neppie gravatar imageneppie ( 2018-06-06 00:57:13 -0600 )edit
1

what is "outputFile" ?

writing CV_64 images is not supported from imwrite(). you probably need a conversion back to CV_16U, and an appropriate image format, like tiff or png

berak gravatar imageberak ( 2018-06-06 01:03:12 -0600 )edit

Thank you for great advice. I found if the image type is not supported on imwrite(), imwrite() forcedly converts the image into CV_8U. Converting the type into CV_16U went expectedly. Thanks!

neppie gravatar imageneppie ( 2018-06-06 01:17:35 -0600 )edit