I have a folder of binary images.I want to assign each image a variable so that it would be easy to extract features for the images.can someone please help me out?
Show older comments
myFolder = 'e:\\invertedimages';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.bmp');
bmpFiles = dir(filePattern);
for k = 1:length(bmpFiles)
baseFileName = bmpFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
7 Comments
neha viswanath
on 11 Feb 2015
Image Analyst
on 11 Feb 2015
imageArray{k} = imread(fullFileName);
neha viswanath
on 11 Feb 2015
Image Analyst
on 11 Feb 2015
Attach your code. You obviously did something wrong - not what I told you. Here is the code that I told you to run and it works fine:
myFolder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.tif');
bmpFiles = dir(filePattern);
for k = 1:length(bmpFiles)
baseFileName = bmpFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
imshow(imageArray); % Display image.
drawnow; % Force display to update immediately.
end
Copy and paste that, then run it. Then compare it to yours and tell me what you did differently.
neha viswanath
on 11 Feb 2015
Edited: neha viswanath
on 11 Feb 2015
neha viswanath
on 11 Feb 2015
Image Analyst
on 11 Feb 2015
Sorry - I evidently pasted the original code instead of the code I changed and tested. Try this:
myFolder = fileparts(which('cameraman.tif')); % Determine where demo folder is (works with all versions).
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.tif');
bmpFiles = dir(filePattern);
for k = 1:length(bmpFiles)
baseFileName = bmpFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray{k} = imread(fullFileName);
imshow(imageArray{k}); % Display image.
drawnow; % Force display to update immediately.
end
As to your latest question, bmpFiles is an array of structures. Each structure has several fields, one of which is name. So bmpFiles(k) is the k'th structure in the array and bmpFiles(k).name is the file name of the k'th image.
Accepted Answer
More Answers (1)
Image Analyst
on 11 Jan 2015
0 votes
Do you have a question? You have your image in the loop, so just do something with it.
Categories
Find more on Matrix Indexing 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!