Create a single-page web application that accepts a black-on-white raster image and generates a visually similar binary image satisfying minimum physical dimensions for:
Black strokes and regions
White gaps, holes, and separating channels
The application runs entirely in the browser. It generates a set of valid candidate images using controlled morphological operations, blurs each candidate and the original image at one or more scales, and selects the candidate whose blurred appearance most closely matches the original.
The first version exports a binary PNG only.
2. Primary design principle
The application treats minimum black and white widths as hard geometric constraints.
Among candidate images satisfying those constraints, it selects the image that best preserves the visual impression of the original after blur.
The primary optimization objective is therefore:
[
L_{\mathrm{blur}}(X,O)
\sum_i \alpha_i
\left|
G_{\sigma_i} * X
G_{\sigma_i} * O
\right|^2
]
where:
(O) is the original binary image.
(X) is a valid candidate image.
(G_{\sigma_i}) is a Gaussian blur at scale (\sigma_i).
(\alpha_i) is the weight assigned to that blur scale.
The blur suppresses unsupported fine detail and compares the original and candidate at the scales most relevant to the final physical output.
3. User workflow
Upload a raster image.
Enter:
Image DPI
Minimum black width in millimeters
Minimum white width in millimeters
Adjust optional controls:
Binary threshold
Blur comparison scale
Simplification strength
Preference for preserving black strokes or white gaps
Click Generate.
Review:
Original binary image
Best candidate
Blurred original
Blurred candidate
Constraint-violation overlay
Difference map
Optionally compare several top-ranked candidates.
Download the selected result as a binary PNG.
All processing remains local to the browser.
4. Physical scale conversion
The application converts the user’s millimeter requirements to pixels:
[
d_{\mathrm{px}}
Assistant
Implemented the complete MINWIDTH single-page application.
Included
Raster upload, transparency compositing, grayscale conversion, Otsu/manual thresholding, and inversion
DPI and millimeter-to-pixel constraint conversion
Disk-based morphology using Euclidean distance transforms
Black-preserving, white-preserving, and balanced candidate families
Skeleton-style independent black/white width validation with endpoint handling
Multi-scale Gaussian-approximated blur scoring with artwork-weighted evaluation
Changed-area, black-mass, and topology penalties
Responsive Web Worker processing with progress and cancellation
Synchronized pan/zoom previews
Original, binary, result, blur, difference, width, and change diagnostics
Ranked valid candidate strip with width and topology metrics
Strictly binary PNG export enabled only for validated candidates
Built-in synthetic demo artwork
Primary implementation files:
src/App.tsx
src/processing.worker.ts
src/components/CanvasStage.tsx
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Rounding upward is recommended so the output does not fall below the requested physical size.
5. Input normalization
After upload, the application:
Decodes the image.
Composites transparency over white.
Converts the image to grayscale.
Applies either:
A user-selected threshold, or
Automatic thresholding
Produces a strictly binary black-and-white source mask.
Adds a temporary white border for analysis.
Determines an artwork bounding box plus margin for loss evaluation.
The threshold should remain adjustable because the inferred source geometry can strongly affect the result.
6. Candidate-generation strategy
The application does not initially attempt arbitrary pixel-level optimization.
Instead, it generates a limited family of candidate images using morphology and local repair operations at scales related to the minimum black and white widths.
6.1 Black-preserving candidates
These candidates favor retaining original black structures:
Thicken thin black strokes.
Dilate black regions locally.
Close small breaks.
Join nearby black regions where the intervening white gap cannot remain valid.
Remove only very small unsupported branches or components.
6.2 White-preserving candidates
These candidates favor retaining white separation:
Widen narrow white channels.
Erode adjacent black boundaries.
Split thin black bridges.
Preserve white holes where possible.
Remove black details that cannot coexist with the white minimum.
6.3 Balanced candidates
These candidates apply moderate repairs to both classes:
Morphological opening and closing at several radii.
Opening or closing by reconstruction where available.
Alternating black and white repair passes.
Local boundary smoothing.
Small-component and small-hole cleanup.
6.4 Candidate parameter variations
Candidate families should vary:
Structuring-element radius
Number of repair passes
Black-versus-white priority
Thickening-versus-deletion preference
Gap-filling-versus-gap-widening preference
Boundary smoothing strength
A first version might generate 20–100 candidates rather than performing an open-ended iterative search.
7. Width validation
Every candidate must be checked independently for minimum black and white local width.
For each class:
Compute the Euclidean distance transform.
Compute a medial axis or skeleton.
Associate each skeleton point with the distance-transform value.
Estimate local width as:
[
W(p)=2D(p)
]
A candidate is valid only when:
[
W_B(p) \ge d_B
]
for all relevant black skeleton points, and:
[
W_W(p) \ge d_W
]
for all relevant white skeleton points.
A small numerical tolerance may be allowed for raster discretization.
Endpoint treatment
Rounded stroke endpoints naturally taper toward a point. The application should avoid rejecting an otherwise valid stroke solely because of its terminal cap.
The first implementation may:
Exclude a short terminal skeleton segment from strict width validation, or
Evaluate the maximum inscribed width associated with the endpoint branch.
This rule must be applied consistently and shown in diagnostics.
8. Blurred similarity scoring
Only valid candidates are ranked.
For each valid candidate:
Blur the original binary image.
Blur the candidate using the same kernel.
Compare the blurred images within the artwork evaluation region.