Depth of Field Info Script (2020 Version)

Started by garry23, January 05, 2020, 04:48:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

This thread is superseded by https://www.magiclantern.fm/forum/index.php?topic=25286.msg230159#msg230159

***DOWNLOAD SCRIPT FROM HERE *** https://gist.github.com/pigeonhill/72dcef944db7bf1b11307dedeb2dc2f0

I'm starting 2020 with a new version of my focus bracketing helper script, called Depth of Field Info (DOFI). This version has had a UI overhaul and now integrates well into the overall ML UI.

The script provides the user with three key pieces of focus information:
   - The optical blur (in microns) at infinity
   - The diffraction blur through the scene
   - The total blur at infinity, which is the optical and diffraction taken in quadrature

Plus an estimate of the number of focus brackets required to go from the current position to infinity and whether the current image overlaps with the last image taken:
  - Yellow means the current image is at the same focus as the last one taken
  - Green means a positive overlap
  - Red means a negative overlap, ie a focus gap
  - White means that an image hasn't been taken yet, or that the focus length or aperture has changed

The script will only run with a lens that reports focus length, focus position and aperture. DOFI resets if aperture or focal length are changed.

All the above info is shown in ML's top info bar, ie in the right hand corner of the screen. DOFI is positioned under ML's Focus bar and can be switched off.

At start up the screen will look like this:



In this screen capture we see we are shooting at 24mm and at an aperture of f/8. I set the ML CoC (blur) to 30 microns, which defines the overlap blur to DOFI, and switched on diffraction aware, although using DOFI we do not need the ML DoF distances, as we will use DOFI to inform our focusing.

In the above we see we are focused at 91cm. We also see (top right) the DOFI information, ie #2:82/10/82, which tells us that we will need two focus brackets to cover from this position to infinity, and that the optical blur, at infinity, at this location, is 82 microns. Finally DOFI tells us that the diffraction blur is 10 microns and that the total blur at infinity is 92 microns, ie sqrt(82*82 + 10*10).

As an example of DOFI's use, lets assume we wish to focus stack from the macro end to infinity. At the macro end we would see the following:



Here we see that DOFI is saying that we will need four focus brackets, so let's get going and take our first image:



The only thing that changed was the DOFI field turned yellow, indicating that the current focus is the same as the last image captured. Thus if we refocus we can always come back to the last focus position by ensuring that the DOFI area is yellow.

As we refocus towards (or away from) infinity DOFI will turn green or red according to whether we have a focus gap. So all you need to do is refocus until you see red, then backoff slightly to green.

The following gif is illustrative:



Here we see I took the final image when the defocus blur at infinity was 9 microns, giving a total blur at infinity of 14 microns. As a point of reference, remember that the defocus blur at infinity, if you focus at the hyperfocal, is simply the circle of confusion, which needs to then be convolved with the diffraction. Thus, using DOFI, you can decide infinity blur quality, ie based on defocus or total blur.

I wrote DOFI for those that wish to control focus and want to have the flexibility to focus stack at any time, ie landscape photographers on a tripod.

As usual I welcome feedback, including ideas to improve DOFI.

wbajzek

This might be a dumb question... Is it possible to have a script set the camera's focus distance to a given point? Such as the hyperfocal distance for a given aperture?

garry23

QuoteIs it possible to have a script set the camera's focus distance to a given point?

Yes, and I've played with doing it by driving an EOS lens, but it's not that refined, ie controlling the lens motor varies across the cameras. It was ok on my 5D3.

Landscape focus stacking is different to macro stacking.

My preferred method is to now use this DOFI script.

I've also written Lua scripts for non ML cameras, eg my G7X and G1X http://photography.grayheron.net/2019/01/landscape-focus-bracket-script-for-g7x.html

I've also got the auto focus bracketing working on my M3: http://photography.grayheron.net/2019/08/more-cameras.html

wbajzek

Thanks for the info. It's interesting about the motor differences between cameras. I never would have expected that.

This is a thing that I don't understand why camera manufacturers don't just include it. Zone focusing/hyperfocal are kind of basic photography things that shouldn't be so hard.

garry23

QuoteI never would have expected that.

The lens is driven by the camera, so I guess a slow camera cpu means a slow lens movement.

My comparison is based on a 5D3 vs an EOSM.

wbajzek


garry23

Have updated the UI a little and rationalised some of the code.

Functionality remains as in the first post, which has the latest download link for the script.

BTW, for anyone that has followed my DoF experiments and scripting over the past few years, I consider DOFI the best script to use for infinity focusing and focus bracketing.

As a landscape photographer using DOFI, I recommend the following workflow:

1. Focus on the nearest object that you wish to see tack sharp and see what DOFI says
2. If DOFI indicates that your infinity defocus blur (first blur on the left of the three) and infinity total blur (last blur) are acceptable, eg defocus blur lower, say, than 30/crop (which should be good enough for on-screen showing), then you know you can accomplish everything in a single capture
3. If, however, the infinity defocus blur is too high, for example greater than 2*sensor-pitch if you are creating a high quality print (which is the best you can do), then you should capture an image at the current focus position and then use DOFI to tell you where to take your next image, ie at the point when DOFI switches between green and red, back off to green and shoot.
4. Review the infinity blurs and if still not 'good enough', repeat step 3.

BTW, make sure you set the ML CoC to the overlap blur that you wish to use, ie between 30/crop to 2*sensor-pitch. But note the lower you set this, the more brackets you will need, so I recommend, initially, set this to 30/crop and see how you go.

Finally, feel free to switch on the ML DoF info if you wish, including diffraction aware, as DOFI calculations are independent (and will also be slightly different to ML). But note the ML CoC must be set to the overlap blur criterion. On my 5D3 I set the CoC to 20, diffraction aware on and DoF on. This gives me all the data I need to inform my focusing.

garry23

I thought I would flag up something that threw me until I understood what was going wrong in my Depth of Field Info script.

BTW the latest version is here: https://gist.github.com/pigeonhill/72dcef944db7bf1b11307dedeb2dc2f0

I have been doing calculations in Lua up until now with out really thinking and then I saw some strangeness in DOFI, but only when I was at infinity, where the focus position is greater than 655000, which is my trap to detect ML reported infinity, ie from Canon.

So far all well and good, but then I, without thinking, used that infinity number, x, and, in particular in this equation, ie sqrt(x*x + something else).

The thing was this did not throw up an error, but it did create some strangeness in the value of the numbers I was getting, including numbers not related to the actual calculation.

Now, I believe, I understand the issue. That is 32 bit vs 64 bit implementation of Lua.

I assume ML is a 32 bit implementation and, somehow, the calculation corrupted the memory around where my numbers were located in memory: but this is my innocent theory  ;)

So, gypsies warning to others who, like me, are simple scripters and not code jockeys, remember you are working in a 32 bit Lua. That is if my assessment of my strangeness is correct.

Bottom line: DOFI remains the best focus aid I have written and I recommend its use to any one trying to get the best out of depth of field, the optimum infinity focusing, or carry out non-macro focus bracketing.

garry23

I've just started a new series on posts on my blog, that will culminate in discussing my Magic Lantern and CHDK focusing scripts, eg this DOFI script for ML and its like over in CHDK, DOFIC

This first post establishes the fundamentals of my approach and I thought some in the ML community may find my output-based approach, using blur info, to focusing of interest/value.

The post may be found here: http://photography.grayheron.net/2020/01/2020-reflections-on-focus-part-1.html

garry23

Just an update for those ML users who are lucky enough to also shoot with CHDK cameras; I have four: G1X, G5X, G7X and ab S95.

I have now ported my ML DOFI script into a CHDK Lua script, which I have called DOFIC.

In addition, I've extended DOFIC to include exposure bracketing and called this script DOFIZ.

You can read about DOFIZ here:   https://chdk.fandom.com/wiki/DOFIZ:_DOFIC_with_Exposure_Bracketing


yokashin

Quote from: garry23 on January 31, 2020, 09:22:03 PM
Just an update for those ML users who are lucky enough to also shoot with CHDK cameras; I have four: G1X, G5X, G7X and ab S95.

At the beginning I want to say that I always read topics about your scripts and appreciate your contribution and skills.
I have S95 and I promise to test the latest script.
Regards!
70D.112 [main cam] | M.202 | S110 [CHDK]

garry23

@yokashin

Great, please feedback anything to do with my CHDK scripts over on the CHDK forum, i.e. not here  ;)

https://chdk.setepontos.com/index.php?topic=13981.msg142539;topicseen#msg142539

BTW I haven't actually tested DOFIC or DOFIZ on my S95, only on my other powershot cameras. So I'd welcome knowing how you get on with these scripts.

garry23

Because of the family links, I thought I would make mention of DOFI's 'family' over on CHDK, as I've just uplifted DOFIZ over there.

BTW my G1X, G7X and G5X make great travel cams, i.e. As a lighter alternative to my EOSMs.

In addition to giving all the depth of field info you need, eg for infinity focusing, manual focus bracketing, exposure bracketing and ISO bracketing; DOFIZ now gives you semi auto focus bracketing.

More about DOFIZ here: https://chdk.fandom.com/wiki/DOFIZ:_DOFIC_with_Tv,_ISO_or_Focus_Bracketing

And my latest post here: https://chdk.setepontos.com/index.php?topic=13981.msg142601#msg142601

Now I've taken DOFIC as far as I wish at the moment, I'll likely look at uplifting ML DOFI now  ;)



vstrglv

@garry23
Thank you very much for your scripts!
Now I am looking for the "Focus distance" script. Focus distance info in ML screen uses a very small fonts and if there is additional info, for example "anamorph", there is no focus distance info at all. I need a script to show distance info with bigger font in independent bar. Can you help me? Thank you in advance.
Canon 5D3,1.1.3; Canon EOS M,202,  CF-SanDisk Extreme PRO,160MB/s, 256GB, SD-SanDisk Extreme Pro, 170MB/s, 128GB.

garry23

As long as the lens reports focus distance, aperture and focal length any of my scripts should work, eg

http://photography.grayheron.net/2018/12/dof-bar-getting-started.html

Or this one

http://photography.grayheron.net/2019/05/multi-image-deep-focus-photography.html

For me, however, my latest version, DOFI, is 'the best'.

Cheers

Garry


vstrglv

But there is no focus distance info in your scripts. The focus distance info is in low bar ML screen only. And it's too small for me.
Canon 5D3,1.1.3; Canon EOS M,202,  CF-SanDisk Extreme PRO,160MB/s, 256GB, SD-SanDisk Extreme Pro, 170MB/s, 128GB.


vstrglv

Thank you for reply, Garry, but there are only two places  where I can see "focus distance" in this link. First is "ML provides us no additional information, other than the focus distance" and second "Thus, at a focus distance of 5.24m and at an aperture of F/11, the near DoF, which meets our ML". So "focus distance" is info from ML low bar, not from your script. And there is no "focus distance info" on your images, besides in ML low bar.
Canon 5D3,1.1.3; Canon EOS M,202,  CF-SanDisk Extreme PRO,160MB/s, 256GB, SD-SanDisk Extreme Pro, 170MB/s, 128GB.

garry23

You are correct.

Focus distance is indicated by the red dot.

I could add in the focus, but I wrote the focus bar script, and it's derivatives, to aid focus stacking, where knowing the focus distance is not important, ie focus on the near object of interest and stack from there to infinity. Where infinity is the infinity blur you want.

Bottom line: you are right my current scripts don't show that info, I use blurs.

garry23

@vstrglv

Here you are: a quick 'fix' to the Depth of Field Bar script, that may help you?

https://www.magiclantern.fm/forum/index.php?topic=23036.msg224912#msg224912

You can select "Show Focus" on the Pro menu.

The screen will show focus in mm in the middle of the Bar:



The latest version is: https://gist.github.com/pigeonhill/fdbc6e2fbeed1206afcc47d69cee9591

garry23

I'm pleased to report that I've added an Augmented Reality (AR) feature to DOFI.

You can read about it here: http://photography.grayheron.net/2020/03/augmented-reality-depth-of-field.html

This is a screen capture that shows the AR feature.



Here we see the AR DoF info showing that we are focused beyond the hyperfocal, H, ie a yellow dot with a green bar, but less than 3*H. The black dot indicates infinity.

Because of the tripod height and the focal length, the H/3, H/5 and H/7 distances, ie the optimal focus stacking points, are not visible in this example.

As usual I welcome feedback; especially regarding ideas to make DOFI 'better'.