将图像划分为块并比较每个对应的块 [英] Divide images into blocks and compare each corresponding block

查看:83
本文介绍了将图像划分为块并比较每个对应的块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组大小为200x200的图像,我想将这些图像分为10个大小为20x20的块(每个图像).在将图像划分为块之后,

Hi I have a set of images of size 200x200 and I want to divide these images into 10 blocks of size 20x20(each image). After the images are divided into blocks,

1)我想将图像1的第一块与图像2的第一块,图像3以及图像2的第二块与图像2的第三块进行比较,依此类推.

1) I want to compare 1st block of image 1 with 1st block of image2, image 3 and 2nd block with 2nd block of image2, image 3 and so on.

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

2)After comparing blocks the block with maximum value should be used and put in a final image such that the final image has blocks with maximum value from image1, image2 or image3.

是否可以进行这种比较并生成新图像.

Is it possible to do such comparison and produce a new image.

image = cv2.resize(im,(200,200))
image1 = cv2.resize(im1,(200,200))

hs = round(h/10)
ws = round(w/10)
hs1 = round(hs1/10)
ws1 = round(ws1/10)
resized = cv2.resize(image, (ws,hs), interpolation = cv2.INTER_AREA)
resized1 = cv2.resize(image1, (ws1,hs1), interpolation = cv2.INTER_AREA)

结果类似于图片此处

可以在此处访问图像.

推荐答案

入门的提示...您无需平铺图像并创建调整大小/裁剪后的子图像即可.您可以完全方便地原位访问您的块.这是一个示例,使用较小的块(以便您可以看到它们)来入门.

A hint to get you started... you don't need to tile your image up and create resized/cropped sub-images to do this. You can perfectly easily access your blocks in situ. Here is an example, with smaller blocks (so you can see them) to get you started.

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列:

Now let's look at the top-left 2 rows and 3 columns:

print(ramp[:2, :3]) 

看起来像这样:

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

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

And let's get their average:

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

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

Now let's look at the bottom-right 2 rows and 3 columns:

print(ramp[-2:, -3:])

array([[54, 64, 74],
       [55, 65, 75]])

得到他们的意思:

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


第二个提示...您的答案将如下所示:


A second hint... your answer will look like this:

这篇关于将图像划分为块并比较每个对应的块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆