【发布时间】:2012-02-27 15:57:20
【问题描述】:
我正在尝试在 matlab 中为 averaging images 编写一个函数(所有的大小和格式都相同 (.png))。但目前它并没有真正起作用。我得到的错误是:“Error using +, Integers can only be combination with integers of the same class, or scalar doubles.”
代码如下。图像全部调整为相同大小,如果比例不相等,则应用填充(填充是使用 Alpha 通道完成的,以使填充透明)。图片都是正确的png,可以在photoshop等中打开,没有错误。
如果我理解正确,您不必在 matlab 中初始化或声明变量。这可能是我的问题的一部分。我的正常(处理/java)方法是将containerAv初始化为大小(x,y,3),将所有图像的所有颜色值添加到其中,然后将所有值除以图像数量。为您提供平均图像。
我真的不知道如何在 matlab 中做到这一点。我究竟做错了什么?我如何重写这段代码,以便获得 rgb 平均图像?
function imageCentroid(imageList, resizeFolder, outputFolder, x, y)
% local variable
centroidImage = zeros([x y 3]);
% loop through all images in the resizeFolder
for i=1:length(imageList)
% get filename and load image
fname = imageList(i).name;
container = imread([resizeFolder fname]);
% add container values to centroidImage
centroidImage = centroidImage + container;
end
% calculate mean image (divide by number of images)
centroidImage = centroidImage / length(imageList);
% save mean image
imwrite(centroidImage, [outputFolder 'centroid.png']);
end
【问题讨论】: