Categories
The Science of Raster to Vector Conversion

Why Bezier Curves Are Great For Raster To Vector Conversion

Unbeknown to you, you may have drawn Bezier curves while growing up. Perhaps because the process was fascinating or the result was spectacularly beautiful. All you needed then was a pen/pencil, blank paper, and a ruler.

You first drew two lines, that were either perpendicular or at an angle, and subsequently marked equidistant points along each line. You then joined the first point on line 1 to the last point on line 2 and repeated this for all the points. Are you still in the dark? Let me jog your memory. Do you remember creating a replica of the image below?

A Curve Created using Straight Lines
A Curve Created using Straight Lines Source

What you didn’t know then is that you were creating a quadratic Bezier curve from multiple linear Bezier curves through a process called linear interpolation. In the image, each line joining the two points is referred to as a linear interpolant.

Bezier curves are based on the principles of calculus. They’re a type of spline vector, which is a mathematical way of representing curves. These curves were first defined by Pierre Etienne Bezier, a French engineer and designer working for Renault. He patented and popularized the curves.

But Wikipedia notes that although Pierre publicized Bezier curves, he wasn’t the first to apply these curves to CAD. Instead, this was the work of Paul de Casteljau who came up with the de Casteljau algorithm – a method through which he evaluated the Bezier curves. At that time, they were known as the Bernstein polynomials. But Pierre obtained the idea and ran with it.  

Applications of Bezier Curves

In computing, Bezier curves feature prominently in computer graphics because they produce smooth curves passing through specific points. They’re also dynamic because dragging the control point updates the entire curve automatically. Furthermore, unlike polygonal lines, Bezier curves still appear smooth regardless of the scale.

These factors have made Bezier curves ideal for not just 2D or 3D software but image editing software as well. From Photoshop to 3ds Max, Blender, Adobe Illustrator, and Adobe After Effects, you’re likely to utilize Bezier curves in one way or another. The underlying similarity in all these applications is the fact that using the different software results in creating some form of art.

The computer has replaced traditional methods of art creation, and with this development, terminologies that describe the new forms of art and methods have arisen. Two of these terminologies are raster and vector images. In cases where the noun image hasn’t been used, you’re likely to see the terms raster and vector graphics. They’re somewhat the same.

Raster Images

In raster images, the underlying graphics create a digital image by grouping individual pixels in grids – with each pixel storing a distinct color. Lines, curves, and arcs are also formed when the pixels along the desired path are colored.

Related: Mending Breaks in Raster Lines for Successful Raster to Vector Conversion.

The emphasis on the role of pixels in creating the image implies that raster images are resolution-based. As such, they cannot be scaled without the image losing its quality and becoming grainy. When the magnification is too much, it even becomes easy to pick out the individual pixels. This makes deciphering the color that each pixel stores effortless. Artistically, therefore, raster images should always remain at the original scale and resolution. 

The modification makes things worse, particularly if it involves magnifying. Editing, on the other hand, is much more intricate since the editor has to manipulate individual pixels. For instance, if you intend to change color or object, you have to do this at the pixel level. For a large image with many pixels, this becomes time-consuming work.

Examples of Raster Images

You may have come across file formats such as PNG, PDF, GIF, and JPEG. Those are everyday formats, which, even without advanced technical know-how, you’ve come across. Raster images can also be stored as BMP, TIFF, IMG, and CALS files.

You can create a raster image by taking a photo using your phone or digital camera, scanning a photo or hand drawing. Alternatively, you can create a raster image using Adobe Photoshop or any raster-based software, e.g., Microsoft Paint, Corel Painter, and PaintShop.

Vector Images

Unlike raster images, vector images are editable regardless of the scale. This ease of editing emanates from the fact that vector images are created from graphics that use a sequence of points, curves, lines, and polygons. All these geometrical components – known as primitives – are anchored on mathematical equations.

Given the mathematical basis, then scaling becomes seamless because the only requirement is multiplying the analytical description – based on the equation – with a factor, which changes the entire mathematical equation. As a result, editing vector images is easy because they’re independent of resolution. They retain their original quality and sharpness even under intense magnification as you can see in the image below.

Differences between Raster and Vector Images
Differences between Raster and Vector Images Source

Furthermore, vector images can be animated much more quickly and easily than raster images. How? By simply animating the geometrical aspects, namely, curves, lines, points, and polygons. With vector images, an artist has a wide array of tools to create and manipulate the image without loss of quality.

Complementation

However, vector images still lag behind raster images, particularly with regards to how they represent complex shapes and colors. In these vector images, the color and shapes are simply limited to what was initially used to describe them. On the other hand, raster images capture complex shapes, a factor that makes them ideal for photography.

But CAD software packages don’t use photographs, do they? In fact, they’re responsible for making vector images, which is why vector image file formats include DWG, DXF, DGN, SVG, EMF, WMF, and HPGL. You can also create vector images using Adobe Illustrator, a vector-based software.

Because CAD software are vector-based, then converting raster images to vector images becomes a necessity since raster and vector are complementary. The limitations of one are remedied by the other.

Raster to Vector Conversion

The process of converting raster images to vector images is referred to as vectorization. Vectorizing raster images works by extracting geometrical or vector aspects – points, curves, lines, and polygons – from raster images.

Vectorization Methods

Many vectorization methods exist, some of which are proprietary. Adobe Live Trace divides an image into regions whose color is either constant or slowly varying. It then fits polygons into these regions. Given that the segmentation is done based on color, a solid color is allocated to each of the resultant vector aspects. However, this becomes problematic in raster images that don’t feature many uniform color areas.

The second method is known as the ArDeco System. It uses linear or quadratic gradient aspects. Like the first vectorization method, the ArDeco System segments the image into regions wherein the color varies slowly. It then approximates the color variations within each region using either linear or quadratic gradients. This results in vector primitives that follow the SVG standard. The image below represents the ArDeco System. 

ArDeco System
ArDeco System Source

The third method entails fitting a gradient mesh to the image automatically.

Each of these methods follows the same vectorization steps.

Vectorization Steps

  1.     Extract edges, color, and blur information

In digital images, edges are points at which the image brightness changes sharply. They also contain the most important visual information within the image.

  1.     Vectorize the information obtained in step 1

This step results in a set of diffusion curves, as you can see in the image below. Diffusion curves are one of the most popular vector graphic primitives. They combine cubic Bezier curves with color control points attached on two sides of each curve to create high-quality vector images.

Raster Image of a Dolphin
Raster Image of a Dolphin Source

 

Diffusion Curves
Diffusion Curves Source
Converted Vector Image of a Dolphin
Converted Vector Image of a Dolphin Source

Diffusion curves and Bezier curves

Diffusion curves are a popular vector graphics primitive, and they make use of Bezier curves – the curves are Bezier curves. By extension, therefore, Bezier curves are popular in raster to vector conversions.

Vectorization starts with the determination of edges, colors, and blurs. This information is extracted. The extraction of the data about edges leads to the definition of boundaries. And this is where Bezier curves play a crucial role.

Bezier curves are diffusion curves’ geometric primitives. Whenever a boundary has been determined, the diffusion curves employ the Bezier curves to describe the boundary. The diffusion curves go beyond this by then attaching color constraints on either side of the Bezier curves. This simply means that diffusion curves are Bezier curves with color constraint attachments on each side. But why are Bezier curves great?

Why Bezier Curves are Great

Bezier Curves are Dynamic

Bezier curves are dynamic. Manipulating their control points causes the entire curve to shift automatically, changing the length of lines and angles. As such, Bezier curves are easily editable.

Their dynamism makes them ideal for defining boundaries and is one reason that makes Bezier curves great for raster to vector conversion. It also makes Bezier curves so effective that the control points need not be explicitly defined. Instead, the control points usually form at the point closest to a clicked position.

Bezier Curves are Mathematical

Image processing applications extensively use the Poisson equation, particularly because it shifts image manipulations from a color space to a gradient space, wherein the color or image variations are independent of the original colors. By solving the Poisson equations, the image-processing software reconstructs an image from a gradient while minimizing any color discontinuities – the diffusion is smooth.

Remember that Bezier curves are mathematical equations. As such, they can be easily integrated into relevant image manipulation equations without being problematic.

Bezier curves refit deformed shapes

Raster images are known to become distorted when magnified to a greater factor. In images whose quality has been distorted or those whose shapes are deformed, Bezier curves always come to the rescue. You should note that for better and more accurate results, more mathematical considerations and formulas are required.

But even with this in mind, the underlying fact is that Bezier curves still fit deformed shapes, albeit after much effort.

Representation of Irregular Curves

Bezier curves are a useful way of representing even the most irregular of curves smoothly. In such cases, representing the irregular curves requires a combination of several Bezier curves. Moreover, Bezier curves are useful because their very nature enables them to connect smoothly with each other, particularly in these setups.

These four reasons make Bezier curves a great inclusion during the conversion of raster images to vector images. At Scan2CAD, we employ the best and most advanced vectorization techniques in our ultimate vectorization software. We’ve also prepared a complete guide on how you can convert raster to vector images – read it for more information on vectorization.