There are two formulae which I am finding it difficult to represent in MATLAB. Let there be two RGB images, A and B, of the same size with m,n representing rows and column and the third dimension d=3. Formula1 basically calculates the rate of change of pixels if A is the original image and B is the distorted version. Formula2 calculates the average rate of change of pixels.
1.
Formula1= { sum(C(m,n,d)) / (m * n)} * 100
where `C(m,n) = 0`, if `A(m,n) = B(m,n)`
`=1`, if `A(m,n) != B(m,n)`
Sum over all rows and column including the third dimension.
I have tried something like this:
Formula1 = sum(sum(abs(double(A)-double(B))./(m*n), 1), 2);
But this does not give any error. However, this is not the correct way to represent it, since the if conditions are not incorporated. The problem area is how to incorporate the condition by checking if A == B or not and if A != B.
2.
Formula2 ={ 1/ (m*n)} * sum { norm (A - B) / 255} * 100
Again, here also it will be summation over all the dimensions. I don’t know how to form the norm of a matrix.
-
Formula3 is ={ 1/ (m*n)} * sum {(A - B) / 255} * 100
I tried out like thisC = double(sum(A-B,3));
r = reshape(100*(C/255)/(m*n),[1 3])
But there is an error saying dimension should be same and reshape does not work.
For
Formula1:The
~=operator checks for inequality.(:)vectorizes the matrix, allowing us to calculate the sum over all dimensions.For
Formula2:Here,
sum(A-B, 3)sums over the color planes, leaving a 2D matrix with the dimensions of the original image. There are several matrix norms, your choices are available in the documentation for NORM.