I want to get multiple jpg files by path and name through the function uigetfile and display them in the picture window.

2 vues (au cours des 30 derniers jours)
[file, path]= uigetfile(('*.jpg',...
'Select One or More Files', ...
'MultiSelect', 'on');

Réponses (1)

Abhishek Chakram
Abhishek Chakram le 21 Sep 2023
Hi KiBaek.
It is my understanding that you want to select multiple jpg images and display them in multiple figure windows or same figure window. Here’s a sample code for that:
Code to display in multiple figure windows:
[fileNames, filePath] = uigetfile('*.jpg', 'Select JPG files', 'MultiSelect', 'on');
% Check if the selected files are returned as a cell array
if iscell(fileNames)
numFiles = numel(fileNames);
else
numFiles = 1;
fileNames = {fileNames};
end
for i = 1:numFiles
% Construct the full file path
fullFilePath = fullfile(filePath, fileNames{i});
% Read and display the image
image = imread(fullFilePath);
figure;
imshow(image);
title(fileNames{i});
end
Code to display in same figure window:
[fileNames, filePath] = uigetfile('*.jpg', 'Select JPG files', 'MultiSelect', 'on');
% Check if the selected files are returned as a cell array
if iscell(fileNames)
numFiles = numel(fileNames);
else
numFiles = 1;
fileNames = {fileNames};
end
% Calculate the number of rows and columns for the subplot
numRows = ceil(sqrt(numFiles));
numCols = ceil(numFiles / numRows);
figure;
for i = 1:numFiles
% Construct the full file path
fullFilePath = fullfile(filePath, fileNames{i});
image = imread(fullFilePath);
subplot(numRows, numCols, i);
imshow(image);
% Set the title of the subplot to the corresponding file name
title(fileNames{i});
end
You can refer to the following documentation to know more about the functions used:
Best Regards,
Abhishek Chakram

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by