Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- from matplotlib import pyplot as plt
- def contrast_stretch_image(img,points):
- rows,cols=img.shape
- img1=(img[0:]).copy()
- for i in range(0,rows):
- for j in range(0,cols):
- value=img[i][j]
- k=1
- while k<len(points):
- (x2,y2)=points[k]
- (x1,y1)=points[k-1]
- if value>=x1 and value<=x2:
- img1[i][j]=((y2-y1)/(x2-x1))*(value-x1)+y1
- break
- k+=1
- return img1
- img=cv2.imread('slika.png',0)
- img_after=contrast_stretch_image(img,([0,0],[50,30],[130,200],[150,220],[256,256]))
- plt.figure(1)
- plt.subplot(121)
- plt.imshow(img,cmap='gray')
- plt.title("Original image")
- plt.xticks([])
- plt.yticks([])
- plt.subplot(122)
- plt.imshow(img_after,cmap='gray')
- plt.title("Image after contrast stretching")
- plt.xticks([])
- plt.yticks([])
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement