Azzera filtri
Azzera filtri

Reading Image/Audio Files of different types

1 visualizzazione (ultimi 30 giorni)
Pedro Sousa
Pedro Sousa il 18 Dic 2018
Modificato: Omer Yasin Birey il 18 Dic 2018
I'm having issues in a code I'm doing because it asks me to create a function that can get the filename and then has to add the type of file to it. Like for example, I have the name = 'test' and in order to do imshow(filename) , my filename must be 'test.jpg', so I have to write: filename=[name '.jpg' ].
The issue here is that some files are of different types like '.png' and my function must read them all alike. Bear in mind I cannot use any pre-set functions besides imread,imshow,length or other basic stuff. The same goes for audio (between .mp3 and .wav).
Help please!!

Risposte (1)

Omer Yasin Birey
Omer Yasin Birey il 18 Dic 2018
Modificato: Omer Yasin Birey il 18 Dic 2018
Hi Pedro, you can find the supported types of both images and audios in the related pages of Matlab. Link:
So, you can create an array of strings and then you may check every supported types with a try-catch loop. Maybe there are easier solutions than this but the code below would work fine too. You can apply this process for the supported types of audios as well.
supportedTypesImages = ["BMP", "GIF", "HDF", "JPEG", "PCX", "PNG", "TIFF", "XWD"];
name = "testImage";
for i = 1:length(supportedTypesImages)
a = [name supportedTypesImages(i)];
newFilename = join(a,'.');
try
readImage = imread(char(newFilename));
imshow(readImage)
catch
end
end

Categorie

Scopri di più su Audio I/O and Waveform Generation 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