I want to do the same action to every files(.png) in one folder, but I face some problem.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
YuCheng Chen
le 19 Oct 2019
Commenté : YuCheng Chen
le 21 Oct 2019
I want to put 1092 files(109 x 109 .png image) in the center of 227 x 227 matrix, so I write down a code like this
files = dir('*.png') ; % I am in folder of the png files
N = length(files) ; % total number of files
% loop for each file
for i = 1:N
x = files(i).name ;
b=imread('x');
a=zeros(227);
a(60:168,69:159)=b;
a=uint8(a);
end
end
answer
Error using imread>get_full_filename (line 516)
File "x" does not exist.
Error in imread (line 340)
fullname = get_full_filename(filename);
How can I process all my files in the folder, and save as .png in a new folder ?
Réponse acceptée
Image Analyst
le 19 Oct 2019
Try the padarray() function.
Or if you want to do it by indexing:
baseFileName = files(i).name ;
b=imread(baseFileName);
a=zeros(227, 227, 'uint8'); % Add class and get rid of a=uint8(a); line of code
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!