Have you ever been frustrated when taking close-up photographs of your layout? Often the images in the foreground are in focus while those in the distance are not, or vice versa. It can be difficult to get everything in focus, especially indoors where the light isn't as strong as it is outdoors and where there is considerable variation in the relative distances of various objects from the camera lens.
The main issue at play is the physics of lenses and what is known as "depth-of-field". I won't get into any of the technicalities because there is a lot of information online explaining depth-of-field. I prefer to offer a solution, particularly for close-up model railroad scenery photographs.
Here is a digital photograph of a scene in which the foreground is in focus but the background is not (note that the "slow" highway sign is sharp but the flatbed trailer in the distance is out of focus):
Here is the same scene in which the background is in focus but the foreground is not (the "slow" highway sign is out of focus but the flatbed trailer is sharp).
The locomotive was stationary in both photographs.
Photograph stacking software analyses several photographs that are identical, aside from each having different areas in focus, aligns them and uses algorithms to digitally create a new photograph taking the best portions of each. The general guidelines for success are that each photograph needs to be taken from the same place (a tripod or placing the camera on a solid object works best) and the more photographs that are taken, the better so the software has lots of sharp areas to choose from.There are several such software products on the market. I have been using Zerene Stacker. It cost me just over C$100 for the personal use version. You can download a free 30-day trial to try it out before buying.
As a test, I used my Samsung Galaxy S10 to take the two photographs above with the phone being held in my hands instead of being mounted on the recommended tripod. Again, as a test, I took only these two shots instead of the recommended multiple shots.
Even with only these two photographs, Zerene Stacker produced the following result which is quite good. Had I taken five or ten shots using a tripod the result would likely have been even better.