Extracting Line Profiles from Image

Hi there,

I have a set of data that looks according to the attached picture. Each row corresponds to an absorbance spectra. As of right now, I can manually extract individual absorbance profiles using the "Image Line Profile" feature present in Image Processing. However, I would like to automate this process.

This is the procedure I have so far:
Function ExtractAllTimeSpectra(image,tlist)
   
    String tlist                            //List of times of spectra of interest
    Wave image
    Variable i
    Wave spec0
   
    Make/O/N=2048 spec0
       
    for(i=0;i<ItemsInList(tlist);i=i+1)
        spec0 = image[i][p]
            String  newspec="a_Prof"+num2str(i)
            Duplicate/O spec0, $(newspec)
    endfor
End


My code currently only produces the very last spectra of the series. Also, the tlist portion does not seem to be working.

Any suggestions?

Thanks!
Extracting rows from a matrix should not be done via the ImageLineProfile operation. Instead use:
MatrixOP/O row_i=row(matrixWave,i)

A.G. is right about the best way to extract a row from a matrix. Looking at your code, you'd need to modify it like this for it to run:
Function ExtractAllTimeSpectra(image,tlist)
    Wave image
    String tlist                            //List of times of spectra of interest

    Variable nSpec = ItemsInList(tlist)
    Variable i,rowN
 
    for(i=0;i<nSpec;i=i+1)
        rowN = StringfromList(i,tList)   //you need to pick the row number from tList
        String  newspec="a_Prof"+num2str(rowN)
        MatrixOP/O $newspec = row(matrixWave,i)
    endfor
End

You'd call it with something like ExtractAllTimeSpectra(wave0,"0;2;10;"). I haven't tested the code. I'm not sure if you can name a new wave in MatrixOp like that, you might have to name it something else and then rename or duplicate it.
vmmr5596 wrote:

Function ExtractAllTimeSpectra(image,tlist)
   
    String tlist                            //List of times of spectra of interest
    Wave image
    Variable i
    Wave spec0
   
    Make/O/N=2048 spec0
       
    for(i=0;i<ItemsInList(tlist);i=i+1)
        spec0 = image[i][p]
            String  newspec="a_Prof"+num2str(i)
            Duplicate/O spec0, $(newspec)
    endfor
End


My code currently only produces the very last spectra of the series. Also, the tlist portion does not seem to be working.


Your code works fine for me with no modification when I run the following commands in the command window:
Make/N=(3,2048) testImage=sin(p*q/100)
ExtractAllTimeSpectra(testImage,"1;3;5")

Perhaps make sure that you're formatting the "tlist" string properly?
@ajleenheer it doesn't run properly. If you execute ExtractAllTimeSpectra(testImage,"a;b;d") you get the same result. tList is not being "read", by the code.
sjr51 wrote:
@ajleenheer it doesn't run properly. If you execute ExtractAllTimeSpectra(testImage,"a;b;d") you get the same result. tList is not being "read", by the code.

True, tList isn't doing anything useful at this point other than giving the number of spectra to extract. My point was that the original code does indeed extract unique rows from the 2D array and put them in individual waves. The OP said that only the last spectra was being extracted, which is not the case.

It's running properly now.

Here's how the working version looks:

#pragma rtGlobals=3     // Use modern global access method and strict wave access.

Function ExtractAllTimeSpectra(image,tlist) //For tlist, set of values must be enclosed by " " and separated by ;
   
    String tlist                            //List of times of spectra of interest
    Wave image
    Variable i
    Wave spec0
   
    Make/O/N=2048 spec0             //Wave with 2048 rows b/c of wavelength
       
    for(i=0;i<ItemsInList(tlist);i=i+1)
        spec0 = image[str2num(stringfromlist(i,tlist,";"))][p]
            String  newspec="a_Prof"+num2str(i)
            Duplicate/O spec0, $(newspec)
    endfor
End