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
1 view (last 30 days)
Show older comments
pl help me with codes
0 Comments
Answers (3)
KSSV
on 4 May 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
0 Comments
Ameer Hamza
on 4 May 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.
0 Comments
Yuvaraj Venkataswamy
on 4 May 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
0 Comments
See Also
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!