Image Cropping with the Vexcel API

A nice new feature was added to the Vexcel API this week; the ability to crop an image to an arbitrary shape, masking off the rest of the image in black. This is very useful in computer vision applications where you don’t want neighboring pixels to interfere in the analysis. A couple of example use cases:

  • when looking for rooftop solar panels, you can crop the image to the building footprint or parcel boundary of the target property so that an adjacent home with solar panels will not interfere.
  • when assessing damage after a hurricane, cropping to the building footprint will prevent the debris field from the storm from coloring the analysis of the target structure.

Lets look at an example. This is a typical image with three homes in it.

If you want to limit the analysis to the building at the center, you can pass a polygon in well known text format as shown in this URL. Also, you’ll want to set the ‘crop’ parameter to ‘exact’.,-105.270888%2040.053184,-105.270891%2040.053073,-105.270795%2040.053072,-105.270794%2040.053094,-105.270625%2040.053091,-105.270623%2040.05318))&AuthToken=YOURTOKEN

Here is another example utilizing recent imagery from the Oregon wildfires. In this case, cropping to the building footprint prevents neighboring properties from adversely affecting the results of analysis to determine if the building has been destroyed or not. Here is the API call: 45.013188,-123.913915 45.013288,-123.913922 45.013306,-123.914021 45.013333,-123.914005 45.013361,-123.914012 45.013379,-123.914257 45.013447,-123.91427 45.013442,-123.914314 45.013363,-123.914307 45.013345,-123.914215 45.01332,-123.914242 45.013272,-123.914235 45.013254,-123.913984 45.013183,-123.913971 45.013188))&AuthToken=YOURTOKEN

and the resulting image:

without cropping:

Here are a couple of additional helpful resources. Microsoft has made large sets of building footprints available for the United States and Canada. You can download them in convenient zip files here.

When passing in a polygon representing a land parcel or building footprint, you might want to buffer or ‘inflate’ the polygon before passing it in. This can be helpful as your geometry might not match up with our imagery perfectly; allowing a bit of fudge factor can insure the entire intended area is included in the cropped image. I’ve used the Clipper library for this and have found it convenient and easy to use. It can also be installed via the NuGet package manager. In the second example above, Clipper was used to inflate the footprint by 20%.

Leave a Reply

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

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

Facebook photo

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

Connecting to %s