Comparing extensions

8 ビュー (過去 30 日間)
Keanu
Keanu 2012 年 4 月 7 日
編集済み: Fahman 2014 年 5 月 26 日
Hi all, I have written a Matlab code that gets a .BMP image and compresses it using dct compression and then shows the compressed image and saves the compressed file as "somefilename".IM3. My program should also be able to open the .IM3 file and decompress it. so when browsing for the file for the first time, if a .BMP file is selected it should compress it and if a .IM3 file is selected it should decompress it. So how can I compare the two file extensions to see what file is selected and what action it should perform? also I have three different buttons in my GUI with three different compression ratio's and when the user presses a button, it will show the original image along with its compressed version. my buttons are in the following format:
uicontrol('Style', 'pushbutton', 'String','Low',... 'Position', [10 5 50 20],... 'Callback', 'subplot(2,2,2), image(uint8(ci2f)),title(''Compression Factor 2 : 2'')');
how can I add a save function to the above code so that when the button is pressed, not only it would show the image but also it would save it as well? any help would be greatly appreciated. Thank You

回答 (3 件)

Walter Roberson
Walter Roberson 2012 年 4 月 7 日
extn = filename( find(filename == '.', 1, 'last') + 1 : end );
if strcmpi(extn, 'BMP')
compress_file(filename);
elseif strcmpi(extn, 'IM3');
uncompress_file(filename);
else
disprove_law_of_excluded_middle(filename);
end

Keanu
Keanu 2012 年 4 月 7 日
Thank You for your answer Walter but now I get the following error:
Error using find Second argument must be a positive scalar integer.
Error in compimage (line 10) extn = filename( find(filename == '.', 'last') + 1 : end );
any ideas why?
  1 件のコメント
Walter Roberson
Walter Roberson 2012 年 4 月 7 日
Sorry, I missed an argument. I fixed it in the above code.

サインインしてコメントする。


Fahman
Fahman 2014 年 5 月 26 日
編集済み: Fahman 2014 年 5 月 26 日
No uncompress_file function in matlab I can not open im3 file how can I open it?

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by