Skip to content

Commit 04fa3d0

Browse files
committed
Red Proportion - shows the relative proportion of red in the total RGB intensity
1 parent 38f13d7 commit 04fa3d0

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

analyze_color_by_style_range.py

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ def plot_comparison_by_style_range(all_results: dict, output_dir: str):
289289
plt.savefig(output_dir / 'color_analysis_by_style_range_overview.png', dpi=150, bbox_inches='tight')
290290
plt.close()
291291

292-
# 2. RGB Channel Analysis - individual channels as % change
293-
fig, axes = plt.subplots(2, 3, figsize=(18, 10))
292+
# 2. RGB Channel Analysis - individual channels as % change + red proportion
293+
fig, axes = plt.subplots(1, 4, figsize=(20, 5))
294294

295295
rgb_channels = ['R', 'G', 'B']
296296
channel_colors = {'R': '#E63946', 'G': '#06D6A0', 'B': '#118AB2'}
297297

298-
# Row 1: Mean plots for each channel
298+
# Columns 0-2: Mean plots for each channel
299299
for col_idx, channel in enumerate(rgb_channels):
300-
ax = axes[0, col_idx]
300+
ax = axes[col_idx]
301301
for style_range in sorted(all_results.keys()):
302302
results = all_results[style_range]
303303
label = get_style_range_label(style_range)
@@ -314,26 +314,34 @@ def plot_comparison_by_style_range(all_results: dict, output_dir: str):
314314
ax.grid(True, alpha=0.3)
315315
ax.axhline(y=0, color='black', linestyle='-', alpha=0.3, linewidth=1)
316316

317-
# Row 2: Std dev plots for each channel
318-
for col_idx, channel in enumerate(rgb_channels):
319-
ax = axes[1, col_idx]
320-
for style_range in sorted(all_results.keys()):
321-
results = all_results[style_range]
322-
label = get_style_range_label(style_range)
323-
vals = np.array(results[f'rgb_{channel}_std'])
324-
ref_val = vals[ref_idx]
325-
pct_change = (vals / ref_val - 1) * 100
326-
ax.plot(results['alphas'], pct_change,
327-
marker='s', linewidth=2, label=label, color=style_colors[style_range])
317+
# Column 3: Red proportion (R / (R+G+B))
318+
ax = axes[3]
319+
for style_range in sorted(all_results.keys()):
320+
results = all_results[style_range]
321+
label = get_style_range_label(style_range)
328322

329-
ax.set_xlabel('Alpha', fontsize=11)
330-
ax.set_ylabel(f'{channel} Channel Std Dev Change (%)', fontsize=11)
331-
ax.set_title(f'{channel} Channel Variation vs Alpha', fontsize=12, fontweight='bold', color=channel_colors[channel])
332-
ax.legend(fontsize=9)
333-
ax.grid(True, alpha=0.3)
334-
ax.axhline(y=0, color='black', linestyle='-', alpha=0.3, linewidth=1)
323+
r_vals = np.array(results['rgb_R_mean'])
324+
g_vals = np.array(results['rgb_G_mean'])
325+
b_vals = np.array(results['rgb_B_mean'])
326+
327+
# Calculate red proportion
328+
red_proportion = r_vals / (r_vals + g_vals + b_vals)
329+
ref_red_proportion = red_proportion[ref_idx]
330+
331+
# Convert to percentage change
332+
pct_change = (red_proportion / ref_red_proportion - 1) * 100
333+
334+
ax.plot(results['alphas'], pct_change,
335+
marker='D', linewidth=2, label=label, color=style_colors[style_range])
336+
337+
ax.set_xlabel('Alpha', fontsize=11)
338+
ax.set_ylabel('Red Proportion Change (%)', fontsize=11)
339+
ax.set_title('Red Proportion vs Alpha\n(R / (R+G+B))', fontsize=12, fontweight='bold', color='#E63946')
340+
ax.legend(fontsize=9)
341+
ax.grid(True, alpha=0.3)
342+
ax.axhline(y=0, color='black', linestyle='-', alpha=0.3, linewidth=1)
335343

336-
plt.suptitle('RGB Channel Statistics by Style Range (% Change)',
344+
plt.suptitle('RGB Channel Analysis by Style Range (% Change)',
337345
fontsize=16, y=0.995, fontweight='bold')
338346
plt.tight_layout()
339347
plt.savefig(output_dir / 'rgb_analysis_by_style_range.png', dpi=150, bbox_inches='tight')

0 commit comments

Comments
 (0)