From 962f88c65f2b527549f1dd9f59a95f6f7d6ead53 Mon Sep 17 00:00:00 2001 From: FEIJINTI <83849113+FEIJINTI@users.noreply.github.com> Date: Tue, 14 Mar 2023 11:29:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=9B=B4=E6=96=B9?= =?UTF-8?q?=E5=9B=BE=E9=80=89=E7=82=B9=E5=8A=9F=E8=83=BD=EF=BC=88=E6=9C=AA?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hist.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 hist.py diff --git a/hist.py b/hist.py new file mode 100644 index 0000000..388234e --- /dev/null +++ b/hist.py @@ -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])) +