Author Topic: A small warning for the perfectionists  (Read 231 times)

garry23

  • Hero Member
  • *****
  • Posts: 1605
A small warning for the perfectionists
« on: November 27, 2018, 07:58:11 AM »
The current depth of field (DoF) calculations in ML do a reasonable job of estimating the near and far DoFs, with or without diffraction.

However, some of you may have noted a strange result if you focus at infinity: have a look in the Focus menu in LV and you will see that the near DoF is different to the hyperfocal distance.

As you know, if you focus at the hyperfocal (H), the near DoF will be H/2 and the far DoF will be inifinity.

If you focus between H and short of infinity, the far DoF will, of course, remain at infinity, and the near DoF will move further away from H/2, until, at infinity it will be H.

The current ML C code estimates the near DoF as follows:

Code: [Select]
    lens_info.dof_near = fl + (fd*H-fl2)/(H+fd-2*fl); // in mm relative to the sensor plane
But, because we are using approximations and infinity is not infinity in ML, it's just a large number, you end up with the 'infinity anomaly' for the near DoF.

The ML code in focus.c should read:

Code: [Select]
if (fd>=655000)
   { lens_info.dof_near = H/2; // in mm relative to the sensor plane }
else
   { lens_info.dof_near = fl + (fdH-fl2)/(H+fd-2fl); // in

Using the fact that ML reports infinity as the distance 655350mm.

BTW my latest DoF Bar correctly reports things, so, at ML-reported infinity, DoF Bar and ML will report different near DoFs. DoF Bar can be downloaded from: https://gist.github.com/pigeonhill/fdbc6e2fbeed1206afcc47d69cee9591/revisions

The ML anomaly will not ruin anyone's day: I'm flagging this up for the perfectionists out there ;-)

I have flagged this in a bug report: https://bitbucket.org/hudson/magic-lantern/issues/2912/focusc-needs-updating-with-one-line-of which I hope will result in it being 'fixed' the next time @a1ex has a chance to refresh the core code.