library(magick)
f <- system.file("extdata", "cruise_boat.png", package = "image.dlib")
x <- image_read(f)
x
surf_blobs <- image_data(x, channels = "rgb")
surf_blobs <- as.integer(surf_blobs, transpose = FALSE)
surf_blobs <- image_surf(surf_blobs, max_points = 10000, detection_threshold = 50)
str(surf_blobs)
library(magick)
plt <- image_draw(x)
points(surf_blobs$x, surf_blobs$y, col = "red", pch = 20)
dev.off()
plt
if (FALSE) {
## Plot the points
"as.cimg.magick-image" <- function(x){
out <- lapply(x, FUN=function(frame){
frame <- as.integer(frame[[1]])[, , 1:3] # dropping the alpha channel
dim(frame) <- append(dim(frame), 1, after = 2)
frame
})
out$along <- 3
out <- do.call(abind::abind, out)
out <- imager::as.cimg(out)
out <- imager::permute_axes(out, "yxzc")
out
}
library(imager)
library(magick)
library(abind)
img <- image_read(path = f)
plot(as.cimg(img), main = "SURF points")
points(surf_blobs$x, surf_blobs$y, col = "red", pch = 20)
}
library(magick)
img1 <- image_scale(logo, "x300")
img2 <- image_flip(img1)
height <- image_info(img1)$height
sp1 <- image_surf(image_data(img1, channels = "rgb"), max_points = 50)
sp2 <- image_surf(image_data(img2, channels = "rgb"), max_points = 50)
## Match surf points and plot matches
library(FNN)
k <- get.knnx(sp1$surf, sp2$surf, k = 1)
combined <- image_append(c(img1, img2), stack = TRUE)
plt <- image_draw(combined)
points(sp1$x, sp1$y, col = "red")
points(sp2$x, sp2$y + height, col = "blue")
for(i_from in head(order(k$nn.dist), 50)){
i_to <- k$nn.index[i_from]
lines(x = c(sp1$x[i_to], sp2$x[i_from]), y = c(sp1$y[i_to], sp2$y[i_from] + height), col = "red")
}
dev.off()
plt
Run the code above in your browser using DataLab