Macro to open DICOM stack, rename stack, save stack

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro to open DICOM stack, rename stack, save stack

yxnsn
Hi all, I'm a beginner at programming and would like some help with my macro code. 

I'm trying to 1) Import a selection of various folders containing DICOM images as individual image sequences; 2) Rename the respective individual folders using info extracted from images' DICOM header; 3) Save the DICOM images as a .tiff image sequence in their respective renamed folders.

The code should cycle through one folder at a time. 

Dir = getDirectory("Choose a directory "); 
list = getFileList(Dir); 
setBatchMode(true); 
for (i=0; i<list.length;i++) { 
run("Image Sequence...", "open=["+Dir+list[i]+"] sort"); 
seriesName = getInfo("0008,103E"); //This is a plugin that extracts info from DICOM header 
File.makeDirectory(Dir+File.separator+seriesName); 
run("Image Sequence...", "format=TIFF save=[Dir+list[i],Dir+File.separator+seriesName]") 


I believe my problem is in the "save" part, I'm not sure what the right code should be. Also, I’d love to learn if I could’ve implemented this code in a more simple way. 
 

Thanks for the help!
Reply | Threaded
Open this post in threaded view
|

Re: Macro to open DICOM stack, rename stack, save stack

Michael Schmid
Hi Anonymous,

there is a subtle difference between the opening and saving commands:
  run("Image Sequence...", ...);  for opening
  run("Image Sequence... ", ...); for saving - mind the blank!

Best, use Plugins>Macros>Record to determine the correct command.

BTW, the same difference, with and without a blank, can be also found for other commands, e.g.:
AVI... opening/writing avi files,
Text Image... opening/writing text images,
XY Coordinates... opening/writing selection coordinates,
LUT... opening/writing LUTs,
Process>Math>Macro vs. Process>Batch>Macro,
Edit Options>Reset vs. Plugins>Utilities>Reset,
Image>Transform>Rotate vs. ImageEdit>Selection>Rotate
Image>Scale vs. Edit>Selection>Scale
Process>Math>Set vs. Image>Zoom>Set

Michael
________________________________________________________________
On Jun 16, 2015, at 22:25, yxnsn wrote:

> Hi all, I'm a beginner at programming and would like some help with my macro code.
>
> I'm trying to 1) Import a selection of various folders containing DICOM images as individual image sequences; 2) Rename the respective individual folders using info extracted from images' DICOM header; 3) Save the DICOM images as a .tiff image sequence in their respective renamed folders.
>
> The code should cycle through one folder at a time.
>
> Dir = getDirectory("Choose a directory ");
> list = getFileList(Dir);
> setBatchMode(true);
> for (i=0; i<list.length;i++) {
> run("Image Sequence...", "open=["+Dir+list[i]+"] sort");
> seriesName = getInfo("0008,103E"); //This is a plugin that extracts info from DICOM header
> File.makeDirectory(Dir+File.separator+seriesName);
> run("Image Sequence...", "format=TIFF save=[Dir+list[i],Dir+File.separator+seriesName]")
> }
>
> I believe my problem is in the "save" part, I'm not sure what the right code should be. Also, I’d love to learn if I could’ve implemented this code in a more simple way.
>
>
> Thanks for the help!

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html