背景差分法和帧间差分法的c++程序

背景差分法和帧间差分法的c++程序,第1张

背景差分法和帧间差分法的程衡樱慧序,其实很简单,就是二值化后,两幅像咐答素相减。这些程序你在任何一本关颂茄于图像处理的有光盘书中都可以找到。我记得我以前用的是张宏林《精通VisualC++数字图像处理典型算法及实现》不知道是不是,记不太清了,你看看吧

mov=aviread('xxxxxxxx.AVI')

temp=size(mov)

fnum=temp(2)

for i=1:fnum,

strtemp=strcat(int2str(i),'.','JPG')

imwrite(mov(i).cdata(:,:,:),strtemp)

end%% 从视频中提出每一帧图像

o=1

e='.jpg'

for i=1:15

u=o-1v=o-2

m=int2str(o)

n=int2str(u)h=int2str(v)

s=strcat(m,e)%%把字符串b与m连接后在连接e得到图像文件存储的位置

m=imread(s)%%从S处把图像读取出来

m=rgb2gray(m)%%将图像M灰度化

m=medfilt2(m,[3,3])

if(o>=3)

s=strcat(n,e)

n=imread(s)

n=rgb2gray(n)

s=strcat(h,e)

h=imread(s)

h=rgb2gray(h)

n=medfilt2(n,[3,3])

h=medfilt2(h,[3,3])

q=im2double(m)%%将图像数组转换为double型

w=im2double(n)g=im2double(h)

c=q-wj=w-g

th=10/255

k=find(abs(c)>=th)

c(k)=1

k=find(abs(c)<th)

c(k)=0

c=bwareaopen(c,15)

se90=strel ('line',3,90)se0=strel ('line',3,0)

c=bwmorph(c,'close')%对上述图像进行形态学闭运算

c=imdilate(c,[se90,se0])c=bwmorph(c,'close')

c=bwareaopen(c,50)

k=find(abs(j)>=th)

j(k)=1

k=find(abs(j)<th)

j(k)=0

j=bwareaopen(j,15)

j=bwmorph(j,'close')%对上述图像进行形态学闭运算

j=imdilate(j,[se90,se0])j=bwmorph(j,'close')

c=bwareaopen(c,50)

c=c&jc=imerode(c,[se90,se0])

figure,imshow(c)

a=cb=cd=cf=c

[m,n]=size(c)

%%行扫描填充

for i=1:m

for j=1:n-1

if a(i,j)>0

a(i,j+1)=1

end

end

end

for i=1:m

for j=n:-1:2

if b(i,j)>0

b(i,j-1)=1

end

end

end

th=a&b

%%列扫描填充

for i=1:n

for j=1:m-1

if d(j,i)>0

d(j+1,i)=1

end

end

end

for i=1:n

for j=m:-1:2

if f(j,i)>0

f(j-1,i)=1

end

end

end

td=d&f

c=th&td

end

o=o+1

end

照片的尺寸一样的么 如果一样的话 要这个程序吧 是背景差分法

close all

a = imread('照片上面是A.jpg')

b = imread('照片上面是A和B.jpg')

% 作差

c = a-b

% 二值咐激化

c = im2bw(c)

% 求出目标区域坐标

[row,col] = find(c==1)

x = min(col)

y = min(row)

w = max(col)-x

h = max(row)-y

% 显示结果

figure,imshow(b)

hold on

% 框残缺区域

rectangle('衡做袜Position',[x,y,w,h],'胡凯LineWidth',1,'EdgeColor','g')


欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/yw/12544972.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存