2015-07-10 84 views
0

我想将图像保存到文件夹中。我尝试了下面给出的代码使用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

我想你可能会覆盖的图像,因为你使用相同的名称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分)。希望它有帮助,

相关问题