Query on Zernike moments as library feature

Hi skimage team,

Myself, Ashu. Very happy to have a python library solely focused on traditional CV. I wanted to ask about Zernike moments (ZMs) as feature descriptors. As far as I know, there is no implementation in the skimage library. I have searched ‘zernike’ keyword on the website, in skimage forum, Zulip chat, issues on github, my recent forked repo of skimage. Couldn’t find any mentions or results. Is it being implemented currently, or maybe skimage2? Was it planned in the past then dropped from the library for some reason?

ZMs are used extensively in optical systems for aberration corrections, where I learned these. I have read the issue #4375 (Show and tell) on GH and see people using skimage for microscopy, shape, defect analysis etc. Assuming there is a need and it’s not being developed, will the community be interested in Zernike moments as a new library feature? If so, I would like to develop it, or help if someone is developing it.

Zernike moments refresher: Given an image, a unit circle centered over the image/object (circular pupil in optical systems, circular bounding box in object detection), Zernike moments are image weighted average of Zernike polynomials. There are three terms here: polynomials are complex valued basis functions which iterate over frequencies (cos(1,2,..,Mθ)); moments are image/object pixel intensities weighted average of these polynomials; features are magnitude of these complex moments. Degree n is a design parameter for the user, and fitting a degree n polynomial gives a feature vector of length (n+1)*(n+2)/2. So a degree=9 will give to the user a feature vector of length 55 with values between 0 and 1 (normalized).

For development and library features, and assuming not being developed by someone, I have the following in mind:

  • Develop the base Zernike moments (zernike.py) using pure python. This is to familiarize myself with the skimage contribution standards and procedures. I will implement feature, interface, documentation, references, tests, examples etc., then generate a PR. Please critique any minor to major changes. For the math heavy work, I want to ask if someone can verify the implementation.
  • Develop the cython extension for faster computation. Here I will need help from the core team as I am not quite familiar with cython and skimage build process. I will provide a working extension (zernike_cy.pyx), but will need help optimizing it. If we imagine a user iterating through thousands of images/objects, the aim is to compute the features very fast (<1s per image/object).
  • Once the base Zernike is optimized and finished, I have 4/5 more Zernike related library features in mind. If interested, I will build these and we can gradually roll out.

Please let me know if this would be something community is interested in, how would you like to proceed, your thoughts on development, and anything else.

Thanks,
Ashu

A long while back I had a need for Zernike moments and I wished there was a library that had them implemented. It’s one of those things that are good to have just in case.

Hey @aacvysion, thanks for reaching out, sorry for taking so long to reply.

My knowledge regarding Zernike moments is almost non-existent, so I can’t really comment on whether we want this feature or how difficult it would be to implement. Are there already existing implementations in Python?

But I can raise your original request in our community meeting (next Tuesday).

That said: we are currently in the middle of refactoring our API to a more consistent state so our resources are very tied up right now. So you’d probably have to be pretty self-sufficient when it comes to implementing the feature. Do you already have experience with bigger contributions to open source projects?

Given that we provide Hu moments, we should for completeness probably include Zernike. @martinberoiz are you interested in working on this?

Yeah @lagru, please let me know what will be the thoughts of the community in the meeting next week.

AFAIK, only mahotas library provides ZM implementation. There are individual repos and packages, but I don’t know which ones are popular and how they are used.

I already have a base ZM working with python, numpy, and multiprocessing. It takes ~4 secs to process one 640x640 image on my PC. I am following the contribution guidelines, so I can raise a PR in a few days with ZM module, docs, examples, tests etc. This can provide a base, so if a senior dev may want to takeover for any reason, we will have a good starting point at least.

Where I need help will be to verify the mathematics, with optimizations and Cython extension so as to make it faster, a recommended place for communication whether for minor questions or in-depth discussions (Zulip, GH PR thread etc), and all this adhering to skimage standards.@martinberoiz please let me know if you’re interested, or if anyone else in the meeting may express an interest, to work in any capacity.

Thanks for the consideration, but I forgot a lot about Zernike moments that I’m no longer confident I can do a good job on my own. I think @aacvysion can lead this and maybe I can help if help is needed, just let me know.