Matlab 积分图的快速计算

Matlab积分图的计算:

方法一:

clc;
clear;
tic
img=imread('a.jpg');
imshow(img);
img=double(img);
[row col]=size(img);
s=zeros(row+1,col+1);
ii=zeros(row+1,col+1);
for x=2:row+1
    for y=2:col+1
        s(x,y)=s(x-1,y)+img(x-1,y-1);
        ii(x,y)=ii(x,y-1)+s(x,y);
    end
end
ii=im2uint8(mat2gray(ii(2:end,2:end)));
imshow(ii);
toc

方法二:(太强大了)

function [A] = IntImg(img)
% calculate the integral image of a window
A = cumsum(cumsum(double(img)),2);  

经测试,计算一个大小为20*20的图像的积分图;方法一:Elapsed time is 0.000013 seconds      方法二:Elapsed time is 0.003777 seconds    相差大约300倍,果断秒杀。所以在matlab编程时,尽量使用矩阵运算,可大幅度降低运算时间。

               

原文地址:https://www.cnblogs.com/zxwAAA/p/3014063.html