Need help programing batch processing

Hello,

So I am doing some image analysis for my research and I need to load and analyze hundreds of photos quickly. I know how to load them with the File loader under the image analysis package, I just can't figure out how to set up a program to go through all of the images quickly and with minimal user effort.

What I am doing is looking at Gaussian burns on a film, and taking a line profile and fitting the Gaussian, here is the code so far:

Function ImageFit(Image2,x_min,x_max,y_min,y_max)
Wave Image2

Variable x_min
Variable x_max
Variable y_min
Variable y_max

ImageTransform rgb2gray Image2

Make/n=2 xTrace={x_min,x_max} ,yTrace={y_min,y_max}
ImageLineProfile /P=-2 /s srcWave=M_RGB2Gray, xWave=xTrace, yWave=yTrace, width=20
Display W_ImageLineProfile

CurveFit W_LineProfile /NTHR=0/TBOX=0 gauss W_ImageLineProfile /W=W_LineProfileStdv /I=1 /D

KillWaves xTrace, yTrace
End


So there are two main things I would like to add....

1: the ability to make it run through a bunch of images without me having to put in each wave name.

2: Output the fit parameters for every fit into a new wave automatically.

Anyone have any ideas?
sleepingawake86 wrote:
So there are two main things I would like to add....

1: the ability to make it run through a bunch of images without me having to put in each wave name.

2: Output the fit parameters for every fit into a new wave automatically.

Anyone have any ideas?


Try out this function:

function doBatchFit(batchstr,x_min,x_max,y_min,y_max)
    string batchstr
    variable x_min,x_max,y_min,y_max
    variable ii,jj=itemsinlist(batchstr)
    make/n=(4,jj)/o fitCoefficients
    for(ii=0;ii<jj;ii+=1)
        wave image2=$stringfromlist(ii,batchstr)
        ImageFit(Image2,x_min,x_max,y_min,y_max)
        wave W_coef
        fitCoefficients[][ii]=W_coef[p]
        setdimlabel 1,ii,$nameofWave(image2),fitCoefficients
    endfor
    edit fitCoefficients.ld
end


You can create a suitable batchstr with a clever call to the 'wavelist' function, e. g. batchstr=wavelist("image*",";","DIMS:2") (see the details of the corresponding help file). Be aware that fitCoefficients is overwritten each time doBatchFit is called.

In this example the fit coefficients are not put into a single wave, but into a 2D wave where each column corresponds to one image file. This is marked by a dimension label.

If you have a lot of image waves and your fits run very stable, then you may want to remove the line 'Display W_ImageLineProfile' from your function, add a /Q flag to th CurveFit call and remove the /D flag.

The function has not been thoroughly tested, but can serve as a starting point that can be adjusted to your needs.

Andreas
awirsing wrote:


If you have a lot of image waves and your fits run very stable, then you may want to remove the line 'Display W_ImageLineProfile' from your function, add a /Q flag to th CurveFit call and remove the /D flag.

Andreas



I would like to have both the fit parameters and the image profiles. Any thoughts on how I can display each line profile in a new graph? I tried this statement in the for-endfor:

Profiles[][ii]=W_ImageLineProfile
setdimlabel 1,ii,$nameofWave(image2),Profiles


it just ended up giving me the same profile for every image as I think each iteration overwrote the previous data. Any help?


and thanks so far!
sleepingawake86 wrote:
I would like to have both the fit parameters and the image profiles. Any thoughts on how I can display each line profile in a new graph?


You have to rename (or duplicate) the wave W_ImageLineProfile that is created by the ImageLineProfile operation, because as you have assumed, it is overwritten by each call to ImageLineProfile.

...
ImageLineProfile /P=-2 /s srcWave=M_RGB2Gray, xWave=xTrace, yWave=yTrace, width=20
string lineProfileStr= nameOfWave(Image2)+"_profile"
duplicate/o W_ImageLineProfile $lineProfileStr
wave lineProfileWave= $lineProfileStr
Display lineProfileWave
CurveFit /Q/NTHR=0/TBOX=0 gauss lineProfileWave /W=W_LineProfileStdv /I=1 /D
...
Quote:
You have to rename (or duplicate) the wave W_ImageLineProfile that is created by the ImageLineProfile operation, because as you have assumed, it is overwritten by each call to ImageLineProfile.


If you are copying W_ImageLineProfile to the Profiles wave then you don't need to duplicate it. However, you must copy the contents of W_ImageLineProfile to Profiles after each call to ImageLineProfile.

Since I have not seen the entire procedure, I'm not sure what the flow is. If you continue to have problems you might want to post the entire procedure as an attachment.