我正在嘗試可視化 3D 陣列切片(即影像堆疊)。令人驚訝的是,我找不到任何具有內置功能的軟體包可以輕松完成這項作業。
我為一些虛擬資料提供了一個帶有我自己的解決方案的示例代碼,但我想知道是否有更簡單且計算成本更低的解決方法?一些大型計算機斷層掃描 (CT) 掃描資料對我的機器造成了相當大的影響。
示例代碼:
library(leaflet) #color palette
library(rgl) #3d visualisation
#example data
slides = array(data = 0,
dim = c(200,200,15))
#add some intensity values
for(i in 1:dim(slides)[3]) slides[20:180,20:180,i] = i*10
#voxel dimensions for x/y/z
dims = c(1,1,20) #adjust z dimension for visualisation
#all possible x/y/z combinations
xyz = expand.grid(1:dim(slides)[1],1:dim(slides)[2],1:dim(slides)[3])
#find the intensity value for each data point
value = apply(xyz, 1, function(x) slides[x[1],x[2],x[3]])
#invert values
value = max(value) - value
#apply the voxel dimensions to x/y/z
xyz = t(t(xyz) * dims)
#convert intensity values to colors
colb = colorNumeric(palette = "Greys",
domain = c(0,max(value)))
col = colb(value)
#plot image stack
plot3d(xyz, col = col, aspect = FALSE, axes = FALSE, xlab = "", ylab = "", zlab = "")
結果:

uj5u.com熱心網友回復:
rgl使用紋理而不是繪圖點會快得多。例如:
library(rgl) #3d visualisation
#example data
slides = array(data = 0,
dim = c(200,200,15))
#add some intensity values
n <- dim(slides)[3]
for (i in 1:n) slides[20:180,20:180,i] = i*10
# Now plot each slide to a separate file to use as a texture
filenames <- character(n)
for (i in 1:n) {
filenames[i] <- tempfile(fileext = ".png")
png(filenames[i], width=200, height=200)
raster <- as.raster(slides[,,i], max = max(slides))
par(mar = c(0,0,0,0))
plot(raster)
dev.off()
}
# Now plot one 3D quad per slide
open3d()
#> glX
#> 1
texturequad <- cbind(c(0, 1, 1, 0), c(0, 0, 1, 1))
quad <- cbind(texturequad*200, 0)
for (i in 1:n) {
quad[,3] <- i
quads3d(quad, texcoords = texturequad, texture = filenames[i],
col = "white", lit = FALSE)
}
# Set the shape of the display as desired
aspect3d(1,1,2)
lowlevel() # Just to get reprex to show it

使用reprex v2.0.2創建于 2022-09-27
我沒有用你的調色板;如果需要,您應該將 的條目設定slides為顏色值而不是數值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/511629.html
標籤:r表现图像处理rgl
