I want to do the same action to every files(.png) in one folder, but I face some problem.

1 visualizzazione (ultimi 30 giorni)
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 ?

Risposta accettata

Image Analyst
Image Analyst il 19 Ott 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
  1 Commento
YuCheng Chen
YuCheng Chen il 21 Ott 2019
b=imread(baseFileName) has solved.
I have the 227x227(uint8) matrix called "a" now
How do I save "a" as png(and name it) in a new folder of my computer?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by