I have a problem concerning dividing matrices element wise, whereby I mean that I want element [i,j] of the first matrix(foto_dcp, see code) to get divided by element[i,j] of the second matrix(Q) .
Some background information : I loaded in an image from my storage. I stored the monochrome values of each pixel in a matrix called "pixelMatrix" This command turns the big matrix (of 128x128) into smaller ones (of 8x8)
foto_dct = skimage.util.view_as_blocks(pixelMatrix, block_shape=(8, 8))
Now, after doing this, I need to divide each matrix in foto_dct by a different matrix (called 'Q' in this code) elementwise.
for x in foto_dct:
for i in range(8):
for j in range(8):
x[i,j] = x[i,j] / Q[i,j]
problem is that I get incorrect results. This is the matrix 'Q':
[[ 16 11 10 16 24 40 51 61]
[ 12 12 14 19 26 58 60 55]
[ 14 13 16 24 40 57 69 56]
[ 14 17 22 29 51 87 80 62]
[ 18 22 37 56 68 109 103 77]
[ 24 35 55 64 81 104 113 92]
[ 49 64 78 87 103 121 120 101]
[ 72 92 95 98 112 100 103 99]]
This is an example matrix ( foto_dct[3,3], though I have done some operations on it, the 3rd column of matrices, the 3rd row of matrices, if you remember from step 1.)
[[613 250 -86 64 -63 59 -44 24]
[ 38 -84 50 -57 54 -47 35 -19]
[-16 4 -4 7 -5 4 -3 1]
[ 10 -18 19 -20 21 -20 16 -9]
[-17 19 -18 16 -14 11 -7 4]
[ -7 9 -10 12 -13 11 -9 5]
[-11 15 -14 15 -14 11 -9 5]
[ -1 2 -4 5 -5 4 -3 2]]
And this is what I get after division:
[[43 17 -6 4 -4 4 -3 1]
[ 2 -4 2 -3 3 -2 2 -1]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]
[ 0 0 0 0 0 0 0 0]]
As you can see, for instance take element [0,0] = 613, so after division we should get [0,0] = 613/16 = 38.3125 (As you can see it also automaticaly rounds up?) By the way, I tried changing
x[i,j] = x[i,j] / Q[i,j]
by
x[i,j] = x[i,j] / 2
and got correct (though rounded) results. So it's something with Q[i,j]
I've also tried to do it this way:
for x in foto_dct:
x = np.divide(x,Q)
But this returns me the original matrix,without doing anything, not even returning an error code, eventhough it should divide elementwise. Can anyone help me out?