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)
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
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
  1 commentaire
YuCheng Chen
YuCheng Chen le 21 Oct 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?

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by