X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=dof.lisp;h=f1cd7b245a71b07bd95e1afdcfcf81a5bc15bcce;hb=6290486a001d80c01676dfd9c2ac053cb4bc1871;hp=4117c5a0f7d703dacce30a0e2cd51315c211945f;hpb=3c1c551f36fe090936bf5d21e7eb65acbcc0d457;p=cl-photo.git diff --git a/dof.lisp b/dof.lisp old mode 100755 new mode 100644 index 4117c5a..f1cd7b2 --- a/dof.lisp +++ b/dof.lisp @@ -19,24 +19,34 @@ (in-package #:photo) -(defun coc (imager-size &key (lpm 5) (minimum-distance 250) +(defun sort-size (size) + "Returns a cons pair with the smaller size first." + (if (>= (car size) (cdr size)) + (cons (cdr size) (car size)) + (cons (car size) (cdr size)))) + +(defun print-magnification (imager-size print-size) + "Returns the magnification required between an imager and print sizes +while taking crop into consideration." + (setf imager-size (sort-size imager-size)) + (setf print-size (sort-size print-size)) + (float (max (/ (car print-size) (car imager-size)) + (/ (cdr print-size) (cdr print-size))))) + +(defun coc (imager-size &key (lpm 5) (minimum-distance 250) (viewing-distance 250) (print-size (output-dimensions :8x10in))) - "Returns circle of confusion in mm and print magnification for a format. + "Returns circle of confusion in mm and print magnification for a format. Default resolving power is 5 lpm at 25cm." + (let* ((magnification (print-magnification imager-size print-size)) + (resolution-factor (/ (* magnification lpm minimum-distance) viewing-distance)) + (coc (/ 1.0d0 resolution-factor))) + (values coc magnification))) - (let* ((imager-diagonal (diagonal (car imager-size) (cdr imager-size))) - (print-diagonal (diagonal (car print-size) (cdr print-size))) - (resolution-factor (/ (* lpm print-diagonal minimum-distance) - (* imager-diagonal viewing-distance))) - (coc (/ 1.0d0 resolution-factor)) - (print-magnification (/ print-diagonal imager-diagonal))) - (values coc print-magnification))) - -(defun coc-format (format &key (lpm 5) (minimum-distance 250) +(defun coc-format (format &key (lpm 5) (minimum-distance 250) (viewing-distance 250) (print-size (output-dimensions :8x10in))) - "Returns circle of confusion in mm and print magnification for a format. + "Returns circle of confusion in mm and print magnification for a format. Default resolving power is 5 lpm at 25cm." (let* ((format-size (imager-dimensions format)) @@ -49,27 +59,36 @@ Default resolving power is 5 lpm at 25cm." (values coc print-magnification))) (defun coc-pixels (imager pixels) - "Returns circle of confusion based on pixel size." + "Returns lpm and circle of confusion based on pixel size." (when (and (consp imager) (consp pixels)) - (values (float (* 2 (/ (car imager) (car pixels)))) - (float (* 2 (/ (cdr imager) (cdr pixels))))))) - + (let ((coc-w (float (* 2 (/ (car imager) (car pixels))))) + (coc-h (float (* 2 (/ (cdr imager) (cdr pixels)))))) + (values coc-w coc-h (/ 1. coc-w) (/ 1. coc-h))))) + (defun coc-pixels-format (format) "Returns circle of confusion based on pixel size." (coc-pixels (imager-dimensions format) (pixel-dimensions format))) -(defun coc-airy (f-stop) +(defun coc-airy (f-stop &optional (wavelength 0.000512)) "Return the circle of confusion based on the airy disk." - (let ((airy (/ f-stop 1500))) - (float (* 2 airy)))) + (float (/ 1 (rayleigh-limit f-stop wavelength)))) + +(defun rayleigh-limit (f-stop &optional (wavelength 0.0005)) + "Returns the rayleigh limit in line pairs per mm (MTF 9%) as well as the MTF50" + (let ((rayleigh (float (/ 1 1.22 f-stop wavelength)))) + (values rayleigh (* 0.46 rayleigh)))) + +(defun maximum-sharpness-aperture (format &optional (wavelength 0.0005)) + (multiple-value-bind (coc-w coc-h lpm-w lpm-h) (coc-pixels-format format) + (declare (ignore coc-w coc-h)) + (/ 1. (* 1.22 wavelength (/ (min lpm-w lpm-h) 0.46))))) (defun dof-mm (focal-length f-stop distance coc &key (pupil-factor 1)) "Returns depth of field based on focal-length, f-stop, distance, and coc. Six values are returned: -near dof, far dof, total dof, near point, far point, magnification, -blur size at infinity (mm). +near point, far point, total dof, magnification, blur size at infinity (mm). Circle of confusion can either be a number or keyword designating format." - (let* ((aperture (/ focal-length f-stop)) + (let* ((aperture (/ focal-length f-stop)) (numerator-1 (* (- pupil-factor 1) (- distance focal-length) coc focal-length)) (numerator-2 (* pupil-factor aperture focal-length distance)) @@ -105,10 +124,10 @@ Pupil factor is the ratio of the exit to enterance pupil diameters." (defun dof (focal-length f-stop distance coc &key (units :mm) (pupil-factor 1)) "Returns the Depth of Field. -Input: FOCAL-LENGTH, F-STOP, DISTANCE, CIRCLE-OF-CONFUSION. +Input: FOCAL-LENGTH, F-STOP, DISTANCE, CIRCLE-OF-CONFUSION. Output: NEAR-POINT, FAR-POINT, TOTAL-DOF, MAGNIFICATION, BLUR-SIZE-OF-INFINITY-POINT-IN-MM." (multiple-value-bind (near-point far-point total-dof mag blur) - (dof-mm focal-length f-stop (length->mm distance units) coc + (dof-mm focal-length f-stop (length->mm distance units) coc :pupil-factor pupil-factor) (values (mm->length near-point units) (mm->length far-point units) @@ -120,3 +139,7 @@ Output: NEAR-POINT, FAR-POINT, TOTAL-DOF, MAGNIFICATION, BLUR-SIZE-OF-INFINITY-P (defun effective-aperture (focal-length distance aperture) (* aperture (bellows-factor focal-length distance))) + +(defun mtf-scanner (freq dscan-freq &optional (order 3)) + (abs (expt (kmrcl:sinc (* pi (/ freq dscan-freq))) order))) +