Conversion from CV_64F to CV_8U images in Edge Detection Tutorial

asked 2017-12-04 04:12:06 -0500

Tschokokuki gravatar image

updated 2017-12-04 04:14:51 -0500

Hello together,

In the "One important Matter" section the conversion from 64F to 8U is mentioned. https://opencv-python-tutroals.readth...

It says that the image should be calculated in a 64F image format, which is good. But the conversion with taking the absolute value and then converting it to 8U is wrong in my eyes. It only works because the image is black and white. Because the negative value becomes 0 and the highest value becomes black. But in general the gray values in between will be calculated wrong.

The image should be normalized something like:

min = np.min(sobelx_64f)
sobelx_64f = sobelx_64f-min #to have only positive values
max=np.max(sobelx_64f) 
div=max/255 #calculate the normalize divisor
sobelx_8u=np.uint8(sobelx_64f/div)

Since I am quite new to image processing, could somebody please validate this?

Thank you Tschokokuki

edit retag flag offensive close merge delete

Comments

1

sidenote: please rather use the opencv python tutorials (the tutroals are no more maintained)

berak gravatar imageberak ( 2017-12-04 04:18:16 -0500 )edit

This seems to work fine, despite of the fact that division by zero may occur.

div = max / float(255) #calculate the normalize divisor
sobelx_8u = np.uint8(np.round(sobelx_64f / div))

should do the trick.

bluecore gravatar imagebluecore ( 2017-12-14 08:18:34 -0500 )edit