Write an image with file name specified in a variable var1 (char)
21 ビュー (過去 30 日間)
古いコメントを表示
I need to write an image and I want to give it a name that is stored in a variable var1, which is a 4 byte char. I am trying to use the command imwrite, but it seems not to have this option.
0 件のコメント
回答 (2 件)
Image Analyst
2016 年 3 月 17 日
Try this:
imwrite(yourImageMatrix, var1);
It would be good to add an extension so that it knows the format to write it out in. If var1 does not contain the extension, like 1.jpg, then append an extension and prepend the folder where you want to store the image:
var1 = '1234'; % Whatever - some filename with or without extension.
[~, baseFileName, ext] = fileparts(var1);
if isempty(ext)
ext = '.PNG'; % Make it a PNG format image.
end
fullFileName = fullfile(yourFolder, [baseFileName, ext]);
imwrite(yourImageMatrix, fullFileName);
0 件のコメント
Walter Roberson
2016 年 3 月 17 日
imwrite(TheArray, var1, 'PNG') %example
With your var1 only being 4 bytes, you do not have room for both the base file name and a period and 3 characters of extension, so imwrite is not going to be able to deduce what kind of image you want to create, so you will need to tell it the format.
Note that most other programs will be counting on the extension being there to tell them what kind of image it is, so this may be of limited value.
You should be considering adding on the extension to the file name. For example,
imwrite(TheArray, [var1 '.png'])
参考
カテゴリ
Help Center および File Exchange で Image Processing Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!