draw histogram moved to image_processor.py

This commit is contained in:
Rafał Tłuchowski
2025-01-27 21:35:01 +01:00
parent d96feac94e
commit eefbbe8cdf
2 changed files with 41 additions and 38 deletions
+38
View File
@@ -262,3 +262,41 @@ class ImageProcessor:
)
return image
@staticmethod
def draw_dynamic_histogram(composite: np.ndarray,
input_black: int, input_white: int,
gamma: float) -> np.ndarray:
"""Creates histogram visualization with dynamic control lines"""
# Convert to grayscale for histogram calculation
gray = cv2.cvtColor(composite, cv2.COLOR_RGB2GRAY) if len(composite.shape) == 3 else composite
# Calculate histogram
hist = cv2.calcHist([gray], [0], None, [256], [0, 256])
hist_img = np.zeros((200, 256, 3), dtype=np.uint8)
cv2.normalize(hist, hist, 0, hist_img.shape[0], cv2.NORM_MINMAX)
# Draw histogram baseline
for i in range(1, 256):
cv2.line(hist_img,
(i - 1, 200 - int(hist[i - 1])),
(i, 200 - int(hist[i])),
(128, 128, 128), 1)
# Calculate gamma position
gamma_pos = int(255 * (0.5 ** (1 / gamma)))
# Draw control lines
cv2.line(hist_img, (input_black, 0), (input_black, 200), (255, 0, 0), 2) # Blue - black level
cv2.line(hist_img, (input_white, 0), (input_white, 200), (0, 255, 0), 2) # Green - white level
cv2.line(hist_img, (gamma_pos, 0), (gamma_pos, 200), (255, 255, 255), 2) # White - gamma
# Add legend
cv2.putText(hist_img, f"Black: {input_black}", (10, 20),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 0, 0), 1)
cv2.putText(hist_img, f"White: {input_white}", (10, 40),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)
cv2.putText(hist_img, f"Gamma: {gamma:.2f}", (10, 60),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
return hist_img