Hi All
I was hoping this would be a quick job but I am stuck. I have a directory full of DICOM images and matching bitmap thumbnails, both named with a timestamp by the capture software. I'd like to rename all the DICOM files and matching BMP's with the string contained in header 0010,0010. I can get the string, but don't seem to be able to rename the files with it. Any help appreciated, Mike macro: ------------------------------------ setBatchMode(true); open(); path = File.directory(); tag = "0010,0010"; close(); function getTag(tag) { info = getImageInfo(); index1 = indexOf(info, tag); if (index1==-1) return ""; index1 = indexOf(info, ":", index1); if (index1==-1) return ""; index2 = indexOf(info, "\n", index1); value = substring(info, index1+1, index2); return value; } list = getFileList(path); showStatus("Getting File List..."); for (i=0; i<list.length; i++){ if(endsWith(list[i], '.dcm')){ open(list[i]); newtitle = replace(getTag(tag),'^','_'); newtitle = replace(newtitle, ' ', '_'); newtitle = substring(newtitle, 1, lengthOf(newtitle)-1); print(newtitle); close(); File.rename(list[i], path+newtitle+".dcm"); thumbnail = replace(list[i], ".dcm", ".bmp"); File.rename(thumbnail, path+newtitle+".bmp"); } } ---------------------------------- |
According to the reference
"The file or directory must be in the user's home directory, the ImageJ directory or the temp directory." You can just put the files under any directory named ImageJ and it will work. There is also now an exec() macro function that will execute system commands. I haven't tried it, but you may be able to use that instead. Justin On 9/26/07, Michael Doube <[hidden email]> wrote: > Hi All > > I was hoping this would be a quick job but I am stuck. I have a > directory full of DICOM images and matching bitmap thumbnails, both > named with a timestamp by the capture software. I'd like to rename all > the DICOM files and matching BMP's with the string contained in header > 0010,0010. I can get the string, but don't seem to be able to rename > the files with it. Any help appreciated, > > Mike > > macro: > ------------------------------------ > setBatchMode(true); > open(); > path = File.directory(); > tag = "0010,0010"; > close(); > > function getTag(tag) { > info = getImageInfo(); > index1 = indexOf(info, tag); > if (index1==-1) return ""; > index1 = indexOf(info, ":", index1); > if (index1==-1) return ""; > index2 = indexOf(info, "\n", index1); > value = substring(info, index1+1, index2); > return value; > } > > list = getFileList(path); > showStatus("Getting File List..."); > for (i=0; i<list.length; i++){ > if(endsWith(list[i], '.dcm')){ > open(list[i]); > newtitle = replace(getTag(tag),'^','_'); > newtitle = replace(newtitle, ' ', '_'); > newtitle = substring(newtitle, 1, lengthOf(newtitle)-1); > print(newtitle); > close(); > File.rename(list[i], path+newtitle+".dcm"); > thumbnail = replace(list[i], ".dcm", ".bmp"); > File.rename(thumbnail, path+newtitle+".bmp"); > } > } > ---------------------------------- > |
In reply to this post by Michael Doube-2
Hi
irfanview has a batch rename feature andcan handle dicom http://www.irfanview.com/ ..might do the trick Joe O'Brien, City Hospital, Bham -----Original Message----- From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of Justin McGrath Sent: 26 September 2007 15.19 To: [hidden email] Subject: Re: Batch rename DICOM files with header info According to the reference "The file or directory must be in the user's home directory, the ImageJ directory or the temp directory." You can just put the files under any directory named ImageJ and it will work. There is also now an exec() macro function that will execute system commands. I haven't tried it, but you may be able to use that instead. Justin On 9/26/07, Michael Doube <[hidden email]> wrote: > Hi All > > I was hoping this would be a quick job but I am stuck. I have a > directory full of DICOM images and matching bitmap thumbnails, both > named with a timestamp by the capture software. I'd like to rename > all the DICOM files and matching BMP's with the string contained in > header 0010,0010. I can get the string, but don't seem to be able to > rename the files with it. Any help appreciated, > > Mike > > macro: > ------------------------------------ > setBatchMode(true); > open(); > path = File.directory(); > tag = "0010,0010"; > close(); > > function getTag(tag) { > info = getImageInfo(); > index1 = indexOf(info, tag); > if (index1==-1) return ""; > index1 = indexOf(info, ":", index1); > if (index1==-1) return ""; > index2 = indexOf(info, "\n", index1); > value = substring(info, index1+1, index2); > return value; > } > > list = getFileList(path); > showStatus("Getting File List..."); > for (i=0; i<list.length; i++){ > if(endsWith(list[i], '.dcm')){ > open(list[i]); > newtitle = replace(getTag(tag),'^','_'); > newtitle = replace(newtitle, ' ', '_'); > newtitle = substring(newtitle, 1, lengthOf(newtitle)-1); > print(newtitle); > close(); > File.rename(list[i], path+newtitle+".dcm"); > thumbnail = replace(list[i], ".dcm", ".bmp"); > File.rename(thumbnail, path+newtitle+".bmp"); > } > } > ---------------------------------- > |
Thanks for your help everyone,
I sorted the problem, which was me not specifying the full path of the file to rename. Wooops. It works pretty well, and handles repeated tags in successive files so files don't get over-written. If anyone's interested, it's here: http://doube.org/macros.html#dcmrenamer Mike O'Brien.Joseph wrote: > Hi > irfanview has a batch rename feature andcan handle dicom > http://www.irfanview.com/ > ..might do the trick > > Joe O'Brien, City Hospital, Bham > > > > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of > Justin McGrath > Sent: 26 September 2007 15.19 > To: [hidden email] > Subject: Re: Batch rename DICOM files with header info > > > According to the reference > "The file or directory must be in the user's home directory, the ImageJ > directory or the temp directory." > > You can just put the files under any directory named ImageJ and it will > work. There is also now an exec() macro function that will execute > system commands. I haven't tried it, but you may be able to use that > instead. > > Justin > > On 9/26/07, Michael Doube <[hidden email]> wrote: > >> Hi All >> >> I was hoping this would be a quick job but I am stuck. I have a >> directory full of DICOM images and matching bitmap thumbnails, both >> named with a timestamp by the capture software. I'd like to rename >> all the DICOM files and matching BMP's with the string contained in >> header 0010,0010. I can get the string, but don't seem to be able to >> rename the files with it. Any help appreciated, >> >> Mike >> >> macro: >> ------------------------------------ >> setBatchMode(true); >> open(); >> path = File.directory(); >> tag = "0010,0010"; >> close(); >> >> function getTag(tag) { >> info = getImageInfo(); >> index1 = indexOf(info, tag); >> if (index1==-1) return ""; >> index1 = indexOf(info, ":", index1); >> if (index1==-1) return ""; >> index2 = indexOf(info, "\n", index1); >> value = substring(info, index1+1, index2); >> return value; >> } >> >> list = getFileList(path); >> showStatus("Getting File List..."); >> for (i=0; i<list.length; i++){ >> if(endsWith(list[i], '.dcm')){ >> open(list[i]); >> newtitle = replace(getTag(tag),'^','_'); >> newtitle = replace(newtitle, ' ', '_'); >> newtitle = substring(newtitle, 1, lengthOf(newtitle)-1); >> print(newtitle); >> close(); >> File.rename(list[i], path+newtitle+".dcm"); >> thumbnail = replace(list[i], ".dcm", ".bmp"); >> File.rename(thumbnail, path+newtitle+".bmp"); >> } >> } >> ---------------------------------- >> >> -- Michael Doube BPhil BVSc MRCVS PhD Student Dental Institute Queen Mary, University of London New Rd London E1 1BB United Kingdom Phone +44 (0)20 7377 7000 ext 2681 |
Free forum by Nabble | Edit this page |