Advertisement
Guest User

prva

a guest
Apr 26th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3. from matplotlib import pyplot as plt
  4.  
  5. def contrast_stretch_image(img,points):
  6. rows,cols=img.shape
  7. img1=(img[0:]).copy()
  8. for i in range(0,rows):
  9. for j in range(0,cols):
  10. value=img[i][j]
  11. k=1
  12. while k<len(points):
  13. (x2,y2)=points[k]
  14. (x1,y1)=points[k-1]
  15. if value>=x1 and value<=x2:
  16. img1[i][j]=((y2-y1)/(x2-x1))*(value-x1)+y1
  17. break
  18.  
  19. k+=1
  20. return img1
  21.  
  22.  
  23. img=cv2.imread('slika.png',0)
  24. img_after=contrast_stretch_image(img,([0,0],[50,30],[130,200],[150,220],[256,256]))
  25. plt.figure(1)
  26. plt.subplot(121)
  27. plt.imshow(img,cmap='gray')
  28. plt.title("Original image")
  29. plt.xticks([])
  30. plt.yticks([])
  31. plt.subplot(122)
  32. plt.imshow(img_after,cmap='gray')
  33. plt.title("Image after contrast stretching")
  34. plt.xticks([])
  35. plt.yticks([])
  36. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement