合并图像块以生成新图像 [英] Merge blocks of images to produce new image

查看:107
本文介绍了合并图像块以生成新图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以合并来自相同大小(例如100x100)的多个图像的特定块,并将它们放在一起形成新图像.更具体地说,考虑一下我有一组图像,这些图像已被分成相同大小的块(例如10x10).现在,我要访问图像1的块1和图像2的块2,图像1的块3,图像5的块4,依此类推,直到完成所有100个块.有没有办法使用python.

Hi is there a way of merging specific blocks from multiple images of same size(say 100x100) and putting them together in a new image. To be more specific, consider I have a set of images which have been divided into blocks of same size(say 10x10). Now I want to access block 1 from image 1 and block 2 from image 2, block 3 from image 1, block 4 from image 5 and so on till I finish all 100 blocks. Is there a way to do so using python.

img_1 = [cv2.imread(file,0) for file in glob.glob("trial_images/*.jpg")]
Y=[]
for img in img_1:
    arr_new = np.asarray(img)
    arr_new = np.split(arr_new, 10)
    arr_new = np.array([np.split(x, 10, 1) for x in arr_new])
    matrix1= [arr_new[i][j] for i in range(10) for j in range(10)]
    Y.append(matrix1)

到目前为止,我已经设法将图像划分为块,并且每个块都有其值.现在,我停留在如何从原始图像中获取块并将其绘制到新图像文件上的问题.

Till now I have managed to divide the images into blocks and I have the values of each block. Now I am stuck on how to get block from original images and draw them onto a new image file.

推荐答案

使用cv2 addWeighted函数(

Use the cv2 addWeighted function (link) to merge the images. Basically you are running a weighted sum over the matrics such that AxImage1 + BxImage2 = NewImage. Where A and B are constants and ImageN is your image.

这篇关于合并图像块以生成新图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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