【问题标题】:MATLAB: batch processing of images and, saves these images. How can I do?MATLAB:批量处理图像并保存这些图像。我能怎么做?
【发布时间】:2015-01-28 23:12:42
【问题描述】:

对不起,我是新手。我试图复制代码找到here 获得相同的结果,但它不起作用(我的错误)。我无法弄清楚saveas 如何理解必须保存的图像。我读到saveas 想要一个句柄和一个文件名作为输入,而在我在上面链接中资助的代码中,我没有看到这些论点:

saveas(sprintf('img%d.tif',num_picture))

这是我的代码的一小部分:

% Here a loop that transform aeach image inside the variable(cell array) 'immages'

for z = 1:length(immages) %images is a cell array contained the matrices of 100images
    temp = immages{z};  %temp means temporary, that is the image to process
    for i = 1:I       % begin of cycle that process each pixel of the image(tmp)
        for j = 1:J
            if temp(i,j) == 0
               temp(i,j) = 115;
            else
                temp(i,j) = 140;
            end
        end
    end
    cd(finalDest);  %move into the directory whre I want to save the new image
    figure;
    imshow(temp);
    saveas(sprintf('img%d.tif',z)); % HOW CAN I SAVE THE CURRENT IMAGE(TEMP) INSIDE 'FINALDEST'?
    cd(initialDest); %return to the folder where the original images are contained
end

我遇到这个错误ERROR USING SAVEAS, line55: Requires handle to Figure or block diagram and filename.

非常感谢。

【问题讨论】:

    标签: image matlab image-manipulation


    【解决方案1】:

    你是对的,saveas 需要一个图形句柄作为第一个参数,你可以改变一个:

    figure;
    

    与

    h = figure(z); //one figure per image
    

    和

    saveas(h, sprintf('img%d.tif',z));
    

    或使用gcf 获取当前图形的句柄:

    saveas(gcf, sprintf('img%d.tif',z));
    

    如果你只想保存temp矩阵上的信息(不是整个图)你应该使用IMWRITE:

    imwrite(temp,sprintf('img%d.tif',z));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多