我跟随this guide from pyimagesearch制作了一个CNN,它可以拍摄图像和数字数据并进行单一输出。在图像方面,本指南为每个示例提供四个彩色图像,然后加载、调整大小并将其堆叠在蒙太奇中,如下所示:
import cv2
inputImages = []
outputImage = np.zeros((64, 64, 3), dtype="uint8")
# loop over the input image paths
for inputImage in imagePaths:
# load the input image, resize it to be 32 32, and then
# update the list of input images
image = cv2.imread(inputImage)
image = cv2.resize(image, (32, 32))
inputImages.append(image)
# tile the four input images in the output image such the first
# image goes in the top-right corner, the second image in the
# top-left corner, the third image in the bottom-right corner,
# and the final image in the bottom-left corner
outputImage[0:32, 0:32] = inputImages[0]
outputImage[0:32, 32:64] = inputImages[1]
outputImage[32:64, 32:64] = inputImages[2]
outputImage[32:64, 0:32] = inputImages[3]
结果是一个蒙太奇是4个彩色图像并排像这样:
我的图像是光栅,因此每个只有一个层。我的四张图片代表了空中拍摄中同一地点的不同索引,所以我会让它们叠在一起,而不是并排。 在队列中:
outputImage = np.zeros((64, 64, 3), dtype="uint8")
我假设维度3
是指原始图像的RGB元素。
为了制作我自己的蒙太奇,我把它简化为np.zeros((64, 64), dtype="uint8)
,但是我得到的outputImage
并不像建议的那样是一个图像蒙太奇,而是一个64X64的数字数组
要加载光栅,我使用的是枕头,目前我的代码如下所示:
from PIL import Image
inputImages = []
outputImage = np.zeros((64, 64), dtype = 'uint8')
# relevant images
for inputMap in relevantMaps:
mapPath = os.path.sep.join([zonePath, inputMap])
# load input image, resize it to be 32 32, the update the input image list
image = Image.open(mapPath)
image = image.resize((32, 32))
inputImages.append(image)
# tile the four input images in the output image such that:
# first image -> top left, second image -> top right
# third image -> bottom left, fourth image -> bottom right
outputImage[0:32, 0:32] = inputImages[0]
outputImage[32:64, 0:32] = inputImages[1]
outputImage[0:32, 32:64] = inputImages[2]
outputImage[32:64, 32:64] = inputImages[3]
我的outputImage
看起来像这样:
array([[123, 125, 131, ..., 0, 0, 0],
[120, 125, 127, ..., 0, 0, 0],
[123, 127, 126, ..., 0, 0, 0],
...,
[205, 153, 55, ..., 242, 242, 242],
[ 4, 241, 28, ..., 242, 242, 242],
[243, 90, 211, ..., 242, 242, 242]], dtype=uint8)
而不是图像蒙太奇
我面临两个问题:
我不确定是否应该像示例中那样将图像堆叠在一起,或者堆叠在一起,因为它们是相同区域的不同层
我不知道如何堆叠图像,并让他们作为图像保留,我的方法将他们变成矩阵
我希望得到一个可用的图像蒙太奇,然后我可以扑通一声进入CNN作为输入
目前没有回答
相关问题 更多 >
编程相关推荐