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

조회 수: 2 (최근 30일)
[file, path]= uigetfile(('*.jpg',...
'Select One or More Files', ...
'MultiSelect', 'on');

답변 (1개)

Abhishek Chakram
Abhishek Chakram 2023년 9월 21일
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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by