필터 지우기
필터 지우기

Reading Image/Audio Files of different types

조회 수: 1 (최근 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 CenterFile Exchange에서 Audio 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