使用matlab保存文件夹中的图像序列

时间:2015-07-10 16:42:14

标签: matlab

我想将图像保存到文件夹中。我尝试了下面给出的代码

      [Ilabel num] = bwlabel(If);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 83]);
 figure,imshow(Ibox);

 for n=1:num
        [r,c] = find(Ilabel==n);
        % Extract letter
        n1=Iout(min(r):max(r),min(c):max(c));  
        % Resize letter (same size of template)
        img_r=imresize(n1,[42 24]);
        %figure,imshow(n1);
        %Uncomment line below to see letters one by one
         %imshow(img_r);pause(0.5)
 imwrite(img_r,['H:\\mainproject\\codes\\images\\test0.jpg' ]);
 end   

但只有最后一个字母保存在文件夹中。我不知道它在哪里犯了错误。我尝试了很多,但我没有得到它。请帮助我,并提前谢谢

1 个答案:

答案 0 :(得分:1)

我认为您可能会覆盖图像,因为您使用的是相同名称test0.jpg。尝试:

[Ilabel num] = bwlabel(If);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 83]);
figure,imshow(Ibox);

 for n=1:num
        [r,c] = find(Ilabel==n);
        % Extract letter
        n1=Iout(min(r):max(r),min(c):max(c));  
        % Resize letter (same size of template)
        img_r=imresize(n1,[42 24]);
        %figure,imshow(n1);
        %Uncomment line below to see letters one by one
        %imshow(img_r);pause(0.5)
        image_name = strcat('H:\\mainproject\\codes\\images\\test', num2str(n), '.jpg');
        imwrite(img_r,[image_name]);
 end

我实际上现在无法测试,也无法评论(低于50分)。希望它有所帮助,