Page 1 of 1

Is "Focus Stacking" possible with IM ?

Posted: 2014-05-19T04:08:46-07:00
by Werty
I was wondering if Focus Stacking is possible with IM ?

I'm aware of all the free/commercial products like CombineZ, but I'm looking for something I can script myself, and to avoid including too much third party stuff in my application.

I'm on Win7 32bit so cant use Hadley's IM/CombineZ combo as it requires 64bit Windows, I've also been looking at Enfuse/EnBlend, but again, would be awesome if something similar could be done with IM.

Re: Is "Focus Stacking" possible with IM ?

Posted: 2014-05-19T06:51:54-07:00
by snibgo
If the Hugin tools can do it, that's probably the best solution. Those tools are awesome interactively, and nearly awesome in batch.

IM has lower-level tools, so scripts would have to be built. If the images are aligned, I guess these would be fairly simple, using masks that identify which images have the best focus, along the lines of

Re: Is "Focus Stacking" possible with IM ?

Posted: 2014-06-18T23:56:30-07:00
by whugemann
I am using CombineZP under Win 7 32 bit without problems, so there still must be 32 bit versions around.

I cannot see how the trick could be performed with IM, even by use of a complex script. You would have to identify the (non-rectangular) regions in which some photo has the sharpest focus and then mount all these regions, found in various photos, into a new version of the entire photo.

Even in a dedicated program, this seems to be a tricky job, as most programs don't do a convincing job on that, with CombineZP being one of the exeptions!

Re: Is "Focus Stacking" possible with IM ?

Posted: 2014-06-19T00:12:54-07:00
by snibgo
I don't think it would be difficult with IM. Yes, I know the proof is in the pudding and I haven't cooked it yet, but it's on my list.

My thoughts are: start with two images of the same size.[*] Can we decide, for each coordinate, which image is sharper? Yes. There are various measures, such as the standard deviation of an n*n square around the pixel. This easily gives us an image that is black where image #1 is best, or white where image #2 is best. Use that black/white image as a mask for "-compose Over" of image #1 and image #2.

The concept is easily extended to an arbitrary number of input images. In theory.

[*]Yes, we already have a complication. When a camera focuses, the lens moves in and out, changing the angle of view so images at different focuses need resizing. That's probably the harder problem to crack. A trial-and-error approach might work well.

Re: Is "Focus Stacking" possible with IM ?

Posted: 2014-06-19T00:25:41-07:00
by whugemann
I don't think that CombineZP scales the photos before mounting them together. They are just aligned in the first step.

Ideas for coding can possibly be taken from Fiji/ImageJ, which also provides a Java module for focus stacking and is Open Source.

Your basic idea – to calculate the sharpness in the neighbourhood of each pixel an then just take the pixel with the highest value - sounds convincing. Could possibly be performed with fx:, which however lacks a genuine max operator, working on an array (and not just two values).

Re: Is "Focus Stacking" possible with IM ?

Posted: 2014-06-19T02:22:10-07:00
by snibgo
My theories often sound convincing until they fall apart. Nevertheless, the camera is charged up, and I'm just waiting for a bit of sun on a handy brick wall.

I avoid fx for 35 Mpix images. Life is too short. "-compose MinusSrc -composite -fill White +opaque Black" is a useful "less than" operation.