Ask Your Question
0

Convert Images (cv::Mat)

asked 2020-09-10 06:54:34 -0600

RoidDoi gravatar image

Hi,

If I want to use the "convertTo" method to convert gray images, I don't get good results. Be it from 8 to 16, 16 to 8, 16 to 32... I always get very noisy images as output.

for example like this:

src.convertTo(dst, CV_32F);

This line is from here: docu

sometimes openCV is so incomprehensible and unnecessarily complicated can anyone help me? Just convert images from one bit depth to another. So if e.g. 16Bit pictures have a range of 0-65536, the 8Bit pictures should have a range of 0-255. This means that the value 65536 should be mapped to 255 in an 8Bit image etc. or ? The output image should look like the input image. In this example from 16 to 8 there should be less grayscale.

edit retag flag offensive close merge delete

Comments

1

You need to scale the results, so multiply or divide by 255 or 65536, etc. Look more closely at that function.

Der Luftmensch gravatar imageDer Luftmensch ( 2020-09-10 07:22:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2020-09-14 04:26:34 -0600

RoidDoi gravatar image

And when i want to "convert" the values between 0 - 1 i use "normalize". But this function don't work as expected. I tested the function with a grayscale image (values in the image 10,100,200) (8bit).When i use :

cv::normalize(img, img, 0, 1,cv::NORM_MINMAX);

When i get the min max values, i get 0 and 1. But i expected ~0.003 and ~0.78 ( because 200 is ~78% of 255) The value 255 has to be 1 after the normalize function and the value 0 = 0. When i calculate beta as = (1. /255.) * 200 i get also 0 and 1 for the min/max values.

What I mean is. Actually the container from 0 - 255 should be put into a "container" between 0 and 1. But in the same ratio. Example: If the maximum value in my 8bit is 200, it should not be 1. 255 should be 1 and 200 should be ~0.78. Do you understand what I mean?

edit flag offensive delete link more

Comments

you probably did NOT want to "normalize", but just "scale" it. to get from 16bit unsigned to 8bit you'd use:

Mat img8;
img16.convertTo(img8, CV_8U, 1.0/255); //1.0/128 if it was CV_16S before
berak gravatar imageberak ( 2020-09-14 04:44:33 -0600 )edit

i tried this:

img.convertTo(img, CV_8U, 1.0/255.0);

and get min= 0 ,max =1.

And i tried this:

img = img / 255;

same result. I check the min max values with:

    double min,max;
cv::minMaxLoc(img,&min,&max);

And befor i do that i get the min/max of the original image with min=10, max =200 and i checked the original image depth with the result CV_8U=0

i have openCV 3.3

RoidDoi gravatar imageRoidDoi ( 2020-09-14 04:55:09 -0600 )edit
1

this works. i have to use CV_64F

img.convertTo(img, CV_64F, 1.0/255.0);
RoidDoi gravatar imageRoidDoi ( 2020-09-14 05:46:07 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-09-10 06:54:34 -0600

Seen: 4,810 times

Last updated: Sep 14 '20