将图像划分为块并比较每个对应的块

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

嗨,我有一组大小为200x200的图像,我想将这些图像分为10个大小为20x20的块(每个图像)。将图像分成块后,

[1)我想比较图像1的第一块与图像2的第一块,图像3以及图像2的第二块与图像2的第二块,图像3等等。

2)在比较块之后,应使用具有最大值的块并将其放入最终图像中,以使最终图像具有来自image1,image2或image3的最大值的块。

是否可以进行这种比较并产生新图像。

image = cv2.resize(im,(200,200))
hs = round(h/10)
ws = round(w/10)
resized = cv2.resize(image, (ws,hs), interpolation = cv2.INTER_AREA)
python image opencv image-processing
1个回答
0
投票

有关入门的提示...您无需平铺图像并创建调整大小/裁剪后的子图像即可。您可以轻松地<访问您的块。这是一个示例,使用较小的块(以便您可以看到它们)来入门。import numpy as np # Make synthetic ramp image ramp = np.arange(6,dtype=np.uint8).reshape(-1,1) + (np.arange(8)*10).reshape(1,-1)

看起来像这样:

array([[ 0, 10, 20, 30, 40, 50, 60, 70], [ 1, 11, 21, 31, 41, 51, 61, 71], [ 2, 12, 22, 32, 42, 52, 62, 72], [ 3, 13, 23, 33, 43, 53, 63, 73], [ 4, 14, 24, 34, 44, 54, 64, 74], [ 5, 15, 25, 35, 45, 55, 65, 75]])

现在让我们看一下左上方的2行和3列:

print(ramp[:2, :3])

看起来像这样:

array([[ 0, 10, 20], [ 1, 11, 21]])

让我们得到他们的平均值:

print(ramp[:2, :3].mean()) 10.5

现在让我们看一下右下角的2行和3列:

print(ramp[-2:, -3:]) array([[54, 64, 74], [55, 65, 75]])

并得到他们的意思:

print(ramp[-2:, -3:].mean()) 64.5

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