Enhancing our search with the analyze image cognitive service

Posted by

Last week we used the Bing image search cognitive service to help us to find images on the internet we didn’t previously have. If the first image wasn’t relevant, we used the search results to allow us to display and pick the next best image. What if we could use AI for this manual picking process, to find a more relevant image auto-magically? Today we are going to use another cognitive service to achieve that.

Analyzing images with AI

Microsoft Azure has an “analyze an image” cognitive service, that can return a lot of different pieces of information. In particular for us, we noticed that it can identify Lego.

In contrast, one of our sets returned the following image as the top/first image last week. These tags do not contain the Lego tag, as it’s clearly a property listing photo.

Given this information, we know that Lego models have a distinct tag identifier – the name “LEGO”. We are going to perform our Bing image search, and then analyze each image. If the image doesn’t contain the “LEGO” tag, we can discard that image. This will help guarantee that we only select and show pictures that contain the Lego tag. This is much more efficient than opening the image picker and removing the images ourselves – a very manual process for us.

Setting up the Analyze image API call

We start by reading the API for the Analyze image call. Since we are looking at images online, we will use the imageUrl call. We pass in tags, and plan to look for the tag “Lego”. In the example below, in theory, this should filter out the last two images. We are using the same cognitive services resource we created last week, so we use the same subscription key too, (in blue below). You’ll note in the query string we request for “Tags” to be returned in the response, in English, (in red below). The image we are processing, needs to be passed inside a Json document, which we can create and serialize using the JsonConvert command, (in green below). We then send the request, and process the response, returning each tag and the confidence in that tag (as a percentage). Here is the completed code.

With this new code, we also update our image picker page. Instead of getting the first 10 images, we get the first 20 images, throwing away any images without Lego until we get to 10 images. (Note that it’s possible we could end up with less than 10 remaining images). Here is the current page for an X-Wing, note the two false-positive pictures of houses.

After the update, we can now see it is only showing pictures that contain Lego.

Wrap up

We’ve automated our main image selection and image picker to only display Lego images with a powerful automatic filter! While the cognitive services are useful by themselves, we can see that combining two or more cognitive services together is super powerful. We will continue to look for other opportunities to use cognitive services in the future.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s