Created
January 26, 2026 19:39
-
-
Save atadams/2e9b1e5abc3a93bb7b966b6b0de76520 to your computer and use it in GitHub Desktop.
GreenChannel14bit.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import rawpy | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import os | |
| def run_14bit_audit(src_path, label, color, out_dir): | |
| if not os.path.exists(src_path): | |
| print(f"Directory not found: {src_path}") | |
| return | |
| files = [f for f in os.listdir(src_path) if f.lower().endswith('.cr2')] | |
| os.makedirs(out_dir, exist_ok=True) | |
| for filename in files: | |
| img_path = os.path.join(src_path, filename) | |
| try: | |
| with rawpy.imread(img_path) as raw: | |
| # 1. 14-bit Extraction: No post-processing, no 'smearing' | |
| raw_data = raw.raw_image_visible.astype(np.float32) | |
| # 2. Isolate Green Channel (The High-Fidelity Noise Test) | |
| # High-frequency Photoshop noise fails this hardware-level check. | |
| green_mask = np.zeros(raw_data.shape, dtype=bool) | |
| green_mask[0::2, 1::2] = True | |
| green_mask[1::2, 0::2] = True | |
| green_channel = raw_data[green_mask] | |
| # 3. Create the 14-bit Forensic Plot | |
| plt.figure(figsize=(10, 6)) | |
| plt.hist( | |
| green_channel, | |
| bins=np.arange(0, 16385, 32), | |
| color=color, | |
| alpha=0.7, | |
| log=True | |
| ) | |
| # Hardware Reference (Anchor) | |
| bl = raw.black_level_per_channel[0] | |
| plt.axvline( | |
| x=bl, | |
| color='black', | |
| linestyle='--', | |
| label=f'Hardware Black Level ({bl})' | |
| ) | |
| plt.title(f"Forensic Audit [{label}]: {filename}") | |
| plt.xlabel("Raw Sensor Signal (0-16383)") | |
| plt.ylabel("Pixel Frequency (Log Scale)") | |
| plt.legend() | |
| plt.grid(True, which="both", alpha=0.1) | |
| # Save with prefix to prevent overwriting across folders | |
| save_filename = f"{label}_{os.path.splitext(filename)[0]}.png" | |
| save_path = os.path.join(out_dir, save_filename) | |
| plt.savefig(save_path) | |
| plt.close() | |
| print(f"[✓] Saved: {save_path}") | |
| except Exception as e: | |
| print(f"[!] Error on {filename}: {e}") | |
| # Execution targeting your specific drive paths | |
| output_folder = "Set your target output folder here" | |
| run_14bit_audit("Authentic CR2 Folder", "Authentic", "blue", output_folder) | |
| run_14bit_audit("Jonas images folder", "Jonas", "red", output_folder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment