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

4 views (last 30 days)
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 Comments
Image Analyst
Image Analyst on 15 Apr 2013
Please start a new question so we don't keep bugging geethi with new emails for your question.
Walter Roberson
Walter Roberson on 15 Apr 2013
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(:);

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 19 Mar 2013
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 Comments
geethi
geethi on 20 Mar 2013
Edited: Walter Roberson on 20 Mar 2013
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 on 20 Mar 2013
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.

Sign in to comment.

More Answers (1)

Md Fakhrul Alam Sajib
Md Fakhrul Alam Sajib on 26 Feb 2018
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 Comments
Md Fakhrul Alam Sajib
Md Fakhrul Alam Sajib on 27 Feb 2018
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;

Sign in to comment.

Categories

Find more on Language Support in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!