mirror of
https://github.com/NanjingForestryUniversity/supermachine-wood.git
synced 2025-11-08 10:13:53 +00:00
添加了直方图选点功能(未测试)
This commit is contained in:
parent
aee4cf9715
commit
962f88c65f
20
hist.py
Normal file
20
hist.py
Normal file
@ -0,0 +1,20 @@
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
|
||||
img_path = 'data/data1015/middle/rgb0.png'
|
||||
img = cv2.imread(img_path)
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2LAB)
|
||||
x = img.reshape(img.shape[0]*img.shape[1], img.shape[2])
|
||||
hist, bins = np.histogram(x[:, 0], bins=10)
|
||||
hist = hist[1:]
|
||||
bins = bins[1:]
|
||||
hist_number = np.argmax(hist)
|
||||
x = x[(x[:, 0] > bins[hist_number]) & (x[:, 0] < bins[hist_number + 1]), :]
|
||||
mean_value = np.mean(x, axis=0).astype(np.uint8)
|
||||
y = np.zeros((img.shape[0]*img.shape[1], img.shape[2]), dtype=np.uint8)
|
||||
y[:, ] = mean_value
|
||||
#lab转rgb再保存
|
||||
y = cv2.cvtColor(y.reshape(img.shape[0], img.shape[1], img.shape[2]), cv2.COLOR_LAB2BGR)
|
||||
cv2.imwrite('3.png', y.reshape(img.shape[0], img.shape[1], img.shape[2]))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user