A non-transitory computer-readable storage medium storing a focal position estimation program causing a computer to operate as a focal position estimation system for estimating a focal position when in focus corresponding to an estimation target image, the focal position estimation program causing the computer to:
- acquire an estimation target image;
- and
- output a feature quantity of the estimation target image from the acquired estimation target image by using a feature quantity output model, to which information based on an image is input and which outputs a feature quantity of the image, and estimate a focal position when in focus corresponding to the estimation target image from the output feature quantity,
- wherein the feature quantity output model is generated by machine learning from a plurality of learning images associated with focal position information related to a focal position at the time of imaging, and feature quantities of two different learning images are compared with each other according to focal position information associated with the two different learning images, and machine learning is performed based on a result of the comparison.