isi-vista / adam

Abduction to Demonstrate an Articulate Machine
MIT License
11 stars 3 forks source link

Use pyBPL for stroke extraction #1158

Open spigo900 opened 2 years ago

spigo900 commented 2 years ago

We'd like to convert the stroke extraction code (#1151) to use PyBPL once we have things working. Our current GNN processing code in #1151 uses Matlab BPL with some modifications by @shengcheng. It would make documenting setup easier if we could use Python for this component instead. There is a partial Python implementation of BPL. It would be nice if we could use a modified version of pyBPL instead of calling out to Matlab.

The first step here is determining if this is possible. It looks like this might not be, because pyBPL uses the Matlab API for some parts that aren't yet implemented. Stroke extraction might be one.

(In theory we could reimplement the stroke extraction logic ourselves, maybe calling out using say opencv-python (or similar tools) but I expect that's probably more work than is worthwhile at this point.)

spigo900 commented 2 years ago

Since I just looked through the code, it might be some help to point out that AFAICT anyway the stroke extraction code uses only three exports from BPL:

Unfortunately, it doesn't look like PyBPL covers these at the moment. So if we want to replace them we would have to re-implement those parts ourselves.

I think rewriting this ourselves is doable but there are bound to be some difficulties. It's doable because there are only ~600 or 700 lines of code total, with no randomness and nothing that looks obviously irreplaceable to me. As for difficulties, I think potentially the most annoying here is finding equivalents for Matlab's image processing functions, specifically edge(), imdilate(), imbothat(), bwmorph(), and bwconncomp(). (These are the functions I noticed were used in ske.m and its dependencies.) Pillow or OpenCV might be useful if we decided to go down that route.

lichtefeld commented 2 years ago

For now let’s have this rewrite as a lower priority given we have the matlab version functioning. It be nice to only need to invoke Python scripts for processing but this may be a larger project time wise than we want to tackle before the demo.

spigo900 commented 2 years ago

@lichtefeld I agree.