フィルターのクリア

I want to read 24 images and stores value of omega,imou,nb into mat file, but some error in my program...

1 回表示 (過去 30 日間)
function [timeelapsed1] = matfileforallimages()
%create .mat file and calculates weights of each binary image in the database
clc;
clear all;
% database veins
nuser=4;
nrep=6;
path='C:\Program Files\MATLAB\R2013a\bin\img\PCA\my_PhD_Programs\DorsalVeinsDEMO\templates';
for iuser=1:nuser
for irep=1:nrep
nfichd=['binaryROImano-',num2str(iuser,'%.3d'),'-',num2str(irep,'%.3d')];
nfichd=[path,'\',nfichd,'.bmp'];
image1=imread(nfichd,'bmp');
%cd ..
timeelapsed1=cputime;
[irow,icol]=size(image1);
S=reshape(image1, irow*icol, 1);
%image mean
imoy=[];
imoy=mean(S,2);
S=double(S);
%eigen values and eigen vectors for the matrix L=S'S
L=S'*S;
[vv dd]=eig(L);
v=[];
d=[];
for i=1:size(vv,2)
if (dd(i,i)>1e-4)
v=[v vv(:,i)];
d=[d dd(i,i)];
end
end
%sort eigen values of L=S'S
[dtemp index]=sort(d,'descend');
for i=1:length(d)
vtemp(:,i)=v(:,index(i));
end
d=dtemp;
v=vtemp;
%normalize eigen vectors of L=S'S
for i=1:size(v,2)
kk=v(:,i);
temp=sqrt(sum(kk.^2));
v(:,i)=v(:,i)./temp;
end
%eigen values and eigen vectors for the covariance matrix C=SS'
u=[];
for i=1:size(v,2)
temp=sqrt(d(i));
u=[u (S*v(:,i))./temp];
end
%normalize eigen vectors of C
for i=1:size(u,2)
kk=u(:,i);
temp=sqrt(sum(kk.^2));
u(:,i)=u(:,i)./temp;
end
%number of eliminated components from the eigen base
nb=0;
%weights of database's images
omega=[];
for h=1:size(S,2)
ww=[];
for i=1:size(u,2)-nb
t=u(:,i);
Weight=dot(t,S(:,h)');
ww=[ww;Weight];
end
omega=[omega,ww];
end
M=4;
save('omega1', 'omega', 'imoy', 'u', 'nb', 'M') %omega contains the extracted features of database images
end
end
  4 件のコメント
Balaji M. Sontakke
Balaji M. Sontakke 2017 年 10 月 31 日
Yes sir, just am trying to store the omega,imou,nb,m for each of the 24 images. But only content of one image is stored, my output is like following... imoy x 1 u X 1 nb 0 omega 59.02 M 4
But i want output like this.. imoy x 1 u X 24 nb 0 omega X 24 M 4
What's wrong in my program i dont know...
Balaji M. Sontakke
Balaji M. Sontakke 2017 年 11 月 2 日
what happen sir, It is not possible to store the omega,imou,nb,m for each of the images?

サインインしてコメントする。

採用された回答

Geoff Hayes
Geoff Hayes 2017 年 11 月 2 日
Balaji - note that on each iteration of the second loop you are saving the data to file
for iuser=1:nuser
for irep=1:nrep
...
M=4;
save('omega1', 'omega', 'imoy', 'u', 'nb', 'M') %omega contains the extracted features of database images
end
end
which means that you are overwriting the data in the omega1 file on each of these iterations. So the only data in this file corresponds to the 24th iteration.
If you want to store all of this data to the same file, then I suggest that you create some cell arrays (in case your matrix dimensions change on any iteration) to store the data from each iteration. Once you have finished looping over all of these files, then save the cell array data to file (doing this outside of the outer for loop.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by