PetteriAimonen / focus-stack

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

Focus stack library #16

Closed crysta1c1ear closed 2 years ago

crysta1c1ear commented 2 years ago

focus-stack library

I am a little reluctant to open this as an issue, since the software is working well, and anything that isn't working well here is probably as a result of me dabbling with it!

I have been focus stacking images from a microscope and it's useful to have the focus stacking done in the software, rather than export the images, focus stack them from the command line, and reimport the result.

For this reason, it's useful to split the focus stacking software into two parts:

  1. the command line program which reads files into cv::Mat and stores a cv::Mat result back into a file, and
  2. a library which can focus stack a vector of cv::Mat images and create a cv::Mat result

I know the aim of the program is to be stand-alone.

branch?

Would it be worth having a branch which can create a focus-stack library? Note: This can be assigned to me. I'm not asking for anything! ;)

Example library files

FocusStackLibrary http://harmonica.hopto.org/WORK/Focus-Stacking/FocusStackLibrary.PNG

Example request for focus-stacking on a microscope

Summary http://harmonica.hopto.org/WORK/Focus-Stacking/Summary.PNG

Example focus stacking result (not uploaded)

A focus stacking result, with two of the pre-stacking images ... http://harmonica.hopto.org/WORK/Focus%20Stacking_Human_Hair_10x/

PetteriAimonen commented 2 years ago

Compiling a library version makes sense. In fact, I recently developed a library version for a client, but for now they have preferred to keep that code private.

For C++ programs, the code can be compiled as a library very easily: just build all files except main.cc and put them in a library. This only needs some build rules. The main focus-stack program can remain as is, just build a .so in addition. The library API is in focusstack.hh.

For C programs and as an interface to other languages, some wrapper functions are needed. These could be something like focusstack_create() to create a FocusStack object, focusstack_add_image() and focusstack_start(). These would just call the methods of the FocusStack object.

crysta1c1ear commented 2 years ago

That's pretty much what I did. In addition I needed to avoid the reading and writing of files using filenames, as the software I am using creates the cv::Mat file from the microscope camera and creates its own output files in addition to displaying the result etc. It simply turns a vector of cv::Mats into a result cv::Mat.

Thanks for your feedback. You may want to close the issue.

PetteriAimonen commented 2 years ago

Yeah, you can specify :memory: as the output filename to avoid writing to files.