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!