How to access JPG files from folder then display them?

2 views (last 30 days)
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')

Accepted Answer

Walter Roberson
Walter Roberson on 21 Jun 2016
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

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!