Skip to content

scan2rew: Extract MIC Calibration Curve (for REW) from Scan

License

Notifications You must be signed in to change notification settings

tritolol/scan2rew

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

scan2rew: Extract MIC Calibration Curve (for REW) from Scan

Example input scan

Turn a scanned, printed microphone calibration chart into a usable CSV for Room EQ Wizard (REW).

Why This Exists

  • I bought a "the t.bone MM-1 Measuring Microphone" from Thomann. It’s inexpensive and (unlike some Behringer units) it comes with an individual calibration curve.
  • The catch: the curve is only provided on paper, which is useless for software workflows like REW without digitizing it.
  • This tool lets you scan that sheet (or take a photo), process the image through an interactive pipeline, trace the plotted line, and export a REW-friendly CSV.

Features

  • Interactive pipeline UI: add, remove, reorder, and tweak processing steps.
  • Robust image ops: crop, thresholding, adaptive thresholding, morphology (dilate/erode), blur, unsharp mask, Sobel edges.
  • Curve tracing: extracts a single black curve and maps image coordinates to frequency/dB with adjustable axis scales.
  • REW export: writes Frequency_Hz,dB CSV for direct use in REW as a mic calibration file.
  • Flexible to real-world scans: handles different scanners, resolutions, mild skew, and lighting with parameter tuning.
  • Import/export pipeline JSON so you can share and iterate on what works for your scans.

Getting Started

Requirements

  • Python 3.8+
  • Packages: numpy, Pillow (Tkinter is bundled with most Python installs on Windows/macOS; on some Linux distros you may need python3-tk).

Install deps:

  • pip install numpy pillow

Run

  • GUI with optional image path: python scan2rew.py path/to/your_scan.png
  • GUI picker (no args): python scan2rew.py
  • Non‑GUI (headless) CSV export: python scan2rew.py <image> <pipeline.json> <out.csv>

Recommended input: a reasonably straight, cropped image focusing on the chart area. Higher resolution (e.g., 300–600 DPI) helps.

CLI (Headless) Mode

Run the pipeline without opening the UI and write a REW CSV.

Usage

  • python scan2rew.py <image> <pipeline.json> <out.csv>

Behavior

  • Loads the image as grayscale and applies the given pipeline JSON.
  • Requires the pipeline to include "Trace to Graph" with sensible axis settings.
  • Writes Frequency_Hz,dB rows to <out.csv>.

Example

  • python scan2rew.py example/Scan01.JPG default_pipeline.json example/Scan01_REW.csv

Workflow

  1. Scan the sheet or take a high-quality photo and save as PNG/TIFF/JPG.
  2. Open it in the app (scan2rew.py). The left panel is your pipeline, the center shows step parameters, and the canvas previews Original vs Processed.
  3. Add and tune steps until the chart’s curve becomes a clean single-pixel-ish dark trace across all columns (no gaps).
  4. Add the "Trace to Graph" step last. Tune its parameters and axis mapping so the traced line covers the full width/height range.
  5. Once tracing succeeds, the "Save REW CSV" button becomes enabled. Click it to export.

Key Steps You’ll Likely Use

  • Threshold / Adaptive Threshold: isolate the line from the background grid/paper.
  • Morphology (Dilate/Erode): thicken and then clean the line, or remove noise.
  • Gaussian Blur + Unsharp Mask: smooth jaggies and enhance edges before thresholding.
  • Trace to Graph: turns the processed image into a mapped (freq, dB) series.

Trace to Graph Parameters

  • invert: flip black/white if the curve is light on dark.
  • smooth: moving average over the traced y to reduce noise.
  • stroke: thickness of the rendered trace overlay.
  • f_min, f_max: frequency span (use log scale for typical mic charts).
  • db_min, db_max: dB span matching your chart’s Y axis labels.
  • x_scale: log or linear based on the chart’s X axis.
  • y_origin: bottom if higher on the page is higher dB (most charts), otherwise top.

When tracing succeeds, every image column must contain at least one dark pixel on the processed image (the app enforces this and will warn if there are gaps). If you see gaps, adjust earlier steps.

Exporting for REW

  • Use the "Save REW CSV" button. The file has a header and two columns:
    • Frequency_Hz, dB
  • Load this file in REW as your microphone calibration. Verify the range + polarity make sense by comparing with the printed curve.

Example Pipeline (the one that worked for me)

Included default_pipeline.json replicates a working setup on my scan of the t.bone MM‑1 sheet. As a starting point:

  • Morphology: Dilate, k=3
  • Morphology: Erode, k=5
  • Gaussian Blur: radius=2.0
  • Threshold: t≈164, invert=false
  • Trace to Graph: smooth≈1.6, x_scale=log, y_origin=bottom (adjust f_min/f_max and db_min/db_max to match your chart labels)

Import this via "Import pipeline (JSON)", then tweak to your scan.

Example: Process Scan01.JPG with the Default Pipeline

This repo includes a default pipeline (in default_pipeline.json) that uses the new Crop step first, followed by morphological cleanup, blur, threshold, and tracing.

Steps

  • Run: python scan2rew.py example/Scan01.JPG
  • Click "Import pipeline (JSON)" and select default_pipeline.json.
  • In the Step Parameters, adjust Crop (left, top, right, bottom) so the chart’s axes and curve fill the processed pane without margins.
  • Verify thresholded output shows a continuous dark trace across all columns. If needed, tweak Morphology/Blur/Threshold.
  • In "Trace to Graph": set x_scale=log, y_origin=bottom, and adjust f_min/f_max (e.g., 20–20000 Hz) and db_min/db_max to match the printed chart.
  • Click "Save REW CSV" and save as example/Scan01_REW.csv.

Open the CSV in REW as the mic calibration file and visually confirm it matches the printed curve.

Tips

  • Crop before processing so the curve occupies most of the image width/height.
  • Remove color if your scan is tinted; the app converts to grayscale internally but neutral scans help.
  • If the grid overwhelms the curve, try slight blur → threshold, or adaptive threshold with a suitable window size.
  • If traced output looks flipped vertically, toggle y_origin. If frequencies look wrong, switch x_scale or adjust f_min/f_max.

Files in This Repo

  • scan2rew.py: the interactive processing app (also supports headless CLI).
  • default_pipeline.json: default pipeline that worked on the included example.
  • example/: sample inputs and outputs (e.g., example/Scan01.JPG, example/Scan01_REW.csv).

Roadmap / Ideas

  • Add explicit crop/deskew tools in-app.
  • Add grid removal helpers and color channel selection.
  • Add optional multi-curve separation (if charts include multiple lines).

License

  • MIT — see LICENSE for details.

Acknowledgements

  • Built to digitize the t.bone MM‑1 paper calibration chart for use in REW. Should be adaptable to similar charts from other microphones.

About

scan2rew: Extract MIC Calibration Curve (for REW) from Scan

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages