Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
274 views
in Technique[技术] by (71.8m points)

python - Merge blocks of images to produce new image

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...