From de955494aa177faf91d9c192610fb556db011511 Mon Sep 17 00:00:00 2001 From: zzyyyl Date: Sat, 27 Jul 2024 20:17:46 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E6=9B=B4=E6=96=B0=20mask-range=20?= =?UTF-8?q?=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/MaskRangeTool/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/MaskRangeTool/utils.py b/tools/MaskRangeTool/utils.py index 8a19bb83f7..ddd5fee983 100644 --- a/tools/MaskRangeTool/utils.py +++ b/tools/MaskRangeTool/utils.py @@ -27,7 +27,7 @@ def calc_mask_from_ranges(image, mask_ranges, color=None): return mask -def show_image_mask(image, mask, color): +def show_image_mask(image, mask, color, hist_mask=None): if color.lower() == 'hsv': image_for_hist = cv2.cvtColor(image, cv2.COLOR_BGR2HSV) elif color.lower() == 'rgb': @@ -39,9 +39,9 @@ def show_image_mask(image, mask, color): fig, axs = plt.subplots(2, 3, figsize=(15, 8)) - hist_0 = cv2.calcHist([image_for_hist], [0], None, [256], [0, 256]) - hist_1 = cv2.calcHist([image_for_hist], [1], None, [256], [0, 256]) - hist_2 = cv2.calcHist([image_for_hist], [2], None, [256], [0, 256]) + hist_0 = cv2.calcHist([image_for_hist], [0], hist_mask, [256], [0, 256]) + hist_1 = cv2.calcHist([image_for_hist], [1], hist_mask, [256], [0, 256]) + hist_2 = cv2.calcHist([image_for_hist], [2], hist_mask, [256], [0, 256]) axs[0, 0].plot(hist_0, color='r') axs[0, 0].set_title('Channel 0 Histogram') @@ -116,7 +116,7 @@ def generate_mask_ranges(image, color, base_mask_ranges=None, thresholds=None): mask = cv2.bitwise_or(mask, cv2.inRange(image_for_mask, (l0, l1, l2), (u0, u1, u2))) print(f'Recommand {color.upper()} Mask Range: {mask_ranges}') - show_image_mask(image, mask, color) + show_image_mask(image, calc_mask_from_ranges(image, mask_ranges, color), color, base_mask) def compare_2_image_with_mask_ranges(image1, image2, mask_ranges, color):