필터 지우기
필터 지우기

saving the output arrays in for loop

조회 수: 2 (최근 30일)
eman
eman 2014년 9월 30일
답변: Image Analyst 2014년 9월 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

답변 (3개)

Jan
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
eman
eman 2014년 9월 30일
Thanks after inserting the two lines and running the code, when I clicked filename at work space it is empty. what is the problem?
Image Analyst
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
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
  댓글 수: 1
eman
eman 2014년 9월 30일
Thanks I will try it also.

댓글을 달려면 로그인하십시오.


Image Analyst
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?

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by