How to Search images Automatically from "My Pictures " folder
9 views (last 30 days)
Show older comments
Programming student
on 20 Oct 2013
Answered: Lakshmi Prasad Mylari
on 5 Apr 2022
if i have set Desktop as my work space and my images are stored in "My Pictures " so what i want is to search the image automatically from My pictures folder that is not my work space how do i get it please help me with it
0 Comments
Accepted Answer
Image Analyst
on 20 Oct 2013
Edited: Image Analyst
on 20 Oct 2013
See this code to recurse into subfolders and find image files:
% Start with a folder and get a list of all subfolders.
% Finds and prints names of all PNG and TIF images in
% that folder and all of its subfolders.
clc; % Clear the command window.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
% Define a starting folder.
start_path = fullfile(matlabroot, '\toolbox\images\imdemos');
% Ask user to confirm or change.
topLevelFolder = uigetdir(start_path);
if topLevelFolder == 0
return;
end
% Get list of all subfolders.
allSubFolders = genpath(topLevelFolder);
% Parse into a cell array.
remain = allSubFolders;
listOfFolderNames = {};
while true
[singleSubFolder, remain] = strtok(remain, ';');
if isempty(singleSubFolder)
break;
end
listOfFolderNames = [listOfFolderNames singleSubFolder];
end
numberOfFolders = length(listOfFolderNames)
% Process all image files in those folders.
for k = 1 : numberOfFolders
% Get this folder and print it out.
thisFolder = listOfFolderNames{k};
fprintf('Processing folder %s\n', thisFolder);
% Get PNG files.
filePattern = sprintf('%s/*.png', thisFolder);
baseFileNames = dir(filePattern);
% Add on TIF files.
filePattern = sprintf('%s/*.tif', thisFolder);
baseFileNames = [baseFileNames; dir(filePattern)];
numberOfImageFiles = length(baseFileNames);
% Now we have a list of all files in this folder.
if numberOfImageFiles >= 1
% Go through all those image files.
for f = 1 : numberOfImageFiles
fullFileName = fullfile(thisFolder, baseFileNames(f).name);
fprintf(' Processing image file %s\n', fullFileName);
end
else
fprintf(' Folder %s has no image files in it.\n', thisFolder);
end
end
Of course if you're looking for one particular filename , then you can just break out of the loops once you've found it. Use strfind() or strcmpi() to check if the found filename matches the desired filename.
0 Comments
More Answers (2)
Azzi Abdelmalek
on 20 Oct 2013
Edited: Azzi Abdelmalek
on 20 Oct 2013
I don't know what you mean by search. To import your image from a specific folder
folder='C:\Users\pc\Pictures'
filename='mypicture.jpg'
f=fullfile(folder,filename)
Im=imread(f)
You can also use uigetfile
doc uigetfile
0 Comments
Lakshmi Prasad Mylari
on 5 Apr 2022
folder='C:\Users\pc\Pictures'
filename='mypicture.jpg'
f=fullfile(folder,filename)
Im=imread(f)
0 Comments
See Also
Categories
Find more on File Operations 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!