This is actually a pretty hard computer science problem, and you may be better off using existing software tools rather than writing your own. However, it may be a fun learning project. What you want to google is "algorithm convert bitmap to vector". Your "normal image" is a bitmap image: a grid of colored pixels. And you want to convert it to a list of colored shapes, which is called a vector image.
Answer copied from a reddit post:
This is actually a pretty hard computer science problem, and you may be better off using existing software tools rather than writing your own. However, it may be a fun learning project. What you want to google is "algorithm convert bitmap to vector". Your "normal image" is a bitmap image: a grid of colored pixels. And you want to convert it to a list of colored shapes, which is called a vector image.
This twitter feed has some examples: twitter.com/PrimitivePic
It has a brief explanation here: primitive.lol/