Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import math
- import collections
- def Histogram(obraz,iloscP):
- unique_elements, counts_elements = np.unique(obraz, return_counts=True)
- uniqueElements = np.arange(256)
- countsElements = np.zeros(256)
- for x,y in zip(unique_elements, counts_elements):
- countsElements[int(x)] = int(y)
- zakres = math.ceil(255 / iloscP)
- X = np.zeros(iloscP)
- Y = np.zeros(iloscP)
- for i,val in zip(range(iloscP),np.array_split(uniqueElements, iloscP)):
- X[i] = val[-1]
- for i,countsPix in zip(range(iloscP),np.array_split(countsElements, iloscP)):
- Y[i] = np.sum(countsPix)
- return X,Y,uniqueElements,countsElements
- obraz = plt.imread("kierowca.jpg")
- obraz = obraz[:,:,2]
- iloscP = 256
- zakres = math.ceil(255 / iloscP)
- X,Y,uniqueE,countsE = Histogram(obraz,iloscP)
- x1 = X[np.where(Y > 1000)[0][0]]
- x2 = X[np.where(Y > 1000)[0][-1]]
- def Rozciganie(obraz):
- image2 = obraz
- size = image2.size
- unique_elements, counts_elements = np.unique(obraz, return_counts=True)
- uniqueElements = np.arange(256)
- countsElements = np.zeros(256)
- for x, y in zip(unique_elements, counts_elements):
- countsElements[int(x)] = int(y)
- cumulativeSumCounts = np.cumsum(countsE)
- valMin = cumulativeSumCounts[np.where(cumulativeSumCounts > 0)[0][0]]
- for x,y in zip(uniqueE,cumulativeSumCounts):
- image2 = np.where(obraz == x,round(( ((y - valMin))/ (size - valMin )) * 255),image2)
- return image2
- image2 = Rozciganie(obraz)
- X,Y,uniqueE,countsE = Histogram(image2,iloscP)
- plt.imshow(image2)
- #plt.bar(X,Y)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement