zxwAAA

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编程时,尽量使用矩阵运算,可大幅度降低运算时间。

               

分类:

技术点:

相关文章:

  • 2021-11-30
  • 2021-05-07
  • 2021-06-28
  • 2021-08-10
  • 2021-06-18
  • 2021-09-14
  • 2021-11-18
猜你喜欢
  • 2021-11-17
  • 2021-06-17
  • 2021-04-28
  • 2021-11-16
  • 2021-06-10
  • 2021-11-24
  • 2021-08-12
相关资源
相似解决方案