将下面代码写成matlab形式 float cal_psnr(const Mat x, const Mat y) { float RMS = 0; for (int i = 0; i < x.rows; i++) { const float* Mx = x.ptr<float>(i); const float* My = y.ptr<float>(i); for (int j = 0; j < x.cols; j++) { RMS += (My[j] - Mx[j]) * (My[j] - Mx[j]); } } RMS = sqrtf(RMS / (x.rows * x.cols)); return 20 * log10f(255.0 / RMS); }
时间: 2023-12-06 10:43:44 浏览: 75
PSNR.rar_ color PSNR_PSNR_code for psnr_psnr code in matlab_psnr
function psnr = cal_psnr(x, y)
RMS = 0;
for i = 1:x.rows
Mx = x(i,:);
My = y(i,:);
for j = 1:x.cols
RMS = RMS + (My(j) - Mx(j)) * (My(j) - Mx(j));
end
end
RMS = sqrt(RMS / (x.rows * x.cols));
psnr = 20 * log10(255.0 / RMS);
end
阅读全文