필터 지우기
필터 지우기

Change name of image file

조회 수: 15 (최근 30일)
Olu adroit
Olu adroit 2015년 2월 7일
편집: Image Analyst 2015년 2월 8일
Hi all, Please how can i change the name of an existing image file. I have used "imread" to read the image and "imwrite" to export with the name that i want. But the exported image is in greyscale and not coloured.
Please how can I export the imported coloured and a coloured file?
thanks in advance

채택된 답변

Image Analyst
Image Analyst 2015년 2월 8일
Use movefile() to rename files:
movefile(oldFileName, newFileName);
  댓글 수: 2
Olu adroit
Olu adroit 2015년 2월 8일
Thanks image analyst. Please how can I put timestamp on the newFileName ? Thanks for your help
Image Analyst
Image Analyst 2015년 2월 8일
편집: Image Analyst 2015년 2월 8일
If you want to rename but use the current time as the timestamp, I'd use copyfile() instead of movefile(). This will create a brand new file that I think should have the current time. Then you can delete the source file. Be aware that Windows maintains three different times stamps for a file: created, modified, and last accessed. If not all 3 are changed with copyfile(), then you'll have to first call imread() and then call imwrite() to create a totally brand new file and this will definitely have all three times as the current time.
Use fileparts() and sprintf() to create the brand new filename. For example
imageArray = imread(oldFileName);
[folder, baseFileName, ext] = fileparts(oldFileName);
% Change base file name and extension.
newBaseFileName= sprintf('%s_changed.PNG', baseFileName);
newFullFileName = fullfile(folder, newBaseFileName);
imwrite(imageArray, newFullFileName); % New file will be PNG instead of TIF

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Erik S.
Erik S. 2015년 2월 8일
Hi, Use this code to generate a time stamp datestr(now);
With this Matlab returns date-month-year Hour:Min:Sec You can use for example strsplit if you want a part of the date of the time only.

카테고리

Help CenterFile Exchange에서 Import, Export, and Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by