saving the output arrays in for loop
1 次查看(过去 30 天)
显示 更早的评论
I need to save the value of TrnPatches for every iteration in for loop and display it How can I do that?
Here is the code:
clc;
clear all;
close all
TrnImgPath='G:\Master_Students\Iman\UIUC\PNGImages\TrainImages\';
TrnPatches=[];
PatchWidth=8;
PatchHeight=8;
NImgs=100;
for i=1:NImgs
I=imread([TrnImgPath 'pos-' num2str(i) .PNG']);%Reading positive Pictures
I=im2double(I);%Convert image to double precision
TrnPatches=[TrnPatches;im2col(I,[PatchHeight,PatchWidth],'sliding')'];
%why the size changes
% imshow(TrnPatches,[]);
disp(i);
disp(TrnPatches);
end
0 个评论
回答(3 个)
Jan
2014-9-30
编辑:Jan
2014-9-30
Insert these lines:
filename = fullfile(TrnImgPath, sprintf('Picture%d.mat', i));
save(filename, TrnPatches);
By the way: You find a lot of help when you ask your favorite internet search engine for "Matlab save files in a loop". The forum is more powerful when you take the chance to examine the already discussed topics.
2 个评论
Image Analyst
2014-9-30
Here, look at this. Then you'll be able to find out whether there's a problem with i, or filename or something else. As long as i is not empty and TrnIMgPath is not empty, then filename cannot be empty. I think if filename were empty, then save() would throw an error. So I have my doubts about what you say, like you're running somewhat different code than what Jan gave. So you're doing something wrong that can be figured out by stepping through and examining variables.
Andrei Bobrov
2014-9-30
one way
cd G:\Master_Students\Iman\UIUC\PNGImages\TrainImages
n = dir('pos-*.PNG');
name1 = {n.name};
nn = numel(name1);
TrnPatches = cell(nn,1);
for ii = 1:nn
I = imread(name1{ii});
TrnPatches{ii} = im2col(im2double(I),[8,8],'sliding').';
end
Image Analyst
2014-9-30
What are you doing with im2col? I never use that function. And why are you concatenating all the images and wanting to save an ever growing image at each iteration?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!