Updated colourspace
This commit is contained in:
parent
5fae9c9a0d
commit
2f39bb9808
@ -6,13 +6,24 @@ def imgStats(img):
|
|||||||
mean = np.zeros(3)
|
mean = np.zeros(3)
|
||||||
std = np.zeros(3)
|
std = np.zeros(3)
|
||||||
for i in range(img.shape[2]):
|
for i in range(img.shape[2]):
|
||||||
mean[i] = np.mean(hsv_img[:, :, i])
|
mean[i] = np.mean(img[:, :, i])
|
||||||
std[i] = np.std(hsv_img[:, :, i])
|
std[i] = np.std(img[:, :, i])
|
||||||
return mean, std
|
return mean, std
|
||||||
|
|
||||||
DATASET_PATH = "C:\\Users\\Tom\\Desktop\\Files\\Repositories\\snake-vault\\TREES\\dataset\\"
|
def histNormalize(hist):
|
||||||
|
max_val = np.amax(hist)
|
||||||
|
min_val = np.amin(hist)
|
||||||
|
for i in range(len(hist)):
|
||||||
|
hist[i][0] = (hist[i][0] - min_val)/(max_val - min_val)
|
||||||
|
|
||||||
|
|
||||||
|
# DATASET_PATH = "C:\\Users\\Tom\\Desktop\\Files\\Repositories\\snake-vault\\TREES\\dataset\\"
|
||||||
|
# full_img = cv2.imread(DATASET_PATH + "alder\\1.jpg", 1)
|
||||||
|
|
||||||
|
DATASET_PATH = "..\\..\\..\\res\\trees\\"
|
||||||
|
full_img = cv2.imread(DATASET_PATH + "berk_sq1_original.png", 1)
|
||||||
|
assert full_img is not None, "Path is wrong"
|
||||||
|
|
||||||
full_img = cv2.imread(DATASET_PATH + "alder\\1.jpg", 1)
|
|
||||||
bgr_img = cv2.resize(full_img, (0, 0), fx=0.25, fy=0.25)
|
bgr_img = cv2.resize(full_img, (0, 0), fx=0.25, fy=0.25)
|
||||||
hsv_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)
|
hsv_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)
|
||||||
|
|
||||||
@ -22,17 +33,33 @@ hsv_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)
|
|||||||
# cv2.imshow('HSV - S',hsv_img[:, :, 1])
|
# cv2.imshow('HSV - S',hsv_img[:, :, 1])
|
||||||
# cv2.imshow('HSV - V',hsv_img[:, :, 2])
|
# cv2.imshow('HSV - V',hsv_img[:, :, 2])
|
||||||
|
|
||||||
|
print("BGR")
|
||||||
|
mean, std = imgStats(bgr_img)
|
||||||
|
print(mean)
|
||||||
|
print(std)
|
||||||
|
print()
|
||||||
|
|
||||||
|
hist = cv2.calcHist([bgr_img], [0], None, [256], [0,256])
|
||||||
|
plt.plot(hist, label='B', c='b')
|
||||||
|
hist = cv2.calcHist([bgr_img], [1], None, [256], [0,256])
|
||||||
|
plt.plot(hist, label='G', c='g')
|
||||||
|
hist = cv2.calcHist([bgr_img], [2], None, [256], [0,256])
|
||||||
|
plt.plot(hist, label='R', c='r')
|
||||||
|
plt.grid()
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
print("HSV")
|
||||||
|
mean, std = imgStats(hsv_img)
|
||||||
|
print(mean)
|
||||||
|
print(std)
|
||||||
|
|
||||||
hist = cv2.calcHist([hsv_img], [0], None, [256], [0,256])
|
hist = cv2.calcHist([hsv_img], [0], None, [256], [0,256])
|
||||||
plt.plot(hist, label='H')
|
plt.plot(hist, label='H')
|
||||||
hist = cv2.calcHist([hsv_img], [1], None, [256], [0,256])
|
hist = cv2.calcHist([hsv_img], [1], None, [256], [0,256])
|
||||||
plt.plot(hist, label='S')
|
plt.plot(hist, label='S')
|
||||||
hist = cv2.calcHist([hsv_img], [2], None, [256], [0,256])
|
hist = cv2.calcHist([hsv_img], [2], None, [256], [0,256])
|
||||||
plt.plot(hist, label='V')
|
plt.plot(hist, label='V')
|
||||||
|
|
||||||
mean, std = imgStats(hsv_img)
|
|
||||||
print(mean)
|
|
||||||
print(std)
|
|
||||||
|
|
||||||
plt.grid()
|
plt.grid()
|
||||||
plt.legend()
|
plt.legend()
|
||||||
plt.show()
|
plt.show()
|
||||||
|
Loading…
Reference in New Issue
Block a user