PetteriAimonen / focus-stack

Fast and easy focus stacking
MIT License
249 stars 37 forks source link

Reducing the memory needed #12

Closed raduprv closed 2 years ago

raduprv commented 3 years ago

I tried to run it on a Raspberry Pi 3, with 1 GB of RAM (around 600 mb free) to focus stack some 18MP images. The program crashes (gets killed) after 10 pics or so. I was wondering if it would be feasible to add a mode where only a few images are processed at once, and then the results of those merges are merged with each other in order to allow for an arbitrarily number of pictures to be merged. Some guys use 10K+ photos in a stack, so probably that wouldn't work even on server grade computers.

PetteriAimonen commented 3 years ago

That's already how it works after #4 was fixed.

The batch size is 8 images, each of which will have a 1-3 temporary copies, one of which is in 32-bit float space. A 18MPixel image takes 72 MBytes itself and 216 MBytes as floats, so you can expect around (722+216)8 = 2880 MByte usage just for the images for each batch. In practice this will vary a bit depending on how the individual tasks get scheduled, as all temporary copies are freed as soon as possible.

You could try --threads=2 or --threads=1 to reduce the number of parallel tasks. With a single thread the memory consumption should be the lowest currently possible.

For such large images, one would have to batch not only individual images, but process only a small area of each image at a time. That may be a worthy option to add in the future, but I'm not currently planning to do so. It would complicate the alignment quite a bit, though perhaps per-area alignment could also be beneficial if done well (avoiding seams between blocks).

raduprv commented 3 years ago

Hmm, would it be possible to have lower batches, such as 2 pictures instead of 8?

PetteriAimonen commented 3 years ago

You can try modifying it here, perhaps it could even be brought out as a command line option: https://github.com/PetteriAimonen/focus-stack/blob/master/src/focusstack.cc#L102