Template matching with transparent regions
Kevin Keraudren
kevin.keraudren at gmail.com
Thu Nov 12 04:07:53 EST 2015
Hi Stefan,
Thanks for correcting me! Looking at the template matching code, I think you will have difficulties making it work with non square templates as long as you use fftconvolve(). You need to have a custom convolution code so that you can skip parts of the template as well as the corresponding parts of the image.
However, what you want can be achieved in a brute force manner with a few lines of Python (as long as you are working with 2D images of reasonable size!), using:
from sklearn.feature_extraction.image import extract_patches_2d
from scipy.spatial import distance
See example attached.
Kind Regards,
Kevin
> On 11 Nov 2015, at 08:08, Stéfan van der Walt <stefanv at berkeley.edu> wrote:
>
> I think kwc meant that he wanted parts of the template to be ignored. I have the same problem at the moment, so will have to investigate soon if no other dev informs us how :)
>
> Stéfan
>
> On Nov 10, 2015 12:26 PM, "'Kevin Keraudren' via scikit-image" <scikit-image at googlegroups.com <mailto:scikit-image at googlegroups.com>> wrote:
> Hi,
>
> What about simply masking out in the matching results the region you want to exclude:
>
> import numpy as np
> from skimage.feature import match_template
>
> ...
>
> matching_result = match_template( image, template, pad_input=False )
>
> matching_result = np.array(matching_result)
>
> # mask out the region you want to exclude
> matching_result[mask==0] = 0
>
> # coordinates of the best match
> best_match = np.unravel_index( np.argmax(matching_result), matching_result.shape )
>
> See this example to better understand what matching_result should look like:
> http://scikit-image.org/docs/dev/auto_examples/plot_template.html <http://scikit-image.org/docs/dev/auto_examples/plot_template.html>
>
> Kind Regards,
>
> Kevin
>
>
>> On 10 Nov 2015, at 09:11, 'kwc' via scikit-image <scikit-image at googlegroups.com <mailto:scikit-image at googlegroups.com>> wrote:
>>
>> Hi, I am new to scikit-image. I would like to use the Template Matching function in scikit-image.
>>
>> In my template image, there are some regions that I would like to ignore or exclude from the template matching process. I plan to change those regions to become transparent (alpha channel). Does the alpha channel have any effect on the template matching result?
>>
>> Thanks.
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups "scikit-image" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe at googlegroups.com <mailto:scikit-image+unsubscribe at googlegroups.com>.
>> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google Groups "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe at googlegroups.com <mailto:scikit-image+unsubscribe at googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to the Google Groups "scikit-image" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe at googlegroups.com <mailto:scikit-image+unsubscribe at googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout <https://groups.google.com/d/optout>.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151112/4fe419ad/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: figure_1.png
Type: image/png
Size: 133334 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151112/4fe419ad/attachment.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151112/4fe419ad/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: match_template.py
Type: text/x-python-script
Size: 1530 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151112/4fe419ad/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/scikit-image/attachments/20151112/4fe419ad/attachment-0002.html>
More information about the scikit-image
mailing list