Hi, please if I have 500 I want to do like this for all the images I need a " for "but I don't how, thank you for help
1 view (last 30 days)
Show older comments
olfa abdalah
on 8 Apr 2016
Commented: olfa abdalah
on 9 Apr 2016
a=imread('image\0.jpg');
r=a(:,:,1);
v=a(:,:,2);
b=a(:,:,3);
couleur=(r+v+b)/3;
save('img\couleur\0.mat','couleur');
0 Comments
Accepted Answer
Azzi Abdelmalek
on 8 Apr 2016
for k=0:500
a=imread(sprintf('image\%d.jpg',k));
r=a(:,:,1);
v=a(:,:,2);
b=a(:,:,3);
couleur=(r+v+b)/3;
save(sprintf('img\couleur\%d.mat',k),'couleur');
end
3 Comments
Walter Roberson
on 9 Apr 2016
in_dir = 'image';
out_dir = fullfile(in_dir, 'couler');
for k = 0 : 499
inname = fullfile(in_dir, sprintf('%d.jpg', k));
a = imread(inname);
couleur = mean(a, 3);
outname = fullfile(out_dir, sprintf('%d.mat', k));
save(outname, 'couleur');
end
The problem with Azzi's code is that inside sprintf(), \ has special meaning. His code could be fixed with
a=imread(sprintf('image\\%d.jpg',k));
and
save(sprintf('img\\couleur\\%d.mat',k),'couleur');
In my version, I avoid the issue by using the more robust fullfile()
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!