1

How to

  1. crop/clip an image with a polygon as the boundary and then
  2. deskew the output using imager and magick package in R?
library(imager)
library(sp)

plot(boats)
xy <-  list(x = c(87.4790282019041, 58.2397610921502, 164.877088198312, 
                  181.216678641998), 
            y = c(49.3995868510868, 131.957517513921, 
                  158.616849290462, 69.1790910723909))
polygon(xy$x, xy$y, border = "red")

enter image description here

poly <- sp::Polygons(list(sp::Polygon(data.frame(xy))), "crop")
poly <-  sp::SpatialPolygons(c(poly))

polyNames <- c("crop")
polydf <- sp::SpatialPolygonsDataFrame(poly, data.frame(1:length(polyNames), row.names=polyNames))
Crops
  • 5,024
  • 5
  • 38
  • 65

0 Answers0