MATLAB:批处理图像并保存这些图像。我能怎么做?

MATLAB: batch processing of images and, saves these images. How can I do?

对不起,我是新手。我试着复制代码 find here 获得相同的结果,但它不起作用(我的故障)。我不明白 saveas 如何理解必须保存的图像。我读到 saveas 需要一个句柄和一个文件名作为输入,而在我在上面的 link 中提供的代码中我没有看到这些参数:

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.

非常感谢。

你是对的,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));