Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring Template Matching Discussion #312

Open
JonBoyleCoding opened this issue Feb 1, 2019 · 3 comments
Open

Refactoring Template Matching Discussion #312

JonBoyleCoding opened this issue Feb 1, 2019 · 3 comments

Comments

@JonBoyleCoding
Copy link
Contributor

When looking at the template matching to add cross-correlation (#311) I came up with a few things that might be an idea for refactoring; however, I thought it would be worth making a discussion before actually doing the work if it's not going to be wanted.

  • Each of the template matching in https://docs.opencv.org/3.4/de/da9/tutorial_template_matching.html has exactly the same normalization term.

    • Would it be better (wanted) to have a separate argument to the template match function to specify whether to normalize? Otherwise the MatchTemplateMethod is going to have a lot of duplications and the various checks for methods are going to be increased two-fold whereas it could just become one function parameter.
  • Currently the method can only accept single-channel grayscale images. The conversion to grayscale isn't always the same and isn't necessary for template matching in general. I've messed around with converting the function to accept any number of channels and data types and it should be possible, although will definitely complicate the code.

@theotherphil
Copy link
Contributor

Both of your suggestions sound good to me.

@JonBoyleCoding
Copy link
Contributor Author

I finally found some time to work on this. I have a working version of the second point, taking a GenericImageView as an argument instead of grayscale (works with current tests, need more for different types), however there is an issue with using the ArrayData::DataType that is returned from sum_image_pixels as the compiler can't seem to index into it when Pixel type is a generic.

I made a workaround for the moment; however, it changes the API of sum_image_pixels in integral_image to turn the ArrayData::DataType back into the pixel it is from: https://github.com/JonBoyleCoding/imageproc/tree/template_matching_update

I was wondering if you had any thoughts on how this might be best approached.

@JonBoyleCoding
Copy link
Contributor Author

I thought I would link to the actual files.

https://github.com/JonBoyleCoding/imageproc/blob/template_matching_update/src/template_matching.rs
https://github.com/JonBoyleCoding/imageproc/blob/template_matching_update/src/integral_image.rs

If you would rather I did this via pull request, I can do that as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants