Filter löschen
Filter löschen

i have a dataset of 1000 images.now i want to convert the images into grey images.i also want to find the histogram of all the images at a time and want to store the result too

2 Ansichten (letzte 30 Tage)
pl help me with codes

Antworten (3)

KSSV
KSSV am 4 Mai 2018
images = dir('*jpg') ; % give extension of your images
N = length(images) ; % total number of images
for i = 1:N
I = imread(images(i).name) ;
[m,n,p] = size(I) ;
if p==3
I = rgb2gray(I);
end
[counts,binLocations] = imhist(I) ;
end

Ameer Hamza
Ameer Hamza am 4 Mai 2018
One of easiest solution is to use Image batch processor app. Type
imageBatchProcessor
in the command window. In the app press the load images button, specify the folder. In the function name specify the name of the function you want to apply to all of the images (for example see the function below) and click process selected. You can also use Parallel processing if you have Parallel Processing Toolbox. It will automatically process all the images. In the end, you can export all the data to the workspace or save to another folder.
function out = batchImage(im)
out.gray = rgb2gray(im);
out.hist = histcounts(gray, 0:255);
end
This approach reduces the chances of making an error. And if you are still interested in the code, press the downward arrow on export button and select Generate Function.

Yuvaraj Venkataswamy
Yuvaraj Venkataswamy am 4 Mai 2018
imagefiles = dir('*.jpg');
nfiles = length(imagefiles);
for ii=1:nfiles
currentfilename = imagefiles(ii).name;
I{ii}=imread(currentfilename);
% grayscale conversion
I1{ii}=rgb2gray(I{ii}); % grayscale conversion
I2{ii}=imhist(I1{ii});
% Save results
str = sprintf('%d', ii);
filename = fullfile('D:\', sprintf('frame_%03d.JPG', ii));
imwrite(I2{ii}, filename);
end

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by