Originally posted by Wiker Aperture and focus affects the image coming through the lens. (Maybe I’m dumb but...) How/why does it makes a difference if those stains are on the sensor itself?
As Falk wrote, changing the focus, changes the effective aperture. The aperture makes a difference for the following reason:
Imagine a particle on the sensor that is lit with light rays that are perpendicular to the sensor. The particle would then create a sharply defined shadow on the sensor. This case, where no light rays can hit the sensor area hidden by the particle from the side is approximated by a very small aperture; the light rays almost come from the same point and there are few light rays that can illuminate the sensor area under the particle.
When you open up the aperture (lower the f-ratio), more light rays become available. The additional rays come from the outer part of the aperture opening and hit the sensor at angles which are suited to "shine around" the particle, i.e., illuminate the sensor area under the particle. The place on the sensor under and around the particle then sees a mix of hard shadows and some light rays hitting it, in other words, a soft shadow will be created.
If you think of the particle as a model then small aperture means "harsh light" -> harsh shadows and wide aperture means "soft light (big light source)" -> soft shadows.
This is why by looking at the difference in shadow shapes depending on the f-stop (size of the light source) Falk has a chance of calculating the distance of the particle to the image forming part of the sensor (which in practice are the micro lenses).