How to create image matrix from array consisting matrix blocks

268 Views Asked by At

I would like to perform DCT on blocks of one of image's channel (red in this case) and then merge these blocks into image that can be displayed. I am stuck on an array that consist blocks and I do not know how to create matrix from it, that can be transformed into image later on. Moreover, I believe that there is solution that creates matrix as the blocks are looping through image, but I am also not certain how to do it. My current code looks like this:

from operator import mod
import cv2
import numpy as np
from scipy.fftpack import fft, dct

img = cv2.imread("simple.bmp")
b = img[:,:,0]
g = img[:,:,1]
r = img[:,:,2]
blocksize = 8
dctimg = []

if len(r)%8 == 0:
    for row in range(0,r.shape[0] - blocksize, blocksize):
        for col in range(0,r.shape[1] - blocksize, blocksize):
            block = r[row:row+blocksize,col:col+blocksize]
            #print(block)
            dct_block = dct(block)
            #print(dct_block)
            dctimg.append(dct_block)

print(dctimg)

image source: https://people.math.sc.edu/Burkardt/data/bmp/bmp_24.bmp

I would be really thankful for any hint bringing me closer to the solution.

0

There are 0 best solutions below