Ask Your Question

Why converting an image from CV_8UC3 to CV_32FC1 still seems the same?

asked 2018-12-04 08:26:35 -0500

I first read an image with:

imread("imgFile.jpg", cv::IMREAD_UNCHANGED)

The image type is CV_8UC3.

After I convert the image into floats with

img.convertTo(f_img, CV_32FC1, 1/255.0);

When I use imshow for both images, they are both displayed with color.

imshow("Original Image", img); imshow("Converted Image", f_img);

This will both displayed as the same.

edit retag flag offensive close merge delete



imshow() silently converts / scales your float img back to CV_8U ;)

berak gravatar imageberak ( 2018-12-04 09:13:37 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-12-04 08:36:44 -0500

LBerger gravatar image

In convertto doc :

desired output matrix type or, rather, the depth since the number of channels are the same as the input has; if rtype is negative, the output matrix will have the same type as the input.

In your program CV_32FC1 becomes CV_32F

If you need a channel use split and if you need a grayscale image use cvtColor

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-12-04 08:26:35 -0500

Seen: 29 times

Last updated: Dec 04 '18