简体   繁体   中英

OpenCV/Python: MedianBlur filter produces a black image

I'm using OpenCV in python 2.7.

I'm trying to add noise to a grayscale image like:

localvar = skimage.util.random_noise(imgray, mode="localvar")

And then I'm trying to use MedianBlur filter to reduce the noise like

median_blur = cv2.medianBlur(localvar.astype(np.uint8),3)

But when I'm trying to show median_blur image, I get an almost black image.

plt.subplot(133),plt.imshow(median_blur, cmap = 'gray')
plt.title('Median Filter'), plt.xticks([]), plt.yticks([])

I found the solution.

I have to convert medianBlur image input, in my example localvar image to float32 .

Here is the solution:

median_blur = cv2.medianBlur(np.float32(localvar),3)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM