Focus Stacking with Focus Bar

Started by garry23, May 29, 2017, 06:57:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

garry23

Those that track 'my fun', will know I've implemented a focus bar in Lua.

In this post I'm releasing an enhanced focusing feature that allows you to get optimum focus stacking.

The only requirement is that the lens should report focus distance (which is assumed to be 'accurate').

As the current ML DoF reporting is broken (pull request submitted), I've made this release of the FOCUS script self contained, ie it does not rely on ML DoF info,

The script can be downloaded from here: https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d

The use the focus stacking/bracketing feature, simply switch it to DoF mode (option -1). The script default for focus stacking is on (you can reverse this if you wish).

Here is a screen dump having just taken an image:



The focus bar is telling us what the optical (sic) DoFs are, and the script (at the bottom) is telling what the diffraction corrected DoFs, ie where the ML DoFs would normally be (switched off when running the script). The focus bar end (in DoF mode) show the 'worst case' DoFs, ie the optical ones that ignore diffraction. The green dots are the diffraction aware DoFs and the red dot the focus point.

In focus stacking mode, the DoFs at the time the image is taken are captured, so that we can compare these with other DoFs as we refocus.

Here is a screen dump showing refocusing towards the infinity end:



And here is a screen grab if we focus the other way, ie towards the macro end:



In both cases, the magenta shows the amount of focus overlap, which you will need to ensure is visible, ie  if no magenta is showing then you don't have focus overlap ;-)

Bottom line: I hope some find the focus stacking feature of value. Although I wrote it for 'landscape photographers', because you can use it 'both ways', ie relative to the image you are taking, it may be of use to others.

As usual, I welcome feedback.

Cheers

Garry


garry23

...and those interested in using the focus stacking enhancement to the focus bar script, here is a tutorial I've just published: http://photography.grayheron.net/2017/05/focus-stacking-using-focus-bar.html

BBA

Don't know if it is the right place to report : it is not the functioning of the script  that is problematic but the functioning of the camera when the script is loaded.

Details (easy to test)

1st configuration (normal behaviour)
Lua.mo disabled
when I switch on the camera I get a black screen (no LV)  as usual ; if I then press the canon menu button, the menu shows up.

2d configuration (weird)
Lua.mo enabled
Focus.lua script set to be loaded
When I switch the camera on, the screen is black as usual.
If I then press the « menu » button, the canon menu does not appear; the screen does not remain black as I can see a little variation of the screen luminosity ; if I press again the button, the screen returns black as usual; this repeats itself as I continue pressing the same button many times in a row)
If I press the LV button and enter the ML menu, it seems to unlock things (the number of « states » of the system increases as one might think and becomes difficult to report).

FYI : firmware 113-ml-Nighy.2 (last nightly ; saw the same problem with a preceding one but could not narrow things at that time)

garry23

@BBA

The script needs some 'Lua fixes'. Could you try running with the experimental Lua fix build.

If you don't (sic) see XXXXXXXXXX on the screen with the focus bar then the Lua.module s OK, the XXXXXXXX on the screen is the sign the 'tansparent' isn't working, ie old build.

I've tested on an EOSM and a 5D3 and works fine...up to a point.

I also see the Menu strangeness and I clear it by accessing the menu, ie is appears in chunks as I click on the menu.

Cheers

Garry

BBA

@garry23

I see XXXX on the screen => not the Lua module needed.
I will try with Lua experimental build

Thanks !

BBA

@garry23

I used the Lua experimental build => no XXX anymore  :).

Some ideas/questions/feedback/reminder:
- So many options...for newbies like me
- saving the config from session to session : have seen in Lua API / module config : config:create_from_menu , config.data , config:save() , config:load() : I will try if I get the time  :P

(About the manual stacking)
- appreciate your tutorial on Grayheron  :)
- questioning about the best way to "restart" a stack : just set in menu off then on ?
- the magenta line is a clever idea for sequentially shooting from infinity to near field (also in the opposite direction) without adding too much complexity to the display

Hope it can help...(not complete)


garry23

@BBA

Thanks for testing and the feedback.

I defaulted the focus bar to open in DoF mode, as this is the most useful for all.

You can reorder the script menu to your default preference, eg stacking off.

I must get config saving working, but haven't tried it yet.

Because of the way the focus stacking works, it is reset every time you take an image. Thus if you are starting a new stack from a point, I personally simply take an image at that point with my hand in front of the lens, then take another with the lens clear. At the end of a stack I use my hand again, now the stack is identifiable in LR, i.e. Between my hands. Simple but effective. You can even identify the start and end of the stack, eg hand open or closed, one of two fingers, front of hand vs back of hand etc.


garry23

@BBA

You may find my latest post of help, as you explore the focus bar: http://photography.grayheron.net/2017/06/getting-best-out-of-focus-bar.html

Postscript: just did a minor tweak to focus bar (https://gist.github.com/pigeonhill/cd1dbe0191ca1264fc0aa07aaafb515d) to correct something ;-)

garry23

@BBA / all

If you use focus bar please make sure you change/set the sensor size for your camera at line 136

BBA

@garry23

a) Thanks for this article,  it is worth reading. Your are not the only user of the focus bar !

IMHO (please, take all of it with a grain of salt : as I reread myself, I feel the following "may" appear like if I were "giving lessons". Don't get me wrong : I write it "in general" (who would I be to give lessons to others I don't even know?); you know I have to struggle to try to give a better feedback and make me understandable  :P .
It would be easier for me to tell you that "everything is fine" or " I like it" or "thumbs up" ...

It is worth reading:
a.0) simply because what is learnt at school is right : it is of good practice to recall the ground basis of one's work : it's good communication. I know you know that because you are a blogger.
In development case, it goes further :
a.1) with software (some sort of expression/communication), one has to take decisions and refer to end users, back and forth, to know if everything suits them (I have done that as analyst and end user) : you make the scripts for your own needs and really know what you are doing (photography), this process is easier than it usually is;
a.2) this intense communication is useful to end users who can then smoothly "interface" with the software.

The following gives "an example" of something you write and that is very interesting to me in practice :
Quote
When the far DoF reaches 'infinity', the focus bar switches its info presentation to show the total blur at infinity, in microns, and the near DoF that corresponds to that blur criterion. This is necessary as far DoF distance now has no meaning, ie the far DoF is at infinity.
The meaning of something changes (for a good reason) : that's important to know.

That's why I appreciate to read your articles and why I am thankful for your efforts that really help me.

b) ease of development

I really hope you have found a graphical development system for Lua scripting because it is much easier, especially when drawing on a screen.
Personally I have found some drawing capabilities in ZeroBrane studio but I am still far from enough : I use routines used by "turtle.lua" which come bundled with it.
It is then possible to emulate the Lua API routines you use with a "dummy module".
In ZeroBrane you can run a chunk of code "as a scratchpad" under the menu "Project": the same script is rerun as soon as you make any modification (like modify constants (colors values,....)) and rework it until it suits you, which can come much faster; I can show you if you are interested.

I think it could also be better to have something like "lua inspect" to check the code and find as much errors as possible before porting to the camera.

Maybe "editor.lua" on EOS M can be useful too for some last typos/changes.

my 2 cents.

garry23

@BBA

Many thanks for all the feedback 8)

As for my development environment; I'm afraid I'm in the stone age.

I use Visual Studio Code only for entering my code.

I then transfer the script to a card and see if it works in my camera. If I'm lucky I can read the screen errors, sometimes I can't, ie not quick enough.

Bottom line: I would love to hear how others develop script with Lua, and in time I hope camera emulation becomes accessible for all, ie not just those who know how to work the magic.

Cheers

Garry

a1ex

One way I've found to be a great time-saver regarding camera transfers was a Wi-Fi SD card. It's way too slow for transferring photos (e.g. to transfer a single CR2 it's usually faster to use the card reader), but for small files (such as a ML module or a Lua script), uploading it via wifi is much faster. It still needs a camera restart for reloading the script (because Canon's filesystem driver doesn't expect the card contents to be changed externally), but this can be worked around.

Using the USB cable also works; I've tried this approach years ago, but didn't like this setup because of the extra cable (so it's not really ready to use).

QEMU works on Windows as well (though I didn't try to compile it on this platform yet - only ran the binaries from their website). Currently it doesn't emulate LiveView, so it has limited usefulness with Lua for now. It does emulate the GUI side and OS internals pretty well, so it's still useful for testing menu code, graphics, memory usage, multitasking, file I/O, or for hunting bugs (it has some valgrind-like tools).

garry23

@A1ex

Thanks for the insight.

My next 'uplift' is simply getting Lua tested on my PC, ie weeding out silly typos like "=" for "==".

Cheers

Garry

a1ex

This step is easy:

luac -p script.lua


This step is done for scripts placed under magic-lantern/scripts, when you compile the Lua module (look up syntax_check.log in the Makefile).

Random thought: what about making QEMU available as a web service?

garry23

@A1ex

If I understand you correctly, running QEMU without having to do all the coding would be great.

BBA

@garry23

Think we have to move hand in hand with our devs who know things way better then we do.

I am sure they also want to improve the situation and they know the best way (for us) to do it. Please trust me they are able to foresee and weight the amount of work needed. As things go deeper, naïve implementation becomes insufficient or a real burden which can become even worse than what there is now.

@A1ex

Thank you for your help
I also think QEMU as a web service would be great.

BBA

luac can detect syntax errors before execution which is great.

BBA

Look at my naïve prototype for 7 segments display emulation.

https://www.dropbox.com/s/gvv57it6f9ru6u5/SEVEN_SEGMENTS.lua?dl=0


if you have ZeroBrane studio installed you can run it (ask me how to do it if you want).

It is prototyping => used to see what appears on the screen, the aspect ratio, the colors, distance between the chars,...

When it is thoroughly tested and appears ok, it can be integrated in the bigger project.


a1ex

@BBA

Nice one, may I include it in api_test.lua?

BBA

@A1ex
Yes, for ML community, it goes without saying : I fully support open source : I am glad if I can help !
But I am not glad with the script as it is :  it needs OO redesigning, it is slow (many lines), ...

garry23

For those interested in using the focus bar and focus stacking, you may be interested in my latest post: http://photography.grayheron.net/2017/06/close-enough.html

garry23

A minor update, but a useful one.

In DoF mode the focus bar now displays the 10% distances between the the near and far DoFs.

This is useful when deciding overlaps when focus stacking, eg aim for a 10% overlap at least.

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

garry23

Another update: mainly cleaning up the 'user guide' text at the front of the script.

Plus the addition of showing the defocus blurs at the 10% distance points.

http://photography.grayheron.net/2017/06/focus-bar-update.html

ironmarshal

I have been interested in trying focus stacking for a while for landscapes and after coming across your blog (which is a wealth of information) I decided to download ML and give it a try. This Focus Bar seems like a great way to approach it, but as I am new I am unfamiliar with Lua and exactly how to download and install this. I have installed the nightly build on my card, what else do I need to do?

Also, as a future thought, particularly for people like myself that are not programmers, an awesome improvement, which I think many people would appreciate, would be to implement the focus stacking and bracketing as a single function. I'm thinking of something like exposure bracketing where you take one picture and ML then figures out how many additional photos are necessary to cover the dynamic range. In this case, you could either take on image, or press the Set button and then have ML take as photos as necessary to achieve optimal front to back sharpness.

At any rate, thanks again for the great blog and development of the focus bar.


garry23

@ironmarshal

Things should work with the latest nightly, however, you might be better off using the latest Lua fix: http://builds.magiclantern.fm/experiments.html

Simply replace the ML files/folders on your card with the Lua fix experimental ones.

I would then go into the ML Lua folder on your card and go into the scripts folder. Create a new folder (call it whatever you wish) and move all the scripts into there. You now have a clean scripts area, ie no scripts will load other than the ones you wish.

Place my FOCUS script into the script folder and my Auto Bracketing V4 script. Read the text at the beginning of each script, ie a simple user guide.

Replace the card in the camera and switch on.

I assume you have switched on the modules you need. I personally use Lua, Silent, ETTR and Dual, as my scripts tap into these.

Once you have turned those modules on, switch the camera off and on.

Now go to the Scripts tab in the ML Menu and switch on the Autorun for the two scripts that are there. Switch the camera off and on again, to ensure the autorun loading is OK.

If all went well you now have the focus bar running and access to my auto focus and exposure bracketing scripts.

Both these scripts have been fully tested on my 5D3 and the focus bar script on my EOSM.

To run the auto focusing script, simply go into the menu and select what you wish to do and run the script, which focus brackets from the near to the far, either the far DoF or the FP 'at' infinity.

Hope you have some fun :-)

BTW what camera are you using?

Cheers

Garry