这篇文章将为大家详细讲解有关基于matlab图像中心差分处理的示例分析,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
在处理图像的时候,特别是处理视频流图像的时候,往往会用到图像差分的方法。顾名思义,图像差分,就是把两幅图像的对应像素值相减,以削弱图像的相似部分,突出显示图像的变化部分。例如,差分图像往往能够检测出运动目标的轮廓,能够提取出闪烁导管的轨迹等等。
中心差分源码:
I = imread('lena1.png');
figure; imshow(I);
forward_dx = mipforwarddiff(I,'dx'); figure, imshow(forward_dx);
forward_dy = mipforwarddiff(I,'dy'); figure, imshow(forward_dy);
central_dx = mipcentraldiff(I,'dx'); figure, imshow(central_dx);
central_dy = mipcentraldiff(I,'dy'); figure, imshow(central_dy);
function dimg = mipcentraldiff(img,direction)
% MIPCENTRALDIFF Finite difference calculations
%
% DIMG = MIPCENTRALDIFF(IMG,DIRECTION)
%
% Calculates the central-difference for a given direction
% IMG : input image
% DIRECTION : 'dx' or 'dy'
% DIMG : resultant image
%
img = padarray(img,[1 1],'symmetric','both');
[row,col] = size(img);
dimg = zeros(row,col);
switch (direction)
case 'dx',
dimg(:,2:col-1) = (img(:,3:col)-img(:,1:col-2))/2;
case 'dy',
dimg(2:row-1,:) = (img(3:row,:)-img(1:row-2,:))/2;
otherwise,
disp('Direction is unknown');
end
dimg = dimg(2:end-1,2:end-1);

原图

x方向

关于“基于matlab图像中心差分处理的示例分析”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。