01

Patterns that repeat

Many carpets and rugs have patterns that repeat across their surface: medallions, stars, flowers or geometric shapes. Weavers and designers describe the size of the repeat, the distance before the pattern starts again. Measuring repeats helps identify designs, compare rugs and check manufacturing quality.

02

A measuring model

Imagine a computer vision model trained to find the repeat spacing in photographs of carpets. It looks at an image, identifies where the motif repeats, and reports the distance between repeats, in pixels or in millimetres.

03

Cropping images

Large carpet photographs are often cut into smaller pieces, or crops, for training a model. Crops may overlap, so the same knot or motif appears in several pieces. This is useful for training, but it creates a risk when splitting data into training and test sets.

04

A leaky split

If crops are made first and then randomly divided, overlapping crops from the same rug can end up in both sets. The model may then see almost identical pieces during training and testing, recognising the particular rug rather than learning to measure repeats in general. Test results would look better than they really are.

05

Split first, crop second

The fix is simple: divide whole rugs between training and testing first, and only then cut each rug's photograph into crops. That way, no part of a test rug is ever seen during training. Holding out entire rugs gives an honest test of whether the model generalises to new carpets.

06

Pixels and millimetres

A model can measure repeat spacing in pixels, but a pixel is not a fixed length. How many millimetres a pixel represents depends on the distance between camera and carpet, the lens and the angle. The same rug photographed from closer up will show the repeat across more pixels.

07

Using a scale

To convert pixels to millimetres, a scale such as a ruler or a printed grid of known size should be placed in the photograph, lying flat in the same plane as the carpet. The model or software can then calculate how many pixels correspond to a millimetre in that image.

08

Camera geometry

If the camera is tilted, parts of the carpet farther away appear smaller, distorting measurements across the image. Photographing straight down, with the camera parallel to the rug, reduces this distortion. Lens distortion can also stretch the edges of images, and may need correcting.

09

How carpets are made

A carpet or rug is a textile floor covering, usually with a pile of fibres attached to a backing. Traditionally, pile was made of wool, while synthetic fibres such as nylon and polypropylene have become common since the 20th century. Hand-knotted rugs are made by tying individual knots, which can create slight irregularities in repeats.

10

Testing honestly

The NIST AI Risk Management Framework encourages careful evaluation of AI systems, including checking for data leakage that can make results misleading. Splitting by rug is one such check.

11

Repeats and borders

Rugs often have a central field with a repeating pattern, surrounded by one or more borders with different, smaller repeats. A model must know which part of the rug it is measuring. Labelling field and border areas separately helps avoid mixing their measurements, and makes results easier to compare between rugs.

12

Wear and fading

Old rugs may be worn or faded in places, making motifs harder to see. Including worn rugs in testing shows whether the model can still find repeats when parts of the pattern are faint.

13

Try the arithmetic

If a ruler in the image shows that 100 millimetres span 400 pixels, each pixel represents 0.25 millimetres. A repeat measured as 600 pixels is then 150 millimetres long.

14

The idea to take away

Overlapping crops can put the same motif in both training and test sets. Split rugs first and crop second. To measure in millimetres, include a scale in the carpet's plane, because pixel spacing alone depends on camera distance and geometry.

FOLLOW THE EVIDENCE

Sources & further reading

Figures in the example are illustrative. Photograph: Wollteppich 1.jpg by Ryj, Public domain, via Wikimedia Commons; cropped and resized. Reference organisations do not endorse this website.