PetteriAimonen / focus-stack

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

align: heavy distortion #33

Open mviereck opened 1 year ago

mviereck commented 1 year ago

Hello,

I have issues with the alignment of focus-stack. (I use it regulary with --align-only). Some image stacks, notably those from microscopic capture, become heavily distorted. If I add option --global-align, it becomes better, but still not good. I've uploaded an example that is even better aligned if I don't align at all: https://e1.pcloud.link/publink/show?code=XZHmdYZlHYAeNKEzCX4sNhMuLJBIzcJfsY7

I assume one reason for the distortion is that regular macro images need some size adjustment due to different camera or lens positions. However, microscopic captures would not need that.

I want to ask you if you could check this. My issue might already be solved if there is an option to disable distortion at all.

focus-stack 1.3-18-g92ec4a2, built Nov  3 2022 17:05:15
Compiled with OpenCV version 4.5.1
PetteriAimonen commented 1 year ago

Hmm, I get the same problem with that image set. One thing that I notice is that there is quite a bit of dust on the sensor that moves in relation to the actual image content, but even that shouldn't cause such large errors.

I noticed that if I comment out the pre-alignment step on task_align.cc line 76, it works better for some reason:

 /* match_transform(256, true); */

That should be pretty much no-op when the stack is quite well aligned to start with, but it ends up messing up the alignment instead.

I'll try to find out why this happens.

PetteriAimonen commented 1 year ago

OpenCV had a quite heavy blur in findTransformECC() by default, which blurred away all the detail in these images. After that the rough alignment was quite random, and that messed up the fine alignment also.

I adjusted the parameters a bit, which seems to have fixed this case and still works well for other image stacks also.

PetteriAimonen commented 1 year ago

(Sorry, had a small mistake first time I pushed that commit, should work now)

mviereck commented 1 year ago

This looks very good now, thank you very much! And thanks for your quick reply and fix.