从多个图像创建背景模型

时间:2014-02-12 20:31:39

标签: matlab image-processing background

我正在尝试从相同大小的多个图像创建背景模型。我想用这个模型来分割滚轮带上的移动物体(背景模型),但我不知道如何实现这一点。

我关心的是如何使用代表滚轮皮带的4幅图像来计算背景模型?

我正在考虑计算每个腰带图像的平均值,将它们加在一起,然后除以图像的数量,但在这种情况下,我将得到整个背景的一个值。如何通过查看提供的4个图像来计算每个像素的平均值?

2 个答案:

答案 0 :(得分:2)

%some example data
A{1}=imread('http://dummyimage.com/600x400/00a/fff.jpg&text=a');
A{2}=imread('http://dummyimage.com/600x400/00a/fff.jpg&text=b');
A{3}=imread('http://dummyimage.com/600x400/00a/fff.jpg&text=c');
A{4}=imread('http://dummyimage.com/600x400/00a/fff.jpg&text=d');

%make sure every image is of type double. Every uint type is possible as well, but requires casting at the end.
for ix=1:numel(A),A{ix}=im2double(A{ix});end


%concatinate on ndims+1, which means 4th dimension for color images and third dimension for grey scale images.    
I=mean(cat(ndims(A{1})+1,A{:}),ndims(A{1})+1);
imshow(I);

答案 1 :(得分:0)

如果图像是im1,im2,im3,im4计算沿第三维的平均值。

% concatenate the images to a single 3-D stack.
im = cat(3,im1,im2,im3,im4);

% find the mean of each pixel.
meanIm = mean(im,3);