image-rs / imageproc

Image processing operations
MIT License
735 stars 145 forks source link

Template matching with a mask #567

Closed F8RZD closed 4 months ago

F8RZD commented 5 months ago

open cv provides a mask argument for their template matching function

mask specifies the pixels that can be ignored during the matching progress

it's very useful for transparent or white background image template matching

I couldn't find any similar functionality here is it planned to be implemented?

any help would be appreciated

cospectrum commented 5 months ago

I'll try to implement

F8RZD commented 5 months ago

Sharing my implementation idea: Having an u8 array of the same dimensions as the template image as the mask.

And each pixel on the mask would specify how important that pixel is. I haven't read how the present template matching works but assuming every pixel after calculations has a score value from 0 to 1.

something along these lines would be great:

let final_score = pixel_score * (mask_pixel_value / 255);

then users can decide whether they want to use a binary mask (only including 0 and 255) or they want a more smoother one.

cospectrum commented 5 months ago

There is no need to guess

template_matching_opencv