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 次查看(过去 30 天)
显示 更早的评论
回答(3 个)
KSSV
2018-5-4
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 个评论
Ameer Hamza
2018-5-4
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 个评论
Yuvaraj Venkataswamy
2018-5-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Convert Image Type 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!