필터 지우기
필터 지우기

How to access JPG files from folder then display them?

조회 수: 2 (최근 30일)
Jacob Jakileaszek
Jacob Jakileaszek 2016년 6월 21일
답변: Walter Roberson 2016년 6월 21일
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