is it possible to adjust the codes such a way that it'l read all sizes of images

4 ビュー (過去 30 日間)
is it possible to adjust the codes such a way that it'l read all sizes of images currently its taking only 11kb
function out=load_database();
% We load the database the first time we run the program.
persistent loaded;
persistent w;
if(isempty(loaded))
v=zeros(10304,400);
for i=1:40
cd(strcat('s',num2str(i)));
for j=1:10
a=imread(strcat(num2str(j),'.pgm'));
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;
  9 件のコメント
Image Analyst
Image Analyst 2013 年 4 月 15 日
Please start a new question so we don't keep bugging geethi with new emails for your question.
Walter Roberson
Walter Roberson 2013 年 4 月 15 日
The jpeg is probably RGB, a 3-dimensional array whose total size is size(a,1) * size(a,2) * size(a,3). You can recode as
v(:,(i)*6+j) = a(:);

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

採用された回答

Image Analyst
Image Analyst 2013 年 3 月 19 日
You need to either make v a cell array, so that each element would be an image of a different size, or you need to call imresize before you stuff it into a column of v (if v is to remain just a regular numerical array).
  2 件のコメント
geethi
geethi 2013 年 3 月 20 日
編集済み: Walter Roberson 2013 年 3 月 20 日
sir i decoded that problem...but now one error is comin
??? Index exceeds matrix dimensions.
Error in ==> frs at 33 title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
main pgm is:
w=load_database();
prompt={'compare'};
title='IMAGE INPUT';
ans=inputdlg(prompt,title);
if ~isempty(ans{1})
r1 = str2num(ans{1});
if isempty(r1)
ri =round (400*rand(1,1));
end
end
r=w(:,r1);
v=w(:,[1:r1-1 r1+1:end]);
N=20;
O=uint8(ones(1,size(v,2)));
m=uint8(mean(v,2));
vzm=v-uint8(single(m)*single(O));
L=single(vzm)'*single(vzm);
[V,D]=eig(L);
V=single(vzm)*V;
V=V(:,end:-1:end-(N-1));
cv=zeros(size(v,2),N);
for i=1:size(v,2);
cv(i,:)=single(vzm(:,i))'*V;
end
subplot(121);
imshow(reshape(r,112,92));
*title('Looking for ...','FontWeight','bold','Fontsize',16,'color','red');
*
subplot(122);
p=r-m;
s=single(p)'*V;
z=[];
for i=1:size(v,2)
z=[z,norm(cv(i,:)-s,2)];
if(rem(i,20)==0),imshow(reshape(v(:,i),112,92)),end;
drawnow;
end
[a,i]=min(z);
subplot(122);
imshow(reshape(v(:,i),112,92));title('Found!','FontWeight','bold','Fontsize',16,'color','red');
Image Analyst
Image Analyst 2013 年 3 月 20 日
Looks like it thinks title() is one of your variables instead of the built-in function. Set a breakpoint at that line and say
k>> whos title
k>> which -all title
and tell us what it says. You probably redefined title() to be a variable.

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

その他の回答 (1 件)

Md Fakhrul Alam Sajib
Md Fakhrul Alam Sajib 2018 年 2 月 26 日
How to make v a cell array in this code. I want to adjust this codes such a way that it will read all sizes of images. Could anyone explain?
function out=load_database();
% We load the database the first time we run the program.
persistent loaded;
persistent w;
if(isempty(loaded))
v=zeros(10304,400);
for i=1:40
cd(strcat('s',num2str(i)));
for j=1:10
a=imread(strcat(num2str(j),'.pgm'));
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;
  3 件のコメント
Md Fakhrul Alam Sajib
Md Fakhrul Alam Sajib 2018 年 2 月 27 日
Thank you. Is it correct way to make v a cell array? I am still getting this error....
Error using reshape,
To RESHAPE the number of elements must not change.
Error in load_database (line 12)
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
function out=load_database()
% We load the database the first time we run the program.
persistent loaded;
persistent w;
if(isempty(loaded))
v={zeros(10304,400)};
for i=1:40
cd(strcat('s',num2str(i)));
for j=1:10
a=imread(strcat(num2str(j),'.pgm'));
v(:,(i-1)*10+j)=reshape(a,size(a,1)*size(a,2),1);
end
cd ..
end
w=uint8(v); % Convert to unsigned 8 bit numbers to save memory.
end
loaded=1; % Set 'loaded' to aviod loading the database again.
out=w;
Md Fakhrul Alam Sajib
Md Fakhrul Alam Sajib 2018 年 2 月 28 日
Sir, how to use imresize() function to solve this error?

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by