is it possible to adjust the codes such a way that it'l read all sizes of images
4 views (last 30 days)
Show older comments
geethi
on 19 Mar 2013
Commented: Md Fakhrul Alam Sajib
on 28 Feb 2018
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
on 15 Apr 2013
Please start a new question so we don't keep bugging geethi with new emails for your question.
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(:);
Accepted Answer
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
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.
More Answers (1)
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
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;
See Also
Categories
Find more on Language Support in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!