Extract SURF features from transparent images

Matteo Ronchetti
May 11, 2018 · 1 min read

When working on my beer recognition project BiBirra I’ve encountered problems loading images that had a transparent background. OpenCV by default mess this images up, and this is especially problematic when we extract SURF features from the loaded image.

The key idea is to load the image with the flag cv2.IMREAD_UNCHANGED that tells OpenCV to keep the alpha (transparency) channel. Then we save separately the alpha channel as a binary mask for latter use.

Notice that when the original image has no alpha channel the mask will be simply returned as None.

Now it is possible to correctly extract SURF features from the masked image


Written by

Italian | Computer Vision | Machine Learning | https://matteo.ronchetti.xyz

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade