Ask Your Question

opencv convertto need to manually scale down inputs ?

asked 2017-01-20 11:28:02 -0500

Nbb gravatar image

if i am converting a cv_32s to cv_8u do i need to scale down the values or will opencv do that for me. what is the equation to scale everything ?

new = (current - min) / (max - min) * 255 ?

edit retag flag offensive close merge delete



can it be, you want a normalization (resulting in a CV_8U image) in the 1st place ?

berak gravatar imageberak ( 2017-01-20 11:47:53 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2017-01-24 12:06:03 -0500

updated 2017-01-24 12:08:56 -0500

Just to complement @pi-null-mezon's answer.

Before converting image type from 32S to 8U, you must normalize the image. For that you don't need to create your own algorithm, OpenCV has a normalize function

This call

cv::normalize(inMat, outMat, CV_MINMAX, 0, 255)

Will transform the smallest pixels to 0, the highest one to 255, and all the in-between accordingly to the right proportion. After that, you convert outMat to 8U and you are ready to display it.

edit flag offensive delete link more

answered 2017-01-24 04:44:02 -0500

pi-null-mezon gravatar image

Hi! As docs says saturate_cast will be applied after conversion. If you downscale precision (from CV_32S to CV_8U) than all converted values that are more than 255 becomes 255 and less than 0 becomes 0. So, now you should decide is that behavior one that you want?

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2017-01-20 11:28:02 -0500

Seen: 661 times

Last updated: Jan 24 '17