【问题标题】:Average image (Type error)平均图像(类型错误)
【发布时间】: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

【问题讨论】:

    标签: matlab image-processing


    【解决方案1】:

    可能会改变:

    container = imread([resizeFolder fname]);
    

    container = im2double(imread([resizeFolder fname]));
    

    【讨论】:

    • 好的,现在函数运行没有错误。但结果是纯白色 png(带有黑色条,alpha 值为 0)。有什么想法吗?
    • 啊,是的,非常好!有没有办法保留png的alpha通道?因为最终图像中丢失了透明度信息。
    • 我这台电脑上没有 matlab,所以我不能帮你查。但无论如何,您的centroidImage 只有尺寸x, y, 3,所以至少您需要为其添加一个 alpha 通道...
    • 好的,我看看能不能通过添加一个额外的维度来解决这个问题。感谢 E 先生的帮助!
    猜你喜欢
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 1970-01-01
    • 2018-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多