Reading Image/Audio Files of different types
2 views (last 30 days)
Show older comments
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!!
0 Comments
Answers (1)
Omer Yasin Birey
on 18 Dec 2018
Edited: Omer Yasin Birey
on 18 Dec 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
0 Comments
See Also
Categories
Find more on Audio I/O and Waveform Generation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!