Macro to save snapshot/ outline files based image name after performing particle measurements
Hello Image-Pro Plus programmers: I just recently started to use Image-Pro Plus (version 7) to perform particle analysis on images captured using light microscopy. My goal is to write a macro that reads images from a folder (perhaps up to 100+ images/ folder), perform pre-filtering (e.g. HiPass), threshold, measure 10+ parameters for each particle in the image, save a snapshot of the particle outlines/ numbers, save the outlines file (.scl), record the particle measurements in the Data Recorder, and finally export the measurement data to a text file for analysis in R. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
I have used the macro recorder, Data Collector and the Batch Process plug-in to get most of the way there (see code below). The issue that I have is how to write a for loop (or other coding method) that saves the snapshot image and outlines file as the image name including the addition of “_outlines” to the name: e.g. Image1_outlines.scl and Image1_outlines.tif. Note the image names are more complex; I simplified them for the example.
Note the lines for saving the image/ outline files are hard-coded to save only a single name, not one that assigns a name that is based on the actual image/ file name.
ret = IpSCalSelect("10x_0.3NA_LU_
ret = IpFltHiPass(3, 10, 1) ‘ applies an initial hi-pass filter to image
ret = IpBlbCount() ‘performs particle size/ count measurements
ret = IpBlbUpdate(0) ‘
ret = IpDcSet(DC_AUTO, 0) ‘Data Collector
ret = IpDcUpdate(DC_FETCH) ’collects data using Data Collector
ret =
IpBlbSaveOutline("C:\Documents And Settings\jhietpas\Desktop\
ret = IpSnap() ‘snaps an image of the particle outlines/ numbers
ret = IpWsSaveAs("C:\Documents And
Settings\jhietpas\Desktop \Images\Processed\
ret = IpDocClose() ‘ closes the image after analysis
Thanks very much for any information/ help you can provide,
-Jack
Comments
Hi Kevin- Thank you very much for your help, I really appreciate it! Sorry for the delay in getting back to you. I have incorporated your code into mine (below). It is working very well, the image and the outline files are being properly labeled and saved! The only question that I have is that I have to select each image individually from the directory. Is there a way to only select one of the images and have the code use all the images in the selected directory? I have been trying to figure this out myself using parts of the Batch_Process script (Yuri's suggestion)... but failing miserably. Do you have any suggestions? Thanks again for your help.
-jh
'Dim Firstfile As String
'Dim Formattype As String
'Firstfile = "C:\Documents and Settings\jhietpas\Desktop\Images\Image1.TIF"
'Formattype = "TIF"
'ret = IpWsLoad(Firstfile, Formattype)
Dim fileName As String, dirName As String
Dim extension As String, baseName As String
Dim name_Script As String, name_Image As String
Dim delim As Integer
fileName = GetFilePath(, , , , 0)
If fileName = "" Then Exit Sub
' Chop up the file name using searches for "." and "\" delimiters
delim = InStrRev(fileName, ".")
extension = Right(fileName, Len(fileName)- delim)
baseName = Left(fileName, delim - 1)
delim = InStrRev(fileName, "\")
dirName = Left(fileName, delim)
' Build new file names for later use
name_Script = baseName + "_outlines" + "." + "scl"
name_Image = baseName + "_outlines" + "." + extension
' Output results
'Debug.Print "fileName: "; vbTab; fileName
'Debug.Print "extension: "; vbTab; extension
' Debug.Print "baseName: "; vbTab; baseName
' Debug.Print "dirName: "; vbTab; dirName
' Debug.Print "name_Script: "; vbTab; name_Script
' Debug.Print "name_Image: "; vbTab; name_Image
' Debug.Print ""
'ret = IpSCalSelect("4x_0.2_NA_Nikon")
'ret = IpSCalSelect("10x_0.45_NA_APO_Nikon")
ret = IpSCalSelect("20x_0.75_NA_APO_Nikon")
ret = IpFltHiPass(3, 10, 1)
ret = IpBlbSetAttr(BLOB_CLEANBORDER,1)
ret = IpBlbCount()
ret = IpBlbUpdate(0)
ret = IpDcShow(3)
ret = IpDcSet(DC_AUTO, 0)
ret = IpDcUpdate(DC_FETCH)
ret = IpBlbSaveOutline(name_Script)
ret = IpSnap()
ret = IpWsSaveAs(name_Image,"TIF")
ret = IpDocClose()