Kirsh MATLAB 快速算法

Kirsh MATLAB 快速算法clcclear%I=double(imread(‘eight.tif’));I=double(imread(‘cameraman.tif’));[m,n]=size(I);imshow(I,[])%原有算法B=on

clc
clear
% I = double(imread('eight.tif'));
I = double(imread('cameraman.tif'));
[m,n] = size(I);
imshow(I,[])

% 原有算法
B = ones(m,n);
s = zeros(7,1);
t = zeros(7,1);
A = I;
tic
for i = 2:m-1
    for j = 2:n-1
        temp = sum(sum(A([i-1:i+1],[j-1:j+1])))-A(i,j);
        s(1) = A(i-1,j-1)+A(i-1,j)+A(i-1,j+1);
        s(2) = A(i-1,j)+A(i-1,j+1)+A(i,j+1);
        s(3) = A(i-1,j+1)+A(i,j+1)+A(i+1,j+1);
        s(4) = A(i,j+1)+A(i+1,j+1)+A(i+1,j);
        s(5) = A(i+1,j+1)+A(i+1,j)+A(i+1,j-1);
        s(6) = A(i+1,j)+A(i+1,j-1)+A(i,j-1);
        s(7) = A(i+1,j-1)+A(i,j-1)+A(i-1,j-1);
        for k = 1:7
            t(k) = temp-s(k);
        end
        B(i,j) = max(abs(5*s-3*t));
    end
end
toc
figure
imshow(B,[])

% 快速算法

r = zeros(8,1);
out = zeros(8,8);


tic
for i=2:m-1
    for j=2:n-1
        r(1) = 0.625*(I(i-1,j-1)+I(i-1,j)+I(i-1,j+1))-0.375*(I(i,j+1)+I(i+1,j+1)+I(i+1,j)+I(i+1,j-1)+I(i,j-1));
        r(2) = r(1)+I(i,j-1)-I(i-1,j+1);
        r(3) = r(2)+I(i+1,j-1)-I(i-1,j);
        r(4) = r(3)+I(i+1,j)-I(i-1,j-1);
        r(5) = r(4)+I(i+1,j+1)-I(i,j-1);
        r(6) = r(5)+I(i,j+1)-I(i+1,j-1);
        r(7) = r(6)+I(i-1,j+1)-I(i+1,j);
        r(8) = r(7)+I(i-1,j)-I(i+1,j+1);
        out(i,j) = max(r);
    end
end
toc
figure
imshow(out,[]);
资源原网址:点击打开链接

今天的文章Kirsh MATLAB 快速算法分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/59815.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注