- imshow : https://in.mathworks.com/help/images/ref/imshow.html
- imread : https://in.mathworks.com/help/matlab/ref/imread.html
- fullfile : https://in.mathworks.com/help/matlab/ref/fullfile.html
- uigetfile : https://in.mathworks.com/help/matlab/ref/uigetfile.html
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');
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!