Calculate covariance of two images in matlab - image

I am doing a project on image quality assessment. I converted the image to grayscale & divided the entire image into 8x8 matrices using mat2cell function. I did this for two images, and now I want to calculate covariance between these two images (i.e the covariance between the matrix of image 1 and covariance between the same matrix of image 2). Note that both are the same images: one a pure image without distortions and one with distortions.

First convert your image to matrix:
I = double(imread('photo.jpg'));
then calculate covariance:
x=cov(I);

For single matrix input, C has size [size(A,2) size(A,2)] based on the number of random variables (columns) represented by A. The variances of the columns are along the diagonal. If A is a row or column vector, C is the scalar-valued variance.
For two-vector or two-matrix input, C is the 2-by-2 covariance matrix between the two random variables. The variances are along the diagonal of C.

Related

How can I subset a matrix from a larger one in matlab?

how to subset a matrix of different dimension from another one in matlab?Thanks for any help.

How to get thin QR decomposition in Julia?

When I perform QR decomposition on a 3x2 matrix A in Julia, it gives a 3x3 matrix Q. Is there any way I can get a "thin" version of this QR, where it returns a Q that is 3x2 (same dimensions as matrix A)? My goal is just to get an orthonormal basis for the column space of A, so I don't need a 3x3 matrix Q.
This can be achieved with Matrix(qr(A)). qr doesn't return matrices, but rather returns an object that can multiply by other matrices or easily extract the thin or full Q matrix.

Keras - Mean Squared Error (MSE) calculation definition for images?

I am using
loss = 'mse'
in Keras for an autoencoder model that reconstructs greyscale images. My batch size is 1. A single loss value is being produced during training.
I can't seem to find anywhere an answer to this question. How does Keras calculate this MSE loss value for these 2 images? They're represented as 2d NumPy arrays. Does it compute the squared difference between each pixel and then divide by the number of pixels (considering the batch size is 1)?
Is this process the same if the input is more than 1 greyscale image into the model; computing the squared pixel difference across all the images, then dividing by the total number of pixels in all the images?
Many thanks
def mse(y_true, y_pred):
return K.mean(K.square(y_pred - y_true), axis=-1)
This is the code for the mse, the operations (difference and square) are bitwise (pixel by pixel), then it computes the mean, so it divides for the number of values (pixel).

How can I find the partial transpose for three qubit density matrix usign mathematica?

I know that the density matrix of a three-qubit is an 8x8 matrix. How can I use Mathematica to find the partial transpose of this 8x8 matrix with respect to the first, second, or the third qubit?

Matlab - Image Formation - Matrix

I am doing a very interesting Computer Vision project which talks about how to "create manually" images with Matlab.
The teacher gave me three matrices: the illuminant matrix (called E), the camera sensitivity matrix (called R) and finally, the surface reflectance matrix (called S).
The matrix dimensions are as follows:
S: 31x512x512 (reflectance samples x x-dimension x y-dimension)
R: 31x3
E: 31x1
The teacher gave me also the following relationship:
P=transpose(C)*R=transpose(S)*diagonal(E)*R
Where C is the color matrix.
Where P is the sensor response matrix.
The goal is to display the image formed by all the previous matrices. Therefore, we have to compute the P matrix.
The class of all the matrices is double.
This is what I have done:
Diag_D=diag(D);% Diagonal matrix of D
S_reshaped= reshape(S,31,[512*512]);% Reshape the surface reflectance matrix
S_permute=permute(S_reshaped,[2 1]);% The output matrix is a 262144x31 matrix
Color_Signal_D65_buffer=S_permute*Diag_DD;
Color_Signal_D65=reshape(Color_Signal_D65_buffer,[512 512 31]);% This is the final color matrix
Image_D65_buffer= (reshape(Color_Signal_D65,[512*512],31))*R;% Apply the given formula
Image_D65= reshape(Image_D65_buffer,[512 512 3]);% image formation
Image_D65_norm=sqrt(sum(Image_D65.^2,3));% Compute the Image_D65 norm
Image_D65_Normalized=bsxfun(#rdivide, Image_D65, Image_D65_norm);% Divide each element of the matrix by the norm in order to normalize the matrix
figure
imshow(Image_D65_Normalized)% Display the image
However,it did not work at all. The output is an image but the colors are completely wrong (there is too much blue on the image).
I think it could be a matrix reshaping problem but I have tried all the possible combinations but nothing to do.
Thank you so much for your help
I've finaly found the error. It was a problem in the normalization process. I was using the wrong formula.

Resources