Reputation: 664
I use OpenCV's Sobel filter for edge detection. I was wondering why the output looks different when I run the 2 following lines.
# uint8 output
img_uint8 = cv2.Sobel(img_gray, cv2.CV_8U, dx=1, dy=0, ksize=5)
# float32 output
img_float32 = cv2.Sobel(img_gray, cv2.CV_32F, dx=1, dy=0, ksize=5)
This is how the 2 outputs look:
The float32 output appears mostly gray whereas the uint8 output appears mostly black. Are negative values of float32 output displayed as gray? Or how are negative values treated when we display the image?
Upvotes: 1
Views: 251
Reputation: 60799
In the uint8 case, negative values get clipped and set to 0. What you see here is an incomplete result, information is missing. You should never do this.
In the float32 case, zero is shown as middle gray, with negative values darker and positive values brighter.
Upvotes: 3