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 ビュー (過去 30 日間)
古いコメントを表示
pl help me with codes
0 件のコメント
回答 (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!