summaryrefslogtreecommitdiffstats
path: root/Scripts/gaussianize
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts/gaussianize')
-rwxr-xr-xScripts/gaussianize36
1 files changed, 29 insertions, 7 deletions
diff --git a/Scripts/gaussianize b/Scripts/gaussianize
index 620e05d..f997b8a 100755
--- a/Scripts/gaussianize
+++ b/Scripts/gaussianize
@@ -410,20 +410,38 @@ def histogram_preserving_blend(
def verify_histogram(image_path: Path, output_path: Path):
- """Generate a minimal RGB histogram verification figure."""
+ """Generate the original image with an RGB histogram chart beneath it."""
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
+ from matplotlib.ticker import MultipleLocator
img = load_image(image_path)
-
- fig = plt.figure(figsize=(4.0, 2.0), facecolor='#bcbcbc')
- plot_ax = fig.add_axes((0.0, 0.0, 1.0, 1.0))
+ h, w, _ = img.shape
+ quantization_step = 0.0 if image_path.suffix.lower() == ".exr" else (1.0 / 255.0)
+
+ # Chart is the full image width, with height proportional to the image
+ chart_height_ratio = 0.25
+ total_height_ratio = 1.0 + chart_height_ratio
+ fig_w = max(w, 2048) / 180.0
+ fig_h = fig_w * total_height_ratio * (h / w)
+
+ fig = plt.figure(figsize=(fig_w, fig_h), facecolor='#bcbcbc')
+
+ # Original image on top
+ img_ax = fig.add_axes((0.0, chart_height_ratio / total_height_ratio, 1.0, 1.0 / total_height_ratio))
+ img_ax.imshow(np.clip(img, 0.0, 1.0))
+ img_ax.set_axis_off()
+
+ # Histogram chart on bottom
+ left_margin = 0.06
+ right_margin = 0.02
+ bottom_margin = 0.04
+ chart_top = chart_height_ratio / total_height_ratio
+ plot_ax = fig.add_axes((left_margin, bottom_margin, 1.0 - left_margin - right_margin, chart_top - bottom_margin))
plot_ax.set_facecolor('#bcbcbc')
for spine in plot_ax.spines.values():
spine.set_visible(False)
- plot_ax.set_xticks([])
- plot_ax.set_yticks([])
kernel = np.array([1.0, 2.0, 3.0, 2.0, 1.0], dtype=np.float64)
kernel /= kernel.sum()
@@ -431,7 +449,8 @@ def verify_histogram(image_path: Path, output_path: Path):
colors = ('#ff1a1a', '#00aa22', '#003cff')
for channel, color in enumerate(colors):
- hist, edges = np.histogram(img[:, :, channel].ravel(), bins=512, range=(0.0, 1.0), density=True)
+ data = dither_channel(img[:, :, channel], quantization_step, channel)
+ hist, edges = np.histogram(data.ravel(), bins=512, range=(0.0, 1.0), density=True)
hist = np.convolve(hist, kernel, mode='same')
centers = 0.5 * (edges[:-1] + edges[1:])
curve_max = max(curve_max, float(hist.max()))
@@ -439,6 +458,9 @@ def verify_histogram(image_path: Path, output_path: Path):
plot_ax.set_xlim(0.0, 1.0)
plot_ax.set_ylim(0.0, curve_max * 1.18 if curve_max > 0.0 else 1.0)
+ plot_ax.xaxis.set_major_locator(MultipleLocator(0.1))
+ plot_ax.tick_params(axis='x', labelsize=5, length=2, pad=1)
+ plot_ax.set_yticks([])
fig.savefig(output_path, dpi=180, facecolor=fig.get_facecolor(), edgecolor='none')
plt.close(fig)
print(f"Saved histogram to {output_path}")