Papers
Topics
Authors
Recent
Search
2000 character limit reached

RulerNet: Deep Learning for Scale Estimation

Updated 6 July 2026
  • RulerNet is a deep learning framework that converts pixel measurements from diverse, unconstrained ruler images into accurate real-world dimensions by detecting centimeter marks.
  • It utilizes a distortion-invariant geometric-progression representation to model perspective effects, avoiding brittle OCR and fixed threshold methods.
  • The system leverages a scalable synthetic data pipeline and a fast DeepGP module to achieve robust, real-time scale estimation in challenging imaging conditions.

RulerNet is a deep learning framework for converting pixel measurements into absolute real-world dimensions from rulers appearing in unconstrained images. It was introduced in "Reading a Ruler in the Wild" (Pan et al., 9 Jul 2025) as a system that reframes ruler reading as centimeter-mark keypoint detection, couples those detections to a one-dimensional geometric-progression representation of perspective-distorted ruler spacing, and augments real training data with a scalable synthetic pipeline that combines graphics-based generation with ControlNet-guided photorealism. The framework is designed for settings in which rulers vary in design, material, viewpoint, and visibility, and in which traditional thresholding- or OCR-based pipelines are brittle.

1. Problem setting and reformulation

RulerNet addresses the problem of estimating pixels-per-centimeter from images containing rulers "in the wild," where ruler appearance may vary across black-on-white and white-on-black designs, transparent substrates, missing millimeter ticks, oblique viewpoints, clutter, and partial occlusion. In this setting, conventional pipelines typically segment a ruler and then either threshold intensity peaks, count mark frequencies under assumptions such as constant millimeter spacing, or rely on digit OCR. The reported limitation of such pipelines is that they are brittle to illumination, mark style, and geometric distortion, and generalize poorly when ruler layouts depart from the assumptions built into the pipeline (Pan et al., 9 Jul 2025).

RulerNet replaces these rigid, ruler-specific procedures with unified keypoint detection of centimeter marks. Annotators click only the centimeter marks, and supervision is generated as a probabilistic heatmap by placing a two-dimensional Gaussian at each annotated click. This supervision is described as distortion-invariant because perspective distortion and overall scale do not change the semantic target being annotated: the centimeter marks themselves. A plausible implication is that the annotation protocol shifts the burden of invariance from handcrafted post-processing to learned visual localization.

The framework therefore treats ruler reading primarily as a localization problem rather than as a sequence of thresholding, OCR, and counting subroutines. At inference, it extracts centimeter-mark proposals from the predicted heatmap, groups them onto a dominant line using a Hough transform, projects them to a one-dimensional ruler axis, and estimates scale from the resulting ordered mark positions. This design is explicitly intended to avoid reliance on millimeter-frequency cues or visible numerals.

2. Geometric-progression representation of perspective-distorted rulers

After two-dimensional centimeter marks are detected and assigned to a ruler line, RulerNet projects all points onto that line to obtain one-dimensional coordinates {mi}\{m_i\}. The ruler is then represented by three geometric-progression parameters: m0m_0, m1m_1, and rr, where m0m_0 and m1m_1 are the first two mark positions on the projected axis and rr is the geometric ratio between consecutive spacings (Pan et al., 9 Jul 2025).

If Δi\Delta_i denotes the spacing between successive centimeter marks, the model assumes

Δi=mi+1mi\Delta_i = m_{i+1} - m_i

and

Δi+1=rΔi.\Delta_{i+1} = r \Delta_i .

Equivalently,

m0m_00

where m0m_01 denotes Euclidean distance and reduces to absolute difference after projection to one dimension. Given m0m_02, m0m_03, and m0m_04, the full one-dimensional mark sequence is generated by the recurrence

m0m_05

and

m0m_06

The theoretical motivation is projective geometry. Under an ideal pinhole camera, equally spaced world marks indexed by integer m0m_07 map to image coordinate

m0m_08

The adjacent image spacings are then

m0m_09

so spacing varies along the ruler under perspective. Over limited spans and typical scenes, RulerNet states that this variation is well approximated by a geometric progression, which motivates the constant-m1m_10 model. The paper further notes that cross-ratio invariance explains why perspective-rescaled intervals can be captured by a low-parameter one-dimensional model, even though the method does not explicitly fit a homography or enforce cross-ratios. A common misconception is therefore that RulerNet performs full projective reconstruction; it instead uses a one-dimensional surrogate that empirically fits projected ruler marks.

3. Detection, grouping, and scale estimation

The dense predictor in RulerNet uses a MobileNetV4 backbone with a U-Net decoder and a m1m_11 input resolution. Its targets are Gaussian heatmaps centered at annotated centimeter clicks. The training loss combines cross-entropy with a continuous-target Dice loss,

m1m_12

and

m1m_13

The Gaussian variance is chosen so that distinct centimeter Gaussians do not overlap. This is intended to smooth click noise while preserving separation between nearby marks (Pan et al., 9 Jul 2025).

Inference proceeds as a fixed pipeline. First, the dense predictor outputs a mark heatmap. Second, the heatmap is smoothed with a Gaussian and local maxima above threshold m1m_14 are extracted as two-dimensional proposals. Third, a Hough transform groups the proposals into line hypotheses by accumulating votes in m1m_15 bins, detecting peaks at or above m1m_16 of the maximum accumulator value, and assigning points to the closest detected line when

m1m_17

The line with maximum support is selected, although the implementation can report per-line scale if multiple rulers are present. Fourth, points on the selected line are projected to one dimension and sorted. Fifth, the framework estimates m1m_18 either by iterative optimization or by a feed-forward regressor. Sixth, it computes pixels-per-centimeter from the fitted progression.

The iterative baseline fits m1m_19 by minimizing one-dimensional Chamfer distance between the projected detections rr0 and a GP-generated sequence:

rr1

subject to

rr2

and

rr3

with rr4, rr5, and rr6 measured from adjacent detected neighbors. Differential evolution with the rand1bin strategy and Latin hypercube initialization is used.

To eliminate this iterative stage, RulerNet introduces DeepGP, a custom one-dimensional U-Net with 1.6M parameters that regresses rr7 directly from a noisy set of projected detections:

rr8

The input mark list is min-max normalized to rr9 and capped at 64 points. Output consists of three scalars in normalized one-dimensional coordinates, with no explicit bounds required. The synthetic supervision for DeepGP is generated by sampling m0m_00, constructing the GP sequence, adding Gaussian displacement noise m0m_01, and then randomly dropping marks and inserting distractors.

Once m0m_02 is available, the local pixel-per-centimeter at centimeter index m0m_03 is

m0m_04

so

m0m_05

For a run of m0m_06 centimeters starting at mark m0m_07,

m0m_08

and

m0m_09

In practice, the reported per-image scale is the median of m1m_10 over the largest consistent run of visible centimeter segments.

4. Synthetic data generation and training regime

RulerNet places substantial emphasis on synthetic data because real ruler images are limited. The real dataset, AnyRuler, contains 1,416 annotated web images with diverse rulers and an 80/20 train/test split. The synthetic component consists of two sources: an on-the-fly graphics-based ruler generator and a ControlNet-enhanced realism stage (Pan et al., 9 Jul 2025).

The graphics-based generator randomizes background source from ImageNet, perspective tilt, random overlay shapes and lines, ruler rectangle fill and edge color, transparency, size, thickness, position, mark frequency and type, tick lengths and colors, fonts and placements for labels, and auxiliary side marks. Perspective tilt is controlled by tilt_factor_horizontal and tilt_factor_vertical. The generator produces exact centimeter-mark ground truth, which makes it suitable for supervised heatmap training.

ControlNet is used as a frozen pre-trained model guided by the Canny edge map of the graphics-generated ruler image and a structured text prompt. The prompt deliberately uses the word rectangle rather than ruler to avoid hallucinated extra rulers: “a {visual_appearance} {material} rectangle with clear {mark_appearance} marks on {background}”. Prompt variables are sampled from curated lists that include materials such as plastic, wood, metal, glass, and rubber; visual appearance categories such as reflective, transparent, opaque, matte, glossy, and textured; mark appearance categories such as engraved, printed, and laser-etched; and backgrounds such as wooden desk, paper, blackboard, concrete, glass table, marble countertop, fabric, grass, sand, water, carpet, tile, painted wall, digital screen, sky, blurred background, and none. The stated purpose is to gain material, illumination, and contextual diversity while preserving the geometry and labels inherited from the graphics stage.

The main detector is trained for 200 epochs with AdamW, base learning rate m1m_11, cosine annealing, and 10% linear warmup. Pretraining uses 80 epochs on 4m1m_12A40 at base learning rate m1m_13. The reported best generalization comes from pretraining on 102,000 ControlNet-generated images, 102,000 graphics-generated images, and the AnyRuler training set, followed by fine-tuning with mixed synthetic data. The implementation uses Python 3.9, PyTorch 2.0.1, OpenCV 4.8.1, scikit-learn 1.5.2, and NumPy 1.26.4, with training on NVIDIA A40 GPUs. Peak extraction and Hough grouping are implemented in PyTorch for batched GPU execution.

DeepGP is trained separately at much larger scale: 1.23 billion synthetic samples with batch size 1,024. The paper states that this scale is intended to ensure exhaustive coverage of GP configurations and noise conditions. A plausible implication is that the robustness of the scale-estimation module is being learned primarily from synthetic combinatorics rather than from the modest size of real ruler datasets.

5. Empirical results and ablations

Evaluation is reported on AnyRuler and on Rulers2023, a set of 654 test images distinct from training. In AnyRuler, ground-truth pixels-per-centimeter is defined as the median spacing across adjacent centimeter marks of the longest run. In Rulers2023, a line is annotated along centimeter marks for each ruler and its absolute length is labeled; the image-level pixels-per-centimeter is taken from the longest ruler. The metric is mean absolute pixel error per centimeter scaled to a base resolution m1m_14:

m1m_15

where m1m_16 is predicted pixels-per-centimeter, m1m_17 is ground truth, and m1m_18 is image size. If a method fails to detect scale, predicted pixels-per-centimeter is set to m1m_19 (Pan et al., 9 Jul 2025).

Method AnyRuler Rulers2023
Digits Detection rr0 rr1
Mark Frequency rr2 rr3
RulerNet-GP rr4 rr5
RulerNet-DeepGP rr6 rr7

Runtime is also reported. Digits Detection requires 1530.62 ms per image, RulerNet-GP 2516.87 ms, and RulerNet-DeepGP 42.18 ms end-to-end on a V100. For the scale-estimation module alone, direct adjacent averaging takes 16.99 ms, median-based filtering 16.08 ms, GP optimization 2497.33 ms, and DeepGP 22.61 ms. The paper states that DeepGP is more than 100rr8 faster than optimization while improving accuracy.

Ablations indicate that input-resolution gains saturate: for a direct variant, AnyRuler/Rulers2023 performance is 2.88/9.77 at 512, 1.53/4.43 at 768, 1.76/2.82 at 1024, and 1.82/2.85 at 1280. The reported interpretation is that very high input resolution does not help low-resolution sources. Synthetic quantity also matters. With graphics-only data at 100, 1,000, and 2,000 generated images per epoch, performance changes from 1.70/4.43 to 1.55/4.06 to 1.55/3.48; with ControlNet-enhanced data, it changes from 1.67/4.36 to 1.58/3.56 to 1.64/2.94. When synthetic sources are combined, the sequence reported is base 1.53/4.43, +Graphics 1.55/4.06, +ControlNet 1.58/3.56, +Both 1.61/2.87, and +Both +Pretraining (102k + 102k) 1.50/1.82. The stated conclusion is that generative synthetic data improves cross-domain generalization more strongly than graphics alone, and that large-scale pretraining followed by mixed fine-tuning yields the best overall generalization.

Qualitative observations align with the quantitative findings. RulerNet is reported to remain accurate under severe perspective and in cases where mark color nearly matches the substrate, and the GP model is said to recover full rulers and correct residual detection noise. OCR-based methods reportedly fail when digits are missing, occluded, or stylized, while mark-frequency pipelines struggle on cluttered backgrounds and nonstandard tick patterns.

6. Limitations, deployment characteristics, and applications

RulerNet is not a general solution to metric reconstruction from arbitrary scenes. Its GP model assumes straight, rigid rulers, so flexible tapes and curved rulers are out of scope. Radial lens distortion is not modeled, although pre-calibration is noted as a possible mitigation. The method returns image-plane pixels-per-centimeter and assumes that the object of interest lies near the ruler plane; out-of-plane offsets introduce errors. Perspective effects orthogonal to the ruler axis are likewise not modeled, which affects off-plane objects. Detection and grouping degrade under extreme occlusion, severe motion blur, very short visible ruler segments, transparent rulers over complex textures, patterns that mimic centimeter marks, and multiple overlapping rulers (Pan et al., 9 Jul 2025).

These limitations are important because they distinguish scale anchoring from full three-dimensional scene understanding. A plausible implication is that RulerNet is best treated as a metric calibration component inside a larger vision pipeline rather than as a standalone geometric reasoning engine. The paper explicitly suggests that future integration with depth or homography estimation could compensate for some of the current two-dimensional and planarity assumptions.

Within its intended operating regime, the framework is positioned as a metric anchor for several application areas. In medical imaging and diagnostics, it can support lesion, wound, and organ size estimation and, when integrated with segmentation, yield per-object metric sizes; the paper notes use within placental assessment pipelines such as AI-PLAX. In forensics, it can calibrate footprint or object size in crime-scene photos. In nutrition and e-commerce, it can support food portion estimation and product dimension display. In three-dimensional understanding, it can help resolve monocular-scale ambiguity by calibrating depth maps near the ruler.

The deployment profile centers on the detector-plus-DeepGP configuration. End-to-end runtime is reported as 42.18 ms per image on a V100, while DeepGP itself is a 1.6M-parameter one-dimensional U-Net and requires about 23 ms for the estimation module. The forward-only design and small parameter count are presented as making the method suitable for mobile or edge devices. A live demo is available at the Hugging Face space listed in the paper, and code and data are stated to be planned for release, with no license specified.

Definition Search Book Streamline Icon: https://streamlinehq.com
References (1)

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to RulerNet.