Hi I am trying to convert multiple images to an array of block structures and then I want to find the average of each block. I came across a solution for a single image but I don't know how to implement it for multiple images. The solution mentioned can be seen [here] (Divide image to blocks)! I want to implement the same for multiple images. Is that possible?
import numpy as np
from PIL import Image
image = Image.open("your_file.jpg", "r")
arr = np.asarray(image)
arr = np.split(arr, 20)
arr = np.array([np.split(x, 20, 1) for x in arr])
mat = [arr[i][j].mean() for i in range(40) for j in range(40)]
This is not my code. I have referenced the original author @Daniel from where I got the idea. His code works for a single image. Is there a way to use it for multiple images all at once?
I have tried it but I am not sure if it right way to do it.
img = [cv2.imread(file,0) for file in glob.glob("resized/*.jpg")]
X=[]
for im in img:
arr = np.asarray(im)
arr = np.split(arr, 20)
arr = np.array([np.split(x, 20, 1) for x in arr])
mat = [arr[i][j].mean() for i in range(20) for j in range(20)]
X.append(mat)