how to rename images (.bmp) merging information from another file?

조회 수: 3 (최근 30일)
dederi
dederi 2015년 1월 9일
댓글: Susan Lane 2017년 5월 28일
Hello, I am struggling writing a code to rename some images (.bmp). I have 900 images to rename; each of one has a different name. Names can be divided into 4 categories: Stim_HF_1.bmp, Stim_HF_1_RUL.bmp, Stim_LF_1.bmp, Stim_LF_1_RUL.bmp with the number changing for every image.
I need to rename each image adding the word that corresponds to that number. For example HF_1 corresponds to the word ‘desert’, while LF_1 corresponds to the word ‘safari’. Following what I would like to obtain: ‘Stim_HF_1.bmp’ into ‘HF_1_desert.bmp’ ‘Stim_HF_1_ RUL.bmp’ into ‘HF_1_desert_ RUL.bmp’ ‘Stim_LF_1.bmp’ into ‘LF_1_safari.bmp’ ‘Stim_LF_1_ RUL.bmp’ into ‘LF_1_safari_ RUL.bmp’
I have a separate file with 3 columns and 901 (headings included) rows. The columns represent number, HF, LF. In each row there is number and words HF and LF associated (e.g. 1, desert, safari).
I wonder if there is a way to rename each image merging the original filename with the information included in the file. Do you have any idea about how to proceed? Many thanks in advance!

답변 (1개)

Guillaume
Guillaume 2015년 1월 9일
편집: Guillaume 2015년 1월 9일
How about:
cd('path\to\bmpfiles');
renametable = readtable('renamefile.txt');
rowfun(@renamefile, renametable);
And in separate m-file
function renamefile(index, HFname, LFname)
sources = strrep({'Stim_HF_*.bmp', 'Stim_HF_*_RUL.bmp', 'Stim_LF_*.bmp', 'Stim_LF_*_RUL.bmp'}, '*', sprintf('%d', index));
destinations = [strrep({'HF_*.bmp', 'HF_*_RUL.bmp'}, '*', sprintf('%d_%s', index, HFname)), strrep({'LF_*.bmp', 'LF_*_RUL.bmp'}, '*', sprintf('%d_%s', index, LFname))];
cellfun(@movefile, sources, destinations);
end
  댓글 수: 4
Guillaume
Guillaume 2015년 1월 9일
Or maybe the problem is that you've remove the @ before renamefile
Susan Lane
Susan Lane 2017년 5월 28일
Very nice answer Guillaume, thank you for the tip! Do you also have a tip on how a .bmp file can be opened and edited? I started learning to code, I am a big Windows user, and I would like to know if there is a way to do this: http://www.coreldraw.com/en/pages/bmp-file/ in code ? Thanks!

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

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by