Borrar filtros
Borrar filtros

Reading Image/Audio Files of different types

1 visualización (últimos 30 días)
Pedro Sousa
Pedro Sousa el 18 de Dic. de 2018
Editada: Omer Yasin Birey el 18 de Dic. de 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!!

Respuestas (1)

Omer Yasin Birey
Omer Yasin Birey el 18 de Dic. de 2018
Editada: Omer Yasin Birey el 18 de Dic. de 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

Categorías

Más información sobre Audio I/O and Waveform Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by