How a $2 Microcontroller Finds Image Corners with SIMD


A camera frame can be a surprisingly large job for a small chip. Even a 320 × 240 grayscale image contains 76,800 pixels. A computer vision algorithm that inspects a neighborhood around each pixel has to repeat its core test tens of thousands of times before the next frame arrives.

That is the setting for Shraiwi’s ESP32-S3 experiment: implement the FAST corner detector using the chip’s vector instructions. The reported result is 11.2 million pixels per second, up from 5.1 million for the project’s baseline implementation. The useful story is in the two obstacles between those numbers. The vector unit wants aligned data and signed bytes; image rows supply overlapping neighborhoods and unsigned bytes.

What the detector is looking for

A corner is a point where image brightness changes in more than one direction. Such points are useful as landmarks for tracking motion, matching frames, and estimating camera position. FAST, introduced by Edward Rosten and Tom Drummond, asks a deliberately cheap question at each candidate pixel: compare the center intensity with sixteen pixels on a small circle around it.

Let the center brightness be p and the threshold be t. A full segment test declares a corner when a sufficiently long contiguous arc of the circle is all brighter than p + t, or all darker than p - t. The neighborhood matters: a single bright neighbor is common along an edge or in noise, while an arc gives stronger evidence of a corner. FAST variants differ in the required arc length and in how they order the tests.

The original high-speed rejection test checks four cardinal positions on that circle first. For the common twelve-pixel arc criterion, a true corner must have at least three of those four positions on the same side of the threshold. If it does not, there is no reason to inspect the other twelve. The test is a filter, not the entire corner detector: candidates that survive still need the full circle test. OpenCV’s FAST explanation also describes scoring and non-maximum suppression, which remove clusters of neighboring responses.

A center pixel and sixteen surrounding pixels form the FAST circle. The top, right, bottom, and left samples form an early rejection test; surviving pixels proceed to the full arc test.
Four samples can reject a candidate cheaply; passing them only earns the full circle test.

Sixteen center pixels at once

The ESP32-S3 has two cores that can run at up to 240 MHz, plus vector instructions intended for packed arithmetic. The experiment puts sixteen eight-bit pixel values into one 128-bit vector register. Instead of testing one center pixel and moving to the next, it computes the cardinal pre-test for sixteen neighboring centers in parallel.

Picture a horizontal run of sixteen candidate pixels. For each candidate, the code needs the pixel a few positions north, east, south, and west. It loads four sixteen-byte chunks representing those directions, compares them with the sixteen centers, and counts which lanes meet the brightness test. Each lane represents a different candidate center, so one vector operation does sixteen small comparisons. That is the main source of parallelism here; the detector is still applying the same image rule.

The author wrote the hot path in Xtensa assembly after examining Espressif’s instruction set and examples in ESP-DSP. This choice matters because the details of loads, comparisons, and register use are exactly where this optimization succeeds or fails. The project also includes basm, a small assembly helper developed during the work to help manage registers. The source repository makes the implementation available rather than leaving the benchmark as a claim without code.

The alignment problem

Vector loads are easiest when their address is aligned to the register width. But the east and west samples for a block of centers begin a few bytes away from the center block. Those positions are naturally misaligned even if the centers are perfectly aligned. Simply loading every shifted neighborhood as a 128-bit block is therefore not a valid plan for this instruction set.

The solution is to load the neighboring aligned blocks and assemble the desired shifted block inside the vector registers. The ESP32-S3’s EE.SRC.Q instruction extracts a slice from two concatenated registers. It lets the code build the east and west neighborhoods without relying on direct misaligned vector reads. North and south samples, which lie on different rows at the same horizontal offsets, do not have that particular shift problem when the row layout preserves alignment.

This is a familiar pattern in SIMD image code: moving several candidate centers together saves arithmetic, but their neighborhoods overlap and are not all aligned alike. The data arrangement can cost as much thought as the comparison itself.

The signed-byte problem

Camera intensities are naturally unsigned bytes, from 0 through 255. The vector comparison available to the author treats eight-bit values as signed, from −128 through 127. Reinterpreting the bits directly changes their order: brightness 128 appears as −128, so an ordinary comparison would say it is less than brightness 127.

The obvious fix, subtract 128 from every lane, runs into another feature of the chip: the relevant packed arithmetic saturates rather than wrapping. A saturating subtraction clamps results at the signed boundary, so it does not produce the desired one-to-one remapping across all 256 input values.

Instead, the implementation flips each byte’s high bit with XOR 0x80. This maps unsigned 0…255 to bit patterns interpreted as signed −128…127, preserving the brightness ordering. For example, unsigned 0 becomes signed −128, 127 becomes −1, 128 becomes 0, and 255 becomes 127. The vector unit can then compare transformed pixels consistently. The threshold arithmetic still needs to respect the signed range; the key point is that the high-bit flip supplies the correct ordering without a saturating subtraction.

Sixteen unsigned pixel lanes enter a vector register, are shifted into aligned neighborhoods, have their high bits flipped with XOR 0x80, and are compared as signed bytes for the FAST pre-test.
Alignment fixes where the bytes come from; the high-bit flip fixes how comparisons interpret them.

What the numbers say

In the author’s test, throughput rose from 5.1 to 11.2 megapixels per second. That is about 2.2 times the baseline throughput, or roughly a 120% increase. The original write-up describes it as about a 220% throughput result; the ratio is the less ambiguous way to state it. At 11.2 million pixels per second, a 320 × 240 frame takes roughly 6.9 milliseconds of detector time, which aligns with the reported approximately 6 ms. A 640 × 480 frame would take roughly 27.4 milliseconds at the same sustained rate, below a 33.3 millisecond frame interval for 30 fps.

That arithmetic is a feasibility check, not a full camera-system benchmark. Capturing frames, copying or converting pixels, finding final corners, and doing anything with those corners also consume time and memory bandwidth. The repository’s result compares this implementation with its own baseline on this device; it does not establish that every FAST implementation or every real-time vision pipeline sees the same speedup.

The experiment does show a useful design method. First identify the early test that runs for almost every pixel. Pack independent pixels into lanes. Then solve the hardware’s awkward rules precisely: reconstruct shifted neighborhoods from aligned loads, and map unsigned bytes into an order that signed comparisons can use. The headline speedup follows from making those small, repeated operations fit the chip, not from changing what a corner means.

Sources

100%