Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

How to make a polygon from images?

Seffana_
7 - Meteor

Hi, 

 

Does anyone know any good resources on how someone can make polygons out of images?

 

I am a complete noob at anything to do with spatials or polygons, and would like some tips and guidance if anyone has anything to offer.

 

How could one go about making a polygon from the spidey image below, for example? Is this even possible?

 

spiderman.jpg

 

Thanks in advance!

 

Seffana

6 REPLIES 6
WilliamR
Alteryx
Alteryx

Hi @Seffana_ ,

I am afraid you need some image processing algorithm for that purpose. Are you comfortable with python?

You need first to use some libraries to extract some features of your image (OpenCV is a good starting point): https://www.pyimagesearch.com/2016/02/08/opencv-shape-detection/

After, you will need to convert your new image in shapefile but nothing out of the box I think.

You project is not an easy one...

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

RishiK
Alteryx
Alteryx

@Seffana_ 

 

I assume you want a way to analyse images?

 

Have a look at this post:

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/Images-analysis-is-possible-in-alteryx...

PhilipMannering
16 - Nebula
16 - Nebula

Hey @Seffana_,

 

The TL;DR is that you cannot with PNGs or JPEGs but might be able to get some semblance of the original image if you use SVGs.

 

A JPEG or PNG gives the color values pixel by pixel so it's near impossible to get any polyline or polygon information from them - you could use some form of edge detection but that would be beyond me and probably more trouble than it's worth. An SVG, however, is a vector graphic that contains the path information in the file.

 

Here's an example of an SVG (original on the left and simplified using graphics software on the right just to get the edge information)

SVGSVGSVG outlineSVG outline

If you open up the SVG in a text editor you can see the path information (which has all the coordinates) is in the form of XML.

SVG in the form of XMLSVG in the form of XML

 

Since the SVG is XML you can input the spiderman.svg file into a workflow as XML then parse out the coordinates, create points and create a polyline,

WorkflowWorkflow

 

What I haven't solved for is that SVG path is often represented as a Bezier curve and I'm only able to create straight lines from point to point. Maybe one day I'll learn to interpolate the points so Spiderman doesn't look so angular.

 

I tried converting your image to an SVG (there are some free tools on the internet that do this) but the results weren't pretty.

 

Hope any of this helps.

 

P

 

 

 

Seffana_
7 - Meteor

Hi @PhilipMannering,

 

Thank you so much! The detailed explanation was really helpful! 😃

AlbertP1
Alteryx
Alteryx

This is great!

Do you happen to have the svg file with this flow you've created? It's currently not attached in the package.

Seffana_
7 - Meteor

Hi @AlbertP1, I believe the images in this link is what @PhilipMannering used in his solution workflow. 

 

I would've attached them in this comment but .svg files aren't supported, annoyingly.

Labels