Merge blocks of images to produce new image

2024/11/16 19:44:42

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.

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.

https://en.xdnf.cn/q/120294.html

Related Q&A

Removing Characters from python Output

I did alot of work to remove the characters from the spark python output like u u u" [()/" which are creating problem for me to do the further work. So please put a focus on the same .I have …

How to make a tkinter entry default value permanent

I am writing a program in python that will take in specific formats, a Phone number and dollar/cent values. How can I make tkinter have default value which is permanent, not deletable. For example (XXX…

distribute value in buckets

Consider below DF, I have an input number=4 to be inserted evenly in different hour buckets.p_hourly mins 0 2020-09-10 07:00:00 60.0 1 2020-09-10 08:00:00 60.0 2 2020-09-10 09:00:00 60…

for loop over list break and continue

To specify the problem correctly :i apologize for the confusion Having doubts with breaking early from loop . I have folders - 1995,1996 to 2014 . Each folder has xml files. In some xml files the entr…

ImportError: cannot import name loads from json (unknown location)

Previos title was: AttributeError: module json has no attribute loads I changed it because it looks similar to this but at the link that i provided, the problem seems that the person was having a file…

How can I filter the domains served by a CDN from a list of domain names?

I have a list of domains and I need to filter the domains served by a CDN(Content Delivery Network). I am going to use python script to do that. At the first I was thinking I can identify them from the…

Convert int(round(time.time())) to C# [closed]

Its difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying thi…

How to iterate over all elements of a 2D matrix using only one loop using python

I know you can iterate over a 2d matrix using two indexes like this: import numpy as npA = np.zeros((10,10))for i in range(0,10):for j in range(0,10):if (i==j):A[i,j] = 4Is there a way of doing this us…

Parse table names from a bunch SQL statements

I have an table with thousands of SQL statements in a column called Queries. Any ideas on how to get just the table names from the statements by using a regular expression?

click multiple buttons with same class names in Python

This a column in a table this column contains buttons, on pressing each buttons a pdf is downloadedThe buttons have the same class names and I want to click on all the buttons.This is what I did, but i…