Reading Image/Audio Files of different types

2 ビュー (過去 30 日間)
Pedro Sousa
Pedro Sousa 2018 年 12 月 18 日
編集済み: Omer Yasin Birey 2018 年 12 月 18 日
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!!

回答 (1 件)

Omer Yasin Birey
Omer Yasin Birey 2018 年 12 月 18 日
編集済み: Omer Yasin Birey 2018 年 12 月 18 日
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

カテゴリ

Help Center および File ExchangeAudio I/O and Waveform Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by