Focus visualisation - for photographers and videographers :-)

Started by garry23, May 14, 2017, 08:58:29 AM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

garry23

I just posted a new script that I wrote for landscape photography, ie where you are seeking to nail the focus from a near field position to infinity,

This helper script uses a 'new' approach to focusing, ie managing infinity blur.

What I also included was a focus bar that visually allows you to see the focus field through the scene.

Because of the non-linear way our lenses behave when we focus, ie look at the focus scale on your lens, finding a way to specify a distance is a challenge.

The method I used was to calculate the distance at which the infinity blur equals the sensor pixel size, eg about 6.3 microns on my 5D3.

This then allows you to zoom out and now in.

To zoom just change the multiplier in the menu, ie 3 = a zoom of 1, < 3 means zoom in (0.5 or 0.25 multipliers) and > 3 means zoom out (multipliers of 2, 3, 4 etc).

This approach is a a bit clunky and will tidy this up when I move out of beta testing.

For all (sic) photographers and videographers, the focus bar in this landscape script allows you to dynamically visualise optical (ie without diffraction) focus.

As we know, diffraction is flat through the scene, while optical blur changes through the depth of the scene.

The colours tell you about the 'focus density' based on a unity blur criterion that you set in the script, eg 30 microns:

- Green = unity blur to half unity blur
- Yellow = less than half unity
- Grey = blurs above unity (Black being the max blur you wish to see, set by the user in the script)

Here is the link to the script: https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d

Bottom line: Anyone (photographer or videographer) interested in 'seeing' what focus looks like through (sic) the scene, can use my landscape focusing helper script, ie use it as an education tool to plan better focusing strategies. It's great fun to play with the script in the comfort of your favorite chair :)

As usual I welcome any feedback. For instance, one idea could be to create a focus bar (alone) script that all can use. As I say, your feedback is most welcome.

mageye

Hello Garry!

I have been following your posts for a number of days now. It's interesting stuff indeed.

Just assume I am a complete idiot here (bare with me!).

I understand the basic principle of the hyper-focal distance. Obviously any tool that helps to achieve optimum/maximum DOF is a good thing (especially for landscape stuff).

I thought that I would be able to use your script easily ... but to be perfectly honest - I am really struggling.

Now I know this question might sound incredibly stupid but: - Where is the 'mod_button_1' 'mod_button_2'?

There is no such button that I am aware of on my 5DMK3

I apologise in advance for my stupidity :) :( ::)
5DMKII | 500D | KOMPUTERBAY 32GB Professional 1000x |Canon EF 50mm f/1.8 II | Samyang 35mm f/1.4 ED AS UMC | Canon EF 75-300mm f/4-5.6 III | Zoom H2 (4CH. audio recorder) | Mac OS X 10.9.2 | Photoshop CC | After Effects CC | Final Cut Pro 7

garry23

@mageye

Not stupid, and I'm here to help :-)

You can use whatever buttons you wish, within reason.

Just change in the script.

I use MENU and ENTER on my 5D3.

If you read the script it points you to a list of buttons or keys, i.e. http://builds.magiclantern.fm/lua_api/modules/constants.html

Those keys presses allow you to access the auto moves, i.e. you don't need to worry about them if just using the blur info or focus bar.

BTW please respect this is a beta release, I will be updating a few times before it's stable. I've already spotted a few errors and the next update will allow you to just have the focus bar displayed, i.e. If you're not interested in the infinity blur stuff.

Cheers

Garry

garry23

As promised, I'm close to 'finishing' the first release of the script.

Here it is: https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d

This version allows you to only have the focus bar on (just below the upper ML bar).



The above image shows the focus helper with the infinity blur option switched on.

This next image shows the focus bar only mode:



The red dot is the point of focus; the green dots the near and far DoFs.

If the green DoF dots go outside the focus bar, this indicates there are either less than HFD/4 (the left hand near field limit) or greater than the displayed distance limit of the focus bar (4.5m above).

Either side of the green dots the grey scale gives you info on the focus, ie:
- between the green dots you see the optical focus going from the DoF limit (black eg 30 microns, say) to zero (white) at the point of focus.
- either side of the green dots, ie camera to near DoF or far DoF to focus bar limit, you see focus as it varies from your criterion (eg 30 microns) to the max blur you have set.
- Red means that the blur is greater than the max blur.

Please read the script for more help in using it.

As usual I welcome feedback.

garry23

After sufficient beta testing, I'm 'releasing' my latest script, now called FOCUS (FOcus COmpanion Script).

You can download it from here: https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d

I have put a lot of help info in the script, so please read it.

I will be writing on my blog (photography.grayheron.net) on how to use this script over the coming weeks.

Note:

- Focus bar can be shown on its own or with the infinity blur data.
- The focus bar has a nice feature (option 0) that shows the optical near field focus from the camera's sensor to the focus point, which together with the ML reported diffraction corrected DoFs and the infinity blur data, gives the landscape photographer the ultimate focus data to make informed decisions regarding focus.

Please give FOCUS a try and let me know what you think. If nothing else it is a great education tool to investigate focus as you sit in your armchair :-)

garry23

With the full release of my FOCUS script (https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d), I will be publishing a few 'tutorials'.

This first one illustrates the landscape focusing use case: http://photography.grayheron.net/2017/05/focus-tutorial.html

As usual I welcome feedback.

Cheers

Garry

BBA

@garry23

This article is well written (as always) !
I think it is indeed quite interesting stuff  :) !

Haven't tested all the functionalities so far nor have I checked the Lua code (should be better debugged in a Lua development environment, shouldn't it ?).

Have tried the script with my 24mm; it is indeed very sensitive near infinity and goes from 63m to infinity with a tiny little angular move.
Wish it could be smoother at that crucial point but I know there are only a few encoded distances.

It is quite an achievement as it is !
Thanks again !

garry23

@BBA

Thanks for the feedback, I'm afraid I don't get much  :o ;) :)

I welcome others testing the script, as my needs are rather limited, but FOCUS, as a tool, has more potential.

I will keep releasing 'updates', eg my next one will provide an enhanced DoF mode, where the focus bar shows the focus field from the focus point out beyond the ML DoF: eg when you go beyond the HFD you get the total infinity blur data.

I think the DOF mode is the real star of the script, as it sits just below the ML top bar, ie as unobtrusive as possible, and provides 'all' the info you need about the focus between the DOFs. The enhanced DOF mode will give you extra focus info if you need to worry about focusing on a subject, ie it will show the focus field outside of the DOFs.

BTW I only have access to normal lenses, ie not cine lenses. It would be good to hear from someone regarding how FOCUS works with cine lenses.

Finally, the obvious caveat is that we 'assume' the lens distance reporting is 'right'. I am thinking about a calibration feature  ;) Maybe this is where some of your working can help?

Cheers

Garry

BBA

@garry23

Those tools rely heavily on man-machine interface, which is always a difficult part of a project (lots of trials and errors, subjective appreciation, ease of use,...).
But as an experienced photographer, you know what is needed and what you are doing !
Quote
I think the DOF mode is the real star of the script, as it sits just below the ML top bar, ie as unobtrusive as possible, and provides 'all' the info you need about the focus between the DOF
Yes it is quite effective (ratio infos/dimensions). On the live view screen, I think we have to "draw" things to be able to remove them when they are not needed anymore. Hint : I thought of drawing digits as 7 segments displays do.
Quote
Finally, the obvious caveat is that we 'assume' the lens distance reporting is 'right'
Agreed : it comes from the lens (cfr communication protocol) : the encoder present in the lens and a conversion table provided by Canon : the encoder is not very precise (few steps), so there are few distances : made for AF lenses/bodies.
Quote
I am thinking about a calibration feature
Me too. Still thinking.
There should be some calibration procedures in professional photography, at least for certain lenses ?
Infinity : I thought of two parallel beams (lasers) focusing/interfering on the same focal plane in the image field : the image focal point should be there (good point).
Quote
Maybe this is where some of your working can help?
You are right, but, IMHO, it is far from finished (sorry).
Maybe the interpolation feature between distances could be used if the calibration shows it can be precise enough.
First, let's render to Caesar... A1ex has done most of the decisive work.
He showed the micro-units counter, the hysteresis probably caused by mechanical backlash (at least for lenses with motor+gears) .
A1ex also proposed to use a Kalman filter to get rid as much as possible of the "errors/noise" from unmodeled mechanical behavior (which still needs to be modeled till some point) and "errors/noise" from the ... (few) sensor(s). 
To be honest, I am stuck.
A1ex has lots of important things to do for himself and the community (3K/4K lossless  :), Qemu  :), fast calculations on matrices/images  :), ... ).

garry23

@BBA

Just carried out a 'final' (for now  ;)) update of the script.

Added more info to the script at the front.

Tidied up the UI.

Would be interested to hear what you (or anyone) think of this latest version.

Cheers

Garry

https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d

a1ex

Played a bit with it. It's very promising, and reveals a lot of rough edges in the Lua backend (which I should fix).

Some initial feedback:
- the focus bar appears to be more intuitive (at least at first sight) - maybe a good idea to make it the default choice
- for mapping distance to pixels I recommend 1/x; a distance scale would be also be helpful
- edge case when the lens reports infinity (the focus bar turns into solid gray)
- there are some transient effects while moving the lens - probably because the lens info changes while you are drawing; to avoid this, I recommend getting all your values into local variables before the drawing loop, so they don't change during the loop. It will still have race conditions (if the lens info is updated while you are reading the variables), but a lot less likely. (todo: expose cli/sei? nicer way to handle it?)
- there are not enough gray shades for a smooth transitions; some dithering should help

Menu:
- settings are not saved (I also need to look into it; the config.lua library should be helpful)
- uppercase ON/OFF are recognized as booleans by the menu backend
- overriding ICON_TYPE results in confusing behavior (green LED = OFF?); simply choices = { "ON", "OFF" } is enough.
- What about placing it in the Focus menu, rather than Shoot? To me, it seems related to the DOF settings submenu.

I'd like to get it working like this, but looks like I have some stuff to fix in the backend:

hfd_move_menu = menu.new
{
    parent     = "Focus",
    name       = "DOF Settings",    -- fixme: it merges with the existing menu, but shows two identical menus
    depends_on = DEPENDS_ON.LIVEVIEW,
    submenu    =
    {
        {
            name    = "Interactive mode",
            help    = "Move focus to hyperfocal distance in LiveView using MENU/SET. Options:",
            help2   = "Use current Av (SET) / MAXimize DOF / WIDE open / +2 stopdown / INF.",
            choices = { "ON", "OFF" },
        },
        ...


Notes:
- the setting is not named "Turn On/Off" (which is quite generic - turn on what?)
- the help "Switches the interactive mode on/off" would not give any additional information after changing the name; rather, I've crammed in a mini-guide for the interactive mode. Feel free to improve.
- uppercase ON/OFF are enough for proper boolean operation in menu

Interactive mode has some bugs:
- display is not updated unless you move the focus ring (I should fix this one, as it's probably in the backend)
- I've tried to move the lens to infinity - rather, it went into an infinite loop showing "Focus: soft limit reached"; didn't try to debug yet; likely something at the stop condition.

Minor:
- I prefer indention with spaces rather than tabs (and so does editor.lua)
- Maybe I should add some auto-indent function to editor.lua :)

dfort

Quote from: a1ex on May 17, 2017, 11:10:13 AM
- I prefer indention with tabs rather than spaces (and so does editor.lua)
- Maybe I should add some auto-indent function to editor.lua :)

That link points to a lua Source Code Formatter with these features:
QuoteWhat the script does

  • Removes tab indents and replaces them with spaces.
  • Standardises indentation at 2 spaces per indent.
  • Checks that line lengths don't exceed 80 characters.

I'm confused. The source code for editor.lua uses spaces.

a1ex


garry23

@A1ex

Just a quick thank you for taking the time to comment on FOCUS.

Some of the things you mention, eg default to only the focus bar, had already been changed and updated on github.

I will be looking  into all that you say and, hopefully, this will make FOCUS a better script.

I'm afraid, however, I'm not a well structured coder, 'just' a simple scripter ;-)

I wrote the script literally 'from my head'. Maybe in future I should do some (layout) planning!

Once again, many thanks for the comments.

Cheers

Garry

BTW I use Visual Studio Code for my Lua scripting and I must say I simply tab to make it 'look good', eg indents.

a1ex

Quote from: garry23 on May 17, 2017, 06:48:59 PM
BTW I use Visual Studio Code for my Lua scripting and I must say I simply tab to make it 'look good', eg indents.

Looks like this should help: http://stackoverflow.com/questions/36814642/spaces-to-tabs-in-visual-studio-code

garry23

@A1ex

I'm making great progress following your 'pointers/suggestions'.

I've also turned the focus bar into a totally standalone function, ie making it transferable to other scripts.

However, I am experiencing some strangeness. Randomly I see the following:



The menu is written like this:

        {
            name = "Diffraction",
            help = "Switches the diffraction on & off in the focus bar",
            help2 = "Focus Bar blur is dynamically linked to ML blur (CoC) settind",
            choices = {"OFF","ON"},
        },


Is it indicative of my code or a Lua error.

Cheers

Garry

a1ex

Very likely a Lua bug. How "randomly" do you experience it? Is it a transient error that goes away after a second or so? (I assume not, since you could take a screenshot)

garry23

@A1ex

The script seems to work ok, but after a few menu changes I see the image below. Once I see this, it doesn't go away.

I'll carry on looking at my code to see if it's me.

Cheers

Garry

dmilligan

Probably the memory used for the choices is getting "garbage collected" by lua and then reused for something else.

from the Lua docs:
Quote
Because Lua has garbage collection, there is no guarantee that the pointer returned by lua_tolstring will be valid after the corresponding Lua value is removed from the stack.
The fix would be to allocate the memory ourselves in C for the menu entries' choices rather than just using the pointer returned from lua_tostring directly:

menu_entry->choices[choice_index] = lua_tostring(L, -1);

would change to something like (but with proper checks and everything):

menu_entry->choices[choice_index] = malloc(sizeof(char) * (strlen(lua_tostring(L, -1)) + 1));
strcpy(menu_entry->choices[choice_index], lua_tostring(L, -1));


And then appropriate code to free those buffers should the menu entry ever be removed and they are no longer needed.

As a workaround you can probably fix it in Lua by assigning anything to be use as 'choices' to global variables (so they don't get garbage collected).

garry23

@dmilligan

Many thanks for the quick insight and 'the fix'.

I've just tried it out and it seems to have worked.

Now back to tidying up the rest of 'function focus_bar(.....)', before I publish.

Cheers

Garry

g3gg0

Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

garry23

@g3gg0 & @a1ex

You have both given me insight into Lua, although some/most of it is over my head  :(

Clearly I need to continue to broaden my Lua skills  ;)

As for the main purpose of my current Lua efforts, getting an ML-based focus bar running; I'm pleased to say the latest version (https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d) is running very smoothly and I now have it on all the time in my 5D3 and EOSM.

The latest tweak provides a boost for the landscape photographers, with the option of providing the near DoF that is twice the blur at infinity.

The guidance is written about elsewhere on the web, for example Jeff Conrad at http://www.largeformatphotography.info/ says:

QuoteThe conventional approach to DoF is based on distinguishing a point from a blur spot in the image, and uses equal CoCs for the near and far limits. Although the CoC usually is quite small in comparison with the imaged size of near objects, it can be quite large in comparison with the imaged size of distant objects, in some cases so much so that a distant object becomes unrecognizable. Although many undoubtedly would maintain that, under normal viewing conditions, a blur spot either is distinguishable from a point or it is not, others (Merklinger 1992; Englander 1994) maintain that sharpness perception is context dependent, and that greater sharpness is required in distant objects to give an acceptably sharp image. This requirement can be addressed by using a smaller CoC for the far limit of DoF; in some respects, this approach is similar to the concept of "relative blur."

That is, if you are using a wide angle lens, and infinity focusing, as most landscapers do, you can tolerate more blur in the near field, ie giving you greater DoF than if the near and far blurs were the same.

My infinity focusing technique is to focus at infinity to the smallest blur I can, before diffraction or sensor limits kick in. Thus, if ML blur/CoC is set, say, to the normal (screen quality) blur of, say, 30 microns on a FF; then I will seek out a total infinity blur of around 15. That is I will use an aperture of around F/8 (not F/16 as the diffraction will get the better of me), ie near the lens MTF-based sweet spot. Once I get to 15 microns, say, with the x2 option switched on in the script (in fact I have it as a default), I get feedback on the near DoF that is twice the infinity one, ie 30 microns = 2 x 15.

Bottom line: I'm afraid I'm only good for Lua scripting, thus most/all of the talk about the 'backend stuff' is over my head.

Cheers

Garry

PS I'm also 'worried' I'm boring most with all my Lua scripting and focus stuff  :-\

g3gg0

> Bottom line: I'm afraid I'm only good for Lua scripting, thus most/all of the talk about the 'backend stuff' is over my head.

no.
right now it is beyond your knowledge - but thats how learning works.
understand things up to your limits and then this "knowledge border" will automatically shift a bit.

Help us with datasheets - Help us with register dumps
magic lantern: 1Magic9991E1eWbGvrsx186GovYCXFbppY, server expenses: [email protected]
ONLY donate for things we have done, not for things you expect!

garry23

@g3gg0

Good point  ;)

And it goes without saying I really appreciate your support on the forum.

Cheers

Garry

BBA

[removed]
@garry23
I didn't want to hurt anyone and do apologize if it has been the case.
Too bad.