Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...