I have this path ('C:\Users\hp\Desktop\testing\abood'), and i want to convert all images in this path to .mat file

Antworten (1)

KSSV
KSSV am 12 Jul. 2022
Bearbeitet: KSSV am 12 Jul. 2022

0 Stimmen

thepath = 'C:\Users\hp\Desktop\testing\abood' ;
imgFiles = dir([thepath,'\*jpg']) ; % give your image extension
N = length(imgFiles) ;
for i = 1:N
imgFile = fullfile(imgFiles(i).folder,imgFiles(i).name) ;
I = imread(imgFile) ;
[filepath,name,ext] = fileparts(imgFile) ;
fname = [thepath,filesep,name,'.mat'] ;
save(fname,'I')
end

7 Kommentare

abdullah al-dulaimi
abdullah al-dulaimi am 12 Jul. 2022
not work brother
KSSV
KSSV am 12 Jul. 2022
Why it is not working.....throwing any error?
abdullah al-dulaimi
abdullah al-dulaimi am 12 Jul. 2022
Unrecognized function or variable 'imgFile'.
Error in untitled5 (line 7)
imgFile = fullfile(imgFile(i).folder,imgFiles(i).name) ;
this is the error in command window brother
KSSV
KSSV am 12 Jul. 2022
There is a small typo error,,,,it is corrected now..It should work now.
abdullah al-dulaimi
abdullah al-dulaimi am 12 Jul. 2022
brother i want all images in one file .mat (i your case each image have .mat file)
thepath = 'C:\Users\hp\Desktop\testing\abood' ;
imgFiles = dir([thepath,'\*jpg']) ; % give your image extension
N = length(imgFiles) ;
I = cell(N,1) ;
for i = 1:N
imgFile = fullfile(imgFiles(i).folder,imgFiles(i).name) ;
I{i} = imread(imgFile) ;
end
fname = [thepath,'myFile','.mat'] ;
save(fname,'I')
Bhagavathula Meena
Bhagavathula Meena am 24 Sep. 2022
I have been searching for the same context to my work . Thank you very much . its working .

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by