Better way to read number of images in a TIFF stack

I discovered the code to read the number of images in a stack. Thank you!

Could we have a way to do this that avoids the explicit need to create and then kill a temporary directory for the tags that we do not want to store. Two options (using the C or perhaps better the RTIO flag) come to mind.

ImageLoad/C=0/T=TIFF/RTIO/P=imgPath fname
print V_numImages

ImageLoad/C=-1/T=TIFF/RTIO=0/P=imgPath fname
print V_numImages

 

Oops! Sorry. The C=0 approach is not viable since stack numbers are zero based. In any case, the RTIO=0 approach is clearer to mean read the tags only but do not store the tags.

Another update here. The correct method to determine the number of images in a stack appears to be with the code change below. Note the difference in C=0 rather than C=-1.

// Get the number of images in a TIFF stack
NewDataFolder/O/S tmp
ImageLoad/C=-1/T=TIFF/RTIO   // as listed in the Igor Help
Print V_numImages
KillDataFolder :

// Get the number of images in a TIFF stack
NewDataFolder/O/S tmp
ImageLoad/C=0/T=TIFF/RTIO    // C=0 is the correct approach
Print V_numImages
KillDataFolder :

The modification that would be useful to just determine the number of stacks without reading the tags is this.

// Get the number of images in a TIFF stack
ImageLoad/C=0/T=TIFF/RTIO=0
Print V_numImages

 

Yes, I found that code as well, especially since I am also interested in this possibility ...

/RTIO=0   // reads base TIFF tags but does not store them, useful to get v_numImages from stacks
/RTIO or /RTIO=1     // reads base TIFF tags and stores them
/RTIO=2   // reads base TIFF tags, also reads and stores all additional TIFF tags

My image files have useful meta-information stored either in the additional (non-base) TIFF tags or in a non-tag field. I have some testing to do exactly with the code that you reference.

My explorations are done. I again note a mistake in the help files.

// Get the number of images in a TIFF stack
NewDataFolder/O/S tmp
ImageLoad/C=0/T=TIFF/RTIO    // C=0 is the correct approach
Print V_numImages
KillDataFolder :

I also again ask for an easier way to just read the number of pages in a multipage file ...

ImageLoad/C=0/T=TIFF/RTIO=0    // sets V_numImages without reading the tags

Finally, I learned that all parts of the multipage TIFF tags are being read fully. My TIFF images are not as complex as I thought (the TIFFTagReader code was not working properly for multi-page images and I correspondingly misread the results compared to those from using the /RAT tag). My mistake ... /RTIO=2 is not needed.