Login  Register

Re: Need to open several images in a folder in file order but not as a stack

Posted by Benoit Lombardot on Mar 27, 2017; 7:22am
URL: http://imagej.273.s1.nabble.com/Need-to-open-several-images-in-a-folder-in-file-order-but-not-as-a-stack-tp5018368p5018375.html

Hi Eglass,

You could use the following line right before your for loop. It will
make sure the file names are in alphanumeric order.

Array.sort(images);

You can find the reference and more on the built-in macro functions
page. <https://imagej.nih.gov/ij/developer/macro/functions.html> I hope
this helps. Good luck with your analysis.

Best,
Benoit

Le 3/24/2017 à 4:43 PM, eglass a écrit :

> Hi All,
>
> Quite new to ImageJ here, but i have been searching and looking for a
> solution to this for days!
>
> This should be quite simple I think but for some reason isnt working.
> I want to open all the image (DICOM) files in a folder in filename order
> (eg: 2cm, 3cm, 4cm, 4.5cm etc.) and then apply ROI's and do some
> calculations and it all gets written to a results table.
>
> As the operator needs to be able to view the ROI's on the images after
> processing to check the positions I need the images to remain open
> individually - so not open them as a stack.
>
> Currently I have:
>
> inputFolder = getDirectory("Choose the input folder!"); //Chose folder
> images are in
> images = getFileList(inputFolder);
>
> for(Pic=0; Pic<images.length; Pic++) {
> inputPath = inputFolder + images[Pic];
> open(inputPath);
>
> ROI_CNR(x1,y1); // my function for calculating CNR with several ROI's this
> spits out a results table in the order of opening
>
> }
>
> My folder contains the DICOM files in the order: 2cm, 3cm, 4cm, 4.5cm, 5cm,
> 6cm, 7cm.  This order is also in ascending time of acquisition and DICOM tag
> of Image number. (all the same file size etc)
>
> BUT following this code it opens the images in a different order of: 7cm,
> 2cm, 3cm, 4.5cm, 4cm, 5cm, 6cm.
> I have repeated this with other image folders (copying and pasting different
> file combinations) and it seems to follow the order in which the image files
> were copied into a folder (i hope that makes sense).
>
>
> Is there anyway of opening the files in filename/numerical order.  OR of
> reordering the results table to be in numerical order?
>
>
> I have also tried batchmode processing and image sequence import (but dont
> want a stack) but it doesnt solve it.  I have also tried a loop, opening
> each file that contains each number in ascending order but this gets stuck
> with the 4.5 file as it gets opened when both 4 and 5 are found in the file
> name...
>
> Hope that makes sense! Any help reaaallllyyyy appreciated!
>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Need-to-open-several-images-in-a-folder-in-file-order-but-not-as-a-stack-tp5018368.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
Benoit Lombardot, PhD
Bio-Image Informatics team leader
Scientific Computing Facility

Max Planck Institute CBG
Pfotenhauer Str. 108, 01307 Dresden
room: 009 (CSBD)
phone: +49 351 210 2544


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