How a Mouse Compares Two Photographs
The mouse takes a photograph of your desk, then another one a moment later, and works out how far the pattern has shifted between them. That comparison was called the whole trick, and then it was left there.
It is worth not leaving there, because the mouse is being asked something quite hard. Nobody labels the specks. No speck is marked "I am the one that was at the top left". The sensor has two grids of light and dark, and it has to find the shift with nothing but those.
The one thing that makes it possible
Between two photographs taken a five-thousandth of a second apart, the desk has not changed. Not one speck of grain has moved relative to another. The whole pattern has simply slid, as one piece, by the same amount everywhere.
That is the fact the mouse leans on. It does not have to work out where each speck went. It has to find one shift that puts every speck where it now is.
Slide it until it fits
So the sensor tries. It takes the second photograph and lays it over the first, offset a little, and counts how well the light and dark parts agree. Then it tries another offset. Then another.
Almost every offset gives a poor score — dark landing on light, specks landing on empty desk. Then one offset lands and the score jumps: dark on dark, light on light, every speck capped.
That offset is the answer, and finding it by trying is not a lazy way of doing it. It is the way.
Have a go yourself. The solid dots are the first photograph. The rings are the second one, and they are all displaced by the same amount because they moved together.
Slide until every ring sits neatly on a dot. There is exactly one setting that does it.
Notice what you did not have to do. You never picked one particular dot and followed it. You watched the whole pattern at once and stopped when it clicked. That is what the sensor does, except it does it by adding up numbers instead of looking, and it gets through every offset in less time than you took to move the handle once.
The drawing slides one way only, to keep it simple. A real sensor searches sideways and up-and-down at the same time, which is more offsets to try but no harder an idea.
Why the shiny table beats it
You already know a mouse misbehaves on glass. Now the reason is sharper than "there is no pattern".
The search only works because exactly one offset scores well. On a wooden desk the grain is a jumble that never repeats, so a wrong offset always lines up badly and the right one stands out on its own.
On plain glass every offset looks the same, because every part of the picture looks the same. There is no winner. The sensor is not confused about which answer is right — there is nothing to be right.
Two numbers, and nothing else
When the search finishes, the mouse sends the computer the offset it found: so much across, so much down. That is all it ever sends. It does not know where the pointer is on your screen and it does not know where it is on the desk.
Which is why picking the mouse up and putting it down somewhere else moves nothing. In the air the camera finds no match, so no shift is reported, so no shift happens. Your hand went back to the middle of the desk and the pointer stayed exactly where you left it.
The sensor tries many different offsets and scores each one. On a well-grained wooden desk, what makes the right offset findable?
- It is the only offset where the two photographs agree well; every other offset lines up badly
- The specks are numbered so the sensor can match them up one at a time
- The mouse remembers where it was on the desk a moment ago
- The right offset is always the smallest one it tries
Every time you nudge the mouse an inch, that search happens thousands of times over — lay it down, score it, try again, keep the winner — and all of it just to answer one small question the mouse asks again a moment later.