Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between CV_8U and CV_32F and what should I worry about when converting between them?

Tags:

c++

opencv

I have some code that is acting up and I suspect it's because I'm operating on the wrong types of data or converting between them poorly.

It is mixing cv::Mat objects of types CV_8U (which is what is created when reading a jpg as grayscale with cv::imread), CV_32F, and CV_32S.

What are the differences between these data types, and what do I need to be sure of when converting between them?

like image 659
mic Avatar asked Dec 04 '11 17:12

mic


People also ask

What is CV_8U?

CV_8U is unsigned 8bit/pixel - ie a pixel can have values 0-255, this is the normal range for most image and video formats.

What is CV_64F?

CV_64F is the same as CV_64FC1 . So if you need just 2D matrix (i.e. single channeled) you can just use CV_64F. EDIT. More generally, type name of a Mat object consists of several parts.


1 Answers

CV_8U is unsigned 8bit/pixel - ie a pixel can have values 0-255, this is the normal range for most image and video formats.

CV_32F is float - the pixel can have any value between 0-1.0, this is useful for some sets of calculations on data - but it has to be converted into 8bits to save or display by multiplying each pixel by 255.

CV_32S is a signed 32bit integer value for each pixel - again useful of you are doing integer maths on the pixels, but again needs converting into 8bits to save or display. This is trickier since you need to decide how to convert the much larger range of possible values (+/- 2billion!) into 0-255

like image 68
Martin Beckett Avatar answered Sep 20 '22 15:09

Martin Beckett