DevCom is happy to announce that our Project Lead Andy Bosyi has created a free R package which quickly and precisely vectorizes raster images into polygons.
Recently DevCom has started a very interesting R project related to data science and geometry. The idea was to calculate complex projections of numerous shapes. As we started with a “clean” mathematical solution, it quickly ended up with a huge number of calculations related to polygon triangulation – O(log n!).
After a week we realized that for real scenarios the process took much more time than we previously expected. As a possible solution, we decided to get the result in a form of a matrix. It led us to search for image vectorization in R packages, available on CRAN repository (The Comprehensive R Archive Network). The package we chose (https://cran.r-project.org/web/packages/raster/index.html) supplied a RasterToPolygons function, though, produced too many points for the polygons.
However, our Project Lead Andy found a significantly cost-effective solution – why not consider creating an R package on our own?
How does it work?
Below is described a code sample on how to use the current package:
inp = volcano;
res = raster2vector(volcano, 120, 200, 20);
image(inp, col = rev(grey.colors(100)), useRaster = TRUE)
plot(0, type = “l”, xlim = c(0, nrow(inp)), ylim = c(0, ncol(inp)))
a = lapply(res, function(x) lines(rbind(x, x[1,])))
The vectorization results can be seen on the example above. Here you can find a piece of temperature map vectorized in temperature layers. Overall, the package deals with different raster types, starting from simple images and photos and ending with text image vectorization.
Where to find it?
You can find the source package here: fasteraster_1.0.4.tar
The Linux 64 binary is available here: fasteraster_1.0.4_R_x86_64-pc-linux-gnu.tar
OR you can get it right from CRAN: cran.r-project.org/web/packages/fasteraster/