Ask Your Question

Convert from CV_32FC1 to binary

asked 2015-03-10 05:11:46 -0500

maystroh gravatar image

I have an image of type CV_32FC1 and I need to convert it binary without passing by the conversion to CV_8U since it seems to me that I'm loosing data by passing to it before going to binary.

result = Mat(res.size(),CV_32FC1); 
for (int i = 0; i < res.rows ; i ++)
        for (int j = 0; j < res.cols; j++)
  <float>(i,j) = (fabs(<float>(i,j)) / 8);
result.convertTo(result, CV_8U);
threshold(result, imageBinary, 30, 255, CV_THRESH_BINARY);

Any idea how can I achieve it?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2015-03-10 05:25:55 -0500

updated 2015-03-10 10:38:56 -0500

thdrksdfthmn gravatar image

Why don't you just pass the 32FC1 image to cv::threshold:

src – input array (single-channel, 8-bit or 32-bit floating point).

And BTW: If you write a loop over pixels in an image, you are doing it wrong (in maybe 90%) of the cases. You are not the first person to compute the abs of a matrix, so there is a function for it:

cv::Mat result = cv::abs(res)* (1/8)

edit flag offensive delete link more



Yep, right. I just figured out.

maystroh gravatar imagemaystroh ( 2015-03-10 05:43:09 -0500 )edit

Question Tools

1 follower


Asked: 2015-03-10 05:11:46 -0500

Seen: 1,402 times

Last updated: Mar 10 '15