Bluur

DPI -OPENCV

Dec 1st, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1. import cv2 as cv
  2. import numpy as np
  3.  
  4. def gammaFilter(img, parameterValue=1.5):
  5.     values = np.array([((i / 255.0) ** (1.0 / parameterValue)) * 255
  6.                       for i in np.arange(0, 256)]).astype("uint8")
  7.     result =  cv.LUT(img, values)
  8.     return result
  9.  
  10. def addLabel(img, text, positionX):
  11.     cv.putText(img, text, (positionX, 50), cv.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
  12.  
  13. def getHistogram(img):
  14.     grayImg = cv.cvtColor(img, cv.COLOR_BGR2YUV)
  15.     grayImg[:, :, 0] = cv.equalizeHist(img[:, :, 0])
  16.     grayImg = cv.cvtColor(img, cv.COLOR_YUV2BGR)
  17.  
  18.     histogram = cv.calcHist([grayImg], [0], None, [256], [0, 255])
  19.     result = np.zeros((255, 256))
  20.     for x, y in enumerate(histogram):
  21.         cv.line(result, (x, 0), (x, y), (255, 255, 255))
  22.  
  23.     return result
  24.  
  25. originalImg = cv.imread("questao.jpeg")
  26.  
  27. imgFiltered = gammaFilter(originalImg, 1.8)
  28. addLabel(imgFiltered, "Gamma filter", 540)
  29. addLabel(originalImg, "Original Image", 540)
  30.  
  31. # show original image | show histogram original image |
  32. cv.imshow("DPI - Original image", originalImg)
  33. histogramOriginalImg = getHistogram(originalImg)
  34. cv.imshow("DPI - Histogram - Original Image", histogramOriginalImg)
  35.  
  36. # show manipuled image based on original image | show histogram after manipuled original image
  37. cv.imshow("DPI - Manipuled Image", imgFiltered)
  38. histogramFilteredGammaImg = getHistogram(imgFiltered)
  39. cv.imshow("Histogram - Filtered Image", histogramFilteredGammaImg)
  40.  
  41. cv.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment