How to save Histogram of Multiple Images

조회 수: 1 (최근 30일)
Zara Khan
Zara Khan 2022년 6월 24일
댓글: Zara Khan 2022년 6월 24일
clc; clear all; close all
folder = 'E:\input';
filepattern = fullfile(folder, '*.png');
srcFiles = dir(filepattern);
numImages = length(srcFiles);
for k = 1 : numImages
fullFileName = fullfile(folder, srcFiles(k).name);
I=imread(fullFileName);
imhist(I);
mkdir('E:\hist');
path='E:\hist\img';
saveas(gcf,['histo' num2str(k) '.png'])
end
This is not working well. any help ???

채택된 답변

DGM
DGM 2022년 6월 24일
This should be a start
sourcefolder = 'E:\input';
filepattern = fullfile(sourcefolder, '*.png');
% this shouldn't be in the loop
% the subdirectory needs to exist before you use it
outputfolder = './hist/img';
mkdir(outputfolder);
srcFiles = dir(filepattern);
numImages = length(srcFiles);
for k = 1 : numImages
% build full file path+name
% use sprintf and zero-padded numbers (this assumes 3 digits is enough)
inputfilename = fullfile(sourcefolder, srcFiles(k).name);
outputfilename = fullfile(outputfolder, sprintf('histo_%03d.png',k));
I = imread(inputfilename);
imhist(I);
saveas(gcf,outputfilename)
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by