daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Mar 20th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import numpy as np
  3.  
  4. image = cv2.imread('images/elephant.jpg')
  5. cv2.imshow('Original Image', image)
  6. cv2.waitKey(0)
  7.  
  8. # Creating our 3 x 3 kernel
  9. kernel_3x3 = np.ones((3, 3), np.float32) / 9
  10.  
  11. # We use the cv2.fitler2D to conovlve the kernal with an image
  12. blurred = cv2.filter2D(image, -1, kernel_3x3)
  13. cv2.imshow('3x3 Kernel Blurring', blurred)
  14. cv2.waitKey(0)
  15.  
  16. # Creating our 7 x 7 kernel
  17. kernel_7x7 = np.ones((7, 7), np.float32) / 49
  18.  
  19. blurred2 = cv2.filter2D(image, -1, kernel_7x7)
  20. cv2.imshow('7x7 Kernel Blurring', blurred2)
  21. cv2.waitKey(0)
  22.  
  23. cv2.destroyAllWindows()
  24.  
  25.  
  26.  
  27. import cv2
  28. import numpy as np
  29.  
  30. image = cv2.imread('images/elephant.jpg')
  31.  
  32. # Averaging done by convolving the image with a normalized box filter.
  33. # This takes the pixels under the box and replaces the central element
  34. # Box size needs to odd and positive
  35. blur = cv2.blur(image, (3,3))
  36. cv2.imshow('Averaging', blur)
  37. cv2.waitKey(0)
  38.  
  39. # Instead of box filter, gaussian kernel
  40. Gaussian = cv2.GaussianBlur(image, (7,7), 0)
  41. cv2.imshow('Gaussian Blurring', Gaussian)
  42. cv2.waitKey(0)
  43.  
  44. # Takes median of all the pixels under kernel area and central
  45. # element is replaced with this median value
  46. median = cv2.medianBlur(image, 5)
  47. cv2.imshow('Median Blurring', median)
  48. cv2.waitKey(0)
  49.  
  50. # Bilateral is very effective in noise removal while keeping edges sharp
  51. bilateral = cv2.bilateralFilter(image, 9, 75, 75)
  52. cv2.imshow('Bilateral Blurring', bilateral)
  53. cv2.waitKey(0)
  54. cv2.destroyAllWindows()
  55.  
  56.  
  57.  
  58. import numpy as np
  59. import cv2
  60.  
  61. image = cv2.imread('images/elephant.jpg')
  62.  
  63. # Parameters, after None are - the filter strength 'h' (5-10 is a good range)
  64. # Next is hForColorComponents, set as same value as h again
  65. #
  66. dst = cv2.fastNlMeansDenoisingColored(image, None, 6, 6, 7, 21)
  67.  
  68. cv2.imshow('Fast Means Denoising', dst)
  69. cv2.waitKey(0)
  70.  
  71. cv2.destroyAllWindows()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top