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)
- zakres = math.ceil(255 / iloscP)
- Y = np.zeros(iloscP)
- X = [x * zakres for x in range(1, iloscP + 1)]
- for x in range(0, iloscP):
- for y, z in zip(unique_elements, counts_elements):
- if x == 0 and (X[x] > y):
- Y[x] = Y[x] + z
- elif (x < iloscP - 1) and (X[x - 1] <= y) and (X[x] > y):
- Y[x] = Y[x] + z
- elif (x == iloscP - 1) and (X[x] <= y):
- Y[x] = Y[x] + z
- return X,Y,unique_elements,counts_elements
- obraz = plt.imread("kierowca.jpg")
- obraz = obraz[:,:,2]
- iloscP = 15
- zakres = math.ceil(255 / iloscP)
- X,Y,uniqueE,countsE = Histogram(obraz,iloscP)
- #plt.subplot(2,6,1)
- plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
- plt.xticks(X,fontsize = 10)
- #plt.subplot(2,6,7)
- plt.show()
- x1 = (np.where(Y > 1000)[0][0] + 1) * zakres
- x2 = (np.where(Y > 1000)[0][-1] + 2) * zakres
- a = 150 / (x2 - x1)
- # image = np.array(plt.imread("kierowca.jpg"))
- # image2 = image[:,:,2]
- # mean = np.mean(image)
- #
- # unique_elements, counts_elements = np.unique(image2, return_counts=True)
- # cumulativeSumCounts = np.cumsum(counts_elements)
- # for x,y in zip(unique_elements,cumulativeSumCounts):
- # image2[image2 == x] = ((y - min(cumulativeSumCounts)) * 255)/ (np.size(image2))
- # X,Y,uniqueE,countsE = Histogram(image2,iloscP)
- # plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(X,fontsize = 10)
- # plt.show()
- # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 * a )
- # image2[image < x1] = 0
- # image2[image > x2] = 255
- # image2[image2 < 0] = 0
- # image2[image2 > 255] = 255
- # Xl,Yl,uniqueEL,countsEL = Histogram(image2,iloscP)
- # plt.subplot(2,6,2)
- # plt.bar(Xl,Yl,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(Xl,fontsize = 1.5)
- # plt.subplot(2,6,8)
- # plt.plot(uniqueEL,countsEL)
- #
- # image2 = image
- # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** 2 )
- # image2[image < x1] = 0
- # image2[image > x2] = 255
- # image2[image2 < 0] = 0
- # image2[image2 > 255] = 255
- # Xp,Yp,uniqueEP,countsEP = Histogram(image2,iloscP)
- # plt.subplot(2,6,3)
- # plt.bar(Xp,Yp,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(Xp,fontsize = 1.5)
- # plt.subplot(2,6,9)
- # plt.plot(uniqueEP,countsEP)
- #
- # image2 = image
- # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.sqrt(image2))
- # image2[image < x1] = 0
- # image2[image > x2] = 255
- # image2[image2 < 0] = 0
- # image2[image2 > 255] = 255
- # Xs,Ys,uniqueES,countsES = Histogram(image2,iloscP)
- # plt.subplot(2,6,4)
- # plt.bar(Xs,Ys,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(Xs,fontsize = 1.5)
- # plt.subplot(2,6,10)
- # plt.plot(uniqueES,countsES)
- #
- # image2 = image
- # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,np.log(image2))
- # image2[image < x1] = 0
- # image2[image > x2] = 255
- # image2[image2 < 0] = 0
- # image2[image2 > 255] = 255
- # XL,YL,uniqueEL,countsEL = Histogram(image2,iloscP)
- # plt.subplot(2,6,5)
- # plt.bar(XL,YL,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(XL,fontsize = 1.5)
- # plt.subplot(2,6,11)
- # plt.plot(uniqueEL,countsEL)
- #
- # image2 = image
- # image2 = np.where(np.logical_or(image < x1 , image > x2),image2,image2 ** a)
- # image2[image < x1] = 0
- # image2[image > x2] = 255
- # image2[image2 < 0] = 0
- # image2[image2 > 255] = 255
- # Xpa,Ypa,uniqueEPA,countsEPA = Histogram(image2,iloscP)
- # plt.subplot(2,6,6)
- # plt.bar(Xpa,Ypa,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(Xpa,fontsize = 1.5)
- # plt.subplot(2,6,12)
- # plt.plot(uniqueEPA,countsEPA)
- #
- #
- #
- #
- # plt.savefig("graph.svg")
- # plt.show()
- # image = np.array(plt.imread("kierowca.jpg"))
- # image2 = image[:,:,2]
- # mean = np.mean(image)
- #
- #
- # cumulativeSumCounts = np.cumsum(Y)
- # cumulativeSumCounts = cumulativeSumCounts / np.size(image2)
- #
- # indexMIN = np.where(cumulativeSumCounts > 0)[0][0]
- # valMin = cumulativeSumCounts[indexMIN]
- # newX = []
- # for x, y in zip(X,cumulativeSumCounts):
- # newX.append(((y - valMin) / (1 - valMin) ) * iloscP)
- # print(newX)
- # unique_elements, counts_elements = np.unique(image2, return_counts=True)
- # cumulativeSumCounts = np.cumsum(counts_elements)
- # for x,y in zip(unique_elements,cumulativeSumCounts):
- # image2[image2 == x] = ((y - min(cumulativeSumCounts)) * 255)/ (np.size(image2))
- # X,Y,uniqueE,countsE = Histogram(image2,iloscP)
- # plt.bar(X,Y,width = zakres,edgecolor='red',align = "edge")
- # plt.xticks(X,fontsize = 10)
- # plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement