Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to concatenate 1000 images vertically using for loop in python?

I want to concatenate vertically a lot of images. I used skimage to read images then in each iteration io read image and vconcat concatenate the new image on the old image vertically. The result of my code didn't concatenate the images, just combine the images. Any ideas how to make each image in each iteration concatenate vertically on each other?

I want to concatenate the first image and the second image vertically:

fist image

second image

but I got this result:

result

enter image description here

data = []
if nSpectogram < 3765:
    for k in range(0, 21):
        path = io.imread('E:\\wavelet\\spectrograms\\paz05\\'+'spec_'+isPreictal+'_'+str(nSpectogram+1)+'_'+str(k+1)+'.png')
        im_v_array = np.array(im_v)
        data.append(path)
    res = np.concatenate(data)
    plt.imshow(res, cmap='inferno', aspect='auto', interpolation='nearest')
like image 429
Edayildiz Avatar asked Sep 11 '20 13:09

Edayildiz


People also ask

How do you combine images vertically in Python?

Combine Images Vertically in Python If we want to combine the images vertically, we have to create a blank image with a height equal to the combined height of the two images and a width equal to the maximum width of the two images. After that, we also have to change the location of the second image on the blank image.

How do I put 2 photos on cv2?

You can add two images with the OpenCV function, cv. add(), or simply by the numpy operation res = img1 + img2. Both images should be of same depth and type, or the second image can just be a scalar value.

How to concatenate images with Python pillow?

Concatenate images with Python, Pillow. Pillow (PIL) can be used to concatenate (combine) multiple images vertically and horizontally. Create a background with Image.new () and paste the images with Image.paste (). There are several conceivable ways to concatenate images of different sizes. Here, three will be described.

How to combine two images vertically in Python?

Following is the complete Python code to combine two images vertically: Following is the visual image combining 2 images vertically: To combine two images horizontally, the height of both images should be same. If the height is different, then one of the images must be resized to make the height same.

How to concatenate images using OpenCV in Python?

Concatenate images using OpenCV in Python Last Updated : 28 Jul, 2020 To concatenate images vertically and horizontally with Python, cv2 library comes with two functions as: hconcat (): It is used as cv2.hconcat () to concatenate images horizontally.

How do I concatenate (combine) images?

Pillow (PIL) can be used to concatenate (combine) multiple images vertically and horizontally. Create a background with Image.new () and paste the images with Image.paste (). There are several ways to concatenate images of different sizes. This article describes the following cases. Concatenate images with the same height or width


1 Answers

Use -

merged_img = []
for i in range(3):
    img = io.imread('https://machinelearningblogs.com/wp-content/uploads/2018/03/849825_XL-830x400.jpg')
    merged_img.append(img)

merge = np.concatenate(merged_img)

plt.imshow(merge)

enter image description here

Just add all the images to a list in the for loop after reading them and pass the list to np.concatenate

like image 143
Vivek Kalyanarangan Avatar answered Oct 22 '22 08:10

Vivek Kalyanarangan