Why i cannot get full database?
1 次查看(过去 30 天)
显示 更早的评论
hi matlab community, ask shown in figure below, the matlab database did not show full database . it just shown []. Can someone help me? this is for my FYP. Can see coding attach. I really appreciate your help!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1403294/image.png)
0 个评论
回答(1 个)
Image Analyst
2023-6-5
编辑:Image Analyst
2023-6-5
Maybe it's due to you looking for the wrong extension in the folder. For example, maybe this:
addpath('C:\Users\User\Desktop\LIVE database\databaserelease2\jpeg');
for i=1:233
A=imread(sprintf('img%d.bmp',i));
A1=rgb2gray(A);
A2=double(A1);
FYPdatabase{575+i,1}=A2;
FYPdatabase{i,3}=1;
end
should really be this:
folder = 'C:\Users\User\Desktop\LIVE database\databaserelease2\jpeg';
filePattern = fullfile(folder, '*.jpeg')
fileList = dir(filePattern)
for k = 1 : numel(fileList) % For however many files are there...
% Get the full filename.
fullFileName = fullfile(fileList(k).folder, fileList(k).name);
fprintf('Adding %s\n', fullFileName)
% Read in original image.
rgbImage = imread(fullFileName);
% Convert from color to grayscale if necessary.
if size(rgbImage, 3) == 3
% It's color. Need to convert to gray scale.
grayImage = rgb2gray(rgbImage);
else
grayImage = rgbImage; % It's already grayscale.
end
grayImage = double(grayImage);
% Add it to the cell array.
% 575 should be a variable that adjusts according to how many
% images there were in the prior loops!!!
FYPdatabase{575 + k, 1} = grayImage;
FYPdatabase{k, 2} = []; % 2 is unassigned for some reason???
FYPdatabase{k, 3} = 1;
end
This is more robust than what you have. Make similar adjustments for the other loops that handle other image file extensions.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!