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!