combine.tr | R Documentation |
Combines rigid tranformation matrices in the following order: translation of points to origin (0, 0) -> reflection of points -> rotation by alpha degrees and translation of points to new center
combine.tr(center.cur, center.new, alpha, mirror.x = FALSE, mirror.y = FALSE)
center.cur |
(x, y) image pixel coordinates specifying the current center of the tissue (stored in slot "tools" as "centers") |
center.new |
(x, y) image pixel coordinates specifying the new center (image center) |
alpha |
Rotation angle |
mirror.x |
Logical: mirrors x or y axis if set to TRUE |
mirror.y |
Logical: mirrors x or y axis if set to TRUE |
## Not run: library(imager) library(tidyverse) im <- load.image("https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/Aster_Tataricus.JPG/1024px-Aster_Tataricus.JPG") d <- sRGBtoLab(im) %>% as.data.frame(wide="c")%>% dplyr::select(-x,-y) km <- kmeans(d, 2) # Run a segmentation to extract flower seg <- as.cimg(abs(km$cluster - 2), dim = c(dim(im)[1:2], 1, 1)) plot(seg); highlight(seg == 1) # Detect edges dx <- imgradient(seg, "x") dy <- imgradient(seg, "y") grad.mag <- sqrt(dx^2 + dy^2) plot(grad.mag) # Extract points at edges edges.px <- which(grad.mag > max(grad.mag[, , 1, 1])/2, arr.ind = TRUE) points(edges.px, col = "green", cex = 0.1) # Apply transformations to point set tr1 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), center.new = c(1200, 1200), alpha = 90) tr2 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), center.new = c(500, 1200), mirror.x = T, alpha = 30) tr3 <- combine.tr(center.cur = apply(edges.px[, 1:2], 2, mean), center.new = c(1200, 500), mirror.y = T, alpha = 270) plot(edges.px, xlim = c(0, 1700), ylim = c(0, 1700), cex = 0.1) points(t(tr1%*%t(edges.px[, 1:3])), cex = 0.1, col = "red") points(t(tr2%*%t(edges.px[, 1:3])), cex = 0.1, col = "yellow") points(t(tr3%*%t(edges.px[, 1:3])), cex = 0.1, col = "blue") ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.