Ask Your Question
0

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

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

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

Comments

1

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

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

1 answer

Sort by ยป oldest newest most voted
0

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

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

Question Tools

1 follower

Stats

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

Seen: 2,960 times

Last updated: Dec 04 '18