How to calculate pixel rate in MATLAB

There are two formulas that are hard for me to imagine in MATLAB . Suppose there are two RGB image, Aand Bthe same size with m, nrepresenting rows and columns, and the third dimension d = 3. Formula1basically calculates the rate of change pixels, when Aa source image and Ba distorted version. Formula2calculates the average pixel rate.

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 all rows and columns, including the third dimension.

I tried something like this:

Formula1 = sum(sum(abs(double(A)-double(B))./(m*n), 1), 2);

But that makes no mistake. However, this is not the correct way to present it, since the conditions are ifnot included. The problem area is how to enable the condition by checking if A == Bor not and if A != B.

2.   Formula2 ={ 1/ (m*n)} * sum { norm (A - B) / 255} * 100 Again, there will also be a summation over all dimensions. I do not know how to form the matrix norm.

  • Formula3 is ={ 1/ (m*n)} * sum {(A - B) / 255} * 100 I tried like this

    C = double (sum (AB, 3)); r = reshape (100 * (C / 255) / (m * n), [1 3])

But there is a mistake saying that the measurement should be the same, and changing the form does not work.

+3
source share
2 answers

For Formula1:

function r = Formula1(A,B)
[m,n,d] = size(A); %# A and B must have the same dimension
C = A ~= B; %# C has a 1 in every pixel that different
r = double(sum(C(:)))/(m*n);
r = r/d; %# normalize by number of color planes

~= . (:) , .

Formula2:

function r = Formula2(A,B)
[m,n,d] = size(A);
C = double(sum(A-B, 3)); %# sum over the color planes
C = C/d; %# normalize by number of color planes
K = norm(C); %# or norm(C,1), norm(C,inf) etc.
r = 100*(K/255)/(m*n);

sum(A-B, 3) , 2D- . , NORM.

+5

(A ~= B) , true, . , . double, 1, .

0

Source: https://habr.com/ru/post/1766425/


All Articles