我一直在努力通過幾次迭代的解決方案,試圖獲得一張已轉換為極坐標的照片(最初是矩形半球形照片)以裁剪出圓外的區域。最初遵循此 [StackOverflow 帖子] 
這是我制作的功能:
hemi_rect_to_polar <- function(hemi_rect_image){
hemi_polar <- image_distort(hemi_rect_image,
"Polar",
c(0),
bestfit = TRUE)
min_dim <- min(image_info(hemi_rect_image)[2])
figure <- image_draw(image_blank(min_dim,min_dim))
symbols(min_dim/2,
min_dim/2,
circles = (min_dim/2),
fg = 'black',
add = TRUE)
dev.off()
return(hemi_polar)
}
以及我從該函式獲得的輸出,該函式的顏色超出了我需要擺脫的圓形邊界以供以后分析:

我不確定為什么它會不斷地將極坐標拉伸到邊界圓之外。
uj5u.com熱心網友回復:
我不確定這是否非常有效,但它確實有效。由于這使用縮放,因此您只需要制作一個蒙版,然后將其縮放到影像而不考慮影像大小。如果影像的大小都相同,那么您所要做的就是構圖。
library(magick)
path = "https://i.stack.imgur.com/XBDRI.jpg"
img <- image_read(path)
hemi_rect_to_polar <- function(hemi_rect_image){
hemi_polar <- image_distort(hemi_rect_image,
"Polar",
c(0),
bestfit = TRUE)
return(hemi_polar)
}
he = hemi_rect_to_polar(img)
# make the mask
png(tf <- tempfile(fileext = "png"), 736, 736)
par(mar = rep(0,4), yaxs="i", xaxs="i")
plot(0, type = "n", ylim = c(0,1), xlim=c(0,1), axes=F, xlab=NA, ylab=NA)
plotrix::draw.circle(.5,0.5,.5, col="black")
# dump the temp file
dev.off()
# read in the plot as an image to use as a mask
mask <- image_read(tf)
# scale the mask for the image size
mask <- image_scale(mask, as.character(image_info(he)$width))
# crop the image
image_composite(mask, he, "plus")

轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/462688.html
上一篇:當影像列為空時,SSRS顯示文本
