input image without writing a path directory in the code

1 Ansicht (letzte 30 Tage)
Danya Karimi
Danya Karimi am 27 Dez. 2019
Kommentiert: dpb am 1 Jan. 2020
I want to write a matlab code which contain inputing images from any directory and any computer without the need for writing the directory path.
I forgot how to do that, I will be thankful for any help
  2 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 27 Dez. 2019
Are you asking to write a code to read any image from the computer any directories/folders without mentioing the path of the directory?
dpb
dpb am 1 Jan. 2020
Well, you'll have to tell it somehow; what groundrules are in play for allowable solution space?
Adding a zillion subdirectories and cd 'ing to them is NOT a recommended solution.
Two possiblilities out of many -depending upon the above question:
  1. If no user intervention, use the OS dir() or similar to do a directory search from some point for the specific files wanted and parse the results to find the base directory. Somewhat problematic if there are many subdirectories and files and can't isolate a starting location very closely, but possible in theory.
  2. I there is the possiblity of initial human intervention, use the uiopenfile dialog and let the user navigate to the starting position desired.
Other ways would be variations on a them depending upon just what it is that is meant/desired/required to meet the demand.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Stijn Haenen
Stijn Haenen am 29 Dez. 2019
maybe you can use this:
to add every folder to the path before importing the files

Image Analyst
Image Analyst am 29 Dez. 2019
Maybe you should just call uigetdir() and let the user decide the folder so you don't have to write any folder name in advance.
folder = uigetdir()
filePattern = fullfile(folder, '*.png')
% Get all PNG files in the user's selected folder and all subfolders.
imds = imageDatastore(filePattern, 'ReadFcn', @imread)
allFileNames = imds.Files

Danya Karimi
Danya Karimi am 1 Jan. 2020
The answer is:
[f,p]= uigetfile();
I= imread([p,f]);
Thank you for your time guys.

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by