How to access JPG files from folder then display them?

2 次查看(过去 30 天)
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Get list of all JPG files in this directory
% DIR returns as a structure array. You will need to use () and . to get
% the file names.
imagefiles = dir('C:\Users\Jake\Desktop\ImagesMatlab.jpg');
nfiles = length(imagefiles); % Number of files found
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
images{ii} = currentimage
end
%
% % Read in standard MATLAB color demo image.
% rgbImage = imread('Edmund comp room ambient flash off.jpg');
% [rows columns numberOfColorBands] = size(rgbImage);
% subplot(2, 2, 1);
% imshow(rgbImage, []);
% title('Original Color Image', 'Fontsize', fontSize);
% set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
%
%
% % Extract the individual color planes.
% redPlane = rgbImage(:, :, 1);
% greenPlane = rgbImage(:, :, 2);
% bluePlane = rgbImage(:, :, 3);
%
% % Let's get its histograms.
% [pixelCountR grayLevelsR] = imhist(redPlane);
% subplot(2, 2, 2);
% bar(pixelCountR, 'r');
% title('Histogram of red plane', 'Fontsize', fontSize);
% xlim([0 grayLevelsR(end)]); % Scale x axis manually.
% xlabel('8 Bit Scale 0-Black 255-White of RGB Color Model')
% ylabel('Relative Number of Pixels in Image')
%
% [pixelCountG grayLevelsG] = imhist(greenPlane);
% subplot(2, 2, 3);
% bar(pixelCountG, 'g');
% title('Histogram of green plane', 'Fontsize', fontSize);
% xlim([0 grayLevelsG(end)]); % Scale x axis manually.
% xlabel('8 Bit Scale 0-Black 255-White of RGB Color Model')
% ylabel('Relative Number of Pixels in Image')
%
% [pixelCountB grayLevelsB] = imhist(bluePlane);
% subplot(2, 2, 4);
% bar(pixelCountB, 'b');
% title('Histogram of blue plane', 'Fontsize', fontSize);
% xlim([0 grayLevelsB(end)]); % Scale x axis manually.
% xlabel('8 Bit Scale 0-Black 255-White of RGB Color Model')
% ylabel('Relative Number of Pixels in Image')

采纳的回答

Walter Roberson
Walter Roberson 2016-6-21
projectdir = 'C:\Users\Jake\Desktop';
imagefiles = dir( fullfile(projectdir, '*.jpg') );
nfiles = length(imagefiles); % Number of files found
for ii=1:nfiles
currentfilename = fullfile(projectdir, imagefiles(ii).name);
currentimage = imread(currentfilename);
image_names{ii} = currentfilename;
images{ii} = currentimage
end
for ii = 1 : nfiles
imshow(images{ii});
title(image_names{ii});
pause(1);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Printing and Saving 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by