R中有重叠的组合/组合图像

问题描述 投票:0回答:1

我在文件夹中有大量64x64像素的小图像。我将所有这些图像加载到列表中。

setwd("C:/Users/PC/Pictures/")
jpeg <- list.files(folder)

我想将所有这些图像合并/组装以创建一个大图像。我想将图像N + 1粘贴在从图像1到k的8个像素间距的前一个图像N上。因此,图像N + 1将部分覆盖先前的图像N。如何做? enter image description here

r image-processing overlap
1个回答
0
投票

首先,我展示了一般如何组合图像,然后我们处理重叠。

为此,我使用了生物导体包装EBImage。因此,您需要先安装BiocManager,然后安装EBImage的某些依赖项,然后再安装EBImage

if (!requireNamespace("BiocManager", quietly = TRUE))
  install.packages("BiocManager")
BiocManager::install(version = "3.10")

# On linux I first had to do:
#   sudo apt-get install libpng-dev libfftw3-dev

install.packages("fftwtools")
install.packages("tiff")

require(tiff)
require(fftwtools)

BiocManager::install("EBImage")
require(EBImage)

现在我们可以合并图像。本示例使用鹦鹉的内置照片,然后对其进行变换并将其与自身结合。来自documentation page

## combination of color images
img = readImage(system.file("images", "sample-color.png", package="EBImage"))[257:768,,]
x = combine(img, flip(img), flop(img))
display(x, all=TRUE)
display(img, all=TRUE)

## Blurred images
x = resize(img, 128, 128)
xt = list()
for (t in seq(0.1, 5, len=9)) xt=c(xt, list(gblur(x, s=t)))
xt = combine(xt)
display(xt, title='Blurred images', all=TRUE)

现在为重叠问题。为此,我认为我们有2个选择-使用稍微复杂一些的abind函数代替combine或除tile外使用combinetile似乎更直接,并且与您要执行的操作直接相关。

 ## make a set of blurred images
  img = readImage(system.file("images", "sample-color.png", package="EBImage"))[257:768,,]
  x = resize(img, 128, 128)
  xt = list()
  for (t in seq(0.1, 5, len=3)) xt=c(xt, list(gblur(x, s=t)))
  xt = combine(xt)
  display(xt, title='Blurred images')

  ## tile
  xt = tile(xt, 3)
  display(xt, title='Tiles')

example of 3 tiled images with overlap

您可以水平平铺(如您的示例),垂直平铺,或两者都平铺。

© www.soinside.com 2019 - 2024. All rights reserved.