Errors using imwrite "Unable to determine the file format from the filename" I am trying to splice together the name of a new image file but dont understand why imwrite isnt working.

5 ビュー (過去 30 日間)
% --- Executes on button press in Save.
function Save_Callback(hObject, eventdata, handles)
% hObject handle to Save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global y
newname = get(handles.newname,'String')
display(y);
tif = '.tif';
filename = [newname tif];
display(filename);
imwrite(y,'default',newname,'tif')
Heres hat I have so far. Not really sure how to solve this issue with the way I am going about it. I though thtat if the filename had the .tif written in it it may recognize the fileformat, but I guess not. Any suggestions? Also on another note, how can I create somesort of dropdown menu to specify the pathway for this image file? Thanks
  1 件のコメント
Stephen23
Stephen23 2015 年 12 月 21 日
This time I fixed your code formatting for you. In future please do it yourself by first selecting your code text, and then clicking the {} Code button. The default text that clicking the button produces is not markup.

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

採用された回答

Stephen23
Stephen23 2015 年 12 月 21 日
編集済み: Stephen23 2015 年 12 月 21 日
You could try reading the imwrite documentation. At the top of the page there is a list of the accepted syntaxes:
Syntax
imwrite(A,filename)example
imwrite(A,map,filename)example
imwrite(___,fmt)
imwrite(___,Name,Value)
Whereas what you are trying to use is:
imwrite(y,'default',newname,'tif')
What does 'default' mean? It does not seem to fit any of the permitted syntaxes. Where did you get this from? I don't see 'default' listed as any of the permitted input arguments. When I try your code with an image it produces the same error:
>> X = imread('parula_0.png');
>> newname = 'test';
>> imwrite(X,'default',newname,'tif')
??? Error using ==> imwrite at 435
Unable to determine the file format from the filename.
but when I remove 'default' from your code it works fine:
>> imwrite(X,newname,'tif')
with a new file created correctly. This is why reading the documentation is useful.
Also note that your code creates a new name string in the variable filename, but that you do not use this variable. Perhaps you really meant to call this:
imwrite(y,filename,'tif')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImages についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by