2d wave normalization every row to its maximum

Dear all

I am new to igor, and struggling to make normalization of 2d wave every row to its maximum. I used a function previously posted (http://www.igorexchange.com/node/4482);

Function NormTo1(inwave)
Wave inwave
Variable normval
normval = wavemin(inwave)
inwave -= normval
normval = wavemax(inwave)
inwave /= normval
End

but this makes normalize to the maximum of whole 2d data. Is there any idea to normalize every row to its maximum?

Thanks

How about:

Function NormTo1(inwave)
    Wave inwave
     // transpose the 2D wave and find maximum values of columns (rows)
    MatrixOp/O/FREE tempMat = maxcols(inWave^t)
    // transpose it back to a 1d wave of max values from each row of inwave
    MatrixTranspose tempMat
    inwave[][] -= tempMat[p]
    inwave[][] /= tempMat[p]
End


You might need Igor7 to do maxcols
If you use Igor 7 you can make use of the MatrixOP scale operations. Execute the following from the command line:

Make/O/N=(2,3) w2d = round(abs(enoise(10))) // make some data
MatrixOP/O w2d_trans = w2d^t // make a transpose
MatrixOP/O w2d_nor = scaleCols(w2d_trans, rec(MaxCols(w2d_trans)^t))^t  // scale to column maximum and transpose back


Unfortunately there is no MaxRows option, so you need the transpose. Note the reciprocal term, rec(), which you need in this situation.
This should do it. It's a copy paste from one of my procedures, and I still use Igor 6.

    //  Normalizes the image by setting the maxium value for each horizontal line equal to 1

        Wave DataWave
    Variable YSize=DimSize(DataWave, 1)

        Variable i=0, Scaling=0
    for (i=0; i<YSize; i=i+1)
        Duplicate/FREE/O/R=[][i] DataWave TempXWave
        Scaling=1/WaveMax(TempXWave)
        if (NumType(Scaling)!=0)
            Scaling=1              
        endif
        FastOP TempXWave=(Scaling)*TempXWave
        ImageTransform /D=TempXWave /G=(i) putCol DataWave
    endfor

In reply to by olelytken

Olelytken, I just got checked your comment, since long time. I put my matrix, where I want normalize every row (not column!), instead of your DataWave, but it does not work. Could you give me some comments if still available? Much appreciated.

normalize_test.pxp (19.07 KB)

This is a fully standalone function and should work. If it doesn't work when you replace RawDataWave with your wave it might be because your wave contains NaNs.

EDIT: I just tested it on your data and it works fine.

Function Test()
//    Test Function

    Make/O/N=(100,100) RawDataWave=p^2*q^0.5
    Duplicate/O RawDataWave, DataWave
   
    //    Flip rows and columns if needed. I always get them confused
    //MatrixTranspose DataWave

    Variable YSize=DimSize(DataWave, 1)
    Variable i=0, Scaling=0
   
    for (i=0; i<YSize; i=i+1)
        Duplicate/FREE/O/R=[][i] DataWave TempXWave
        Scaling=1/WaveMax(TempXWave)
        if (NumType(Scaling)!=0)
            Scaling=1              
        endif
     
        FastOP TempXWave=(Scaling)*TempXWave
        ImageTransform /D=TempXWave /G=(i) putCol DataWave
    endfor
   
    //    Flip rows and columns if needed. I always get them confused
    //MatrixTranspose DataWave
   
    DoWindow /K RawDataWindow
    Display /W=(5, 40, 370, 340) /K=1 /N=RawDataWindow
    AppendImage/W=RawDataWindow RawDataWave
    ModifyImage/W=RawDataWindow '' ctab= {*,*,ColdWarm,0}, ctabAutoscale=1, lookup= $""
   
    DoWindow /K DataWindow
    Display /W=(405, 40, 770, 340) /K=1 /N=DataWindow
    AppendImage/W=DataWindow DataWave
    ModifyImage/W=DataWindow '' ctab= {*,*,ColdWarm,0}, ctabAutoscale=1, lookup= $""
end

There seems to be some problem when code is copied and pasted from the forum page into the IP6 procedure window.

When compiling the "Function compilation error" seems to complain about white space in front of lines of code. This does not occur on IP8 (IP7 not tested).

In reply to by ChrLie

Quote:
There seems to be some problem when code is copied and pasted from the forum page into the IP6 procedure window.

Copy/pasting the Test function above from Microsoft Edge into Igor6, Igor7 and Igor8 gives normal spaces (0x20).

Copy/pasting the Test function above from Safari into Igor7 and Igor8 gives normal spaces (0x20).

Copy/pasting the Test function above from Safari into Igor6 gives non-breaking spaces (0xCA in MacRoman text encoding). I don't know why. Igor does not expect non-breaking spaces there and so throws a compiler error. The only solution is to replace the non-breaking spaces with normal spaces, or upgrade to Igor8.

I don't know why copying code in forum topics gives spaces instead of tabs.

 

 

In reply to by hrodstein

hrodstein wrote:

The only solution is to replace the non-breaking spaces with normal spaces, or upgrade to Igor8.

 

On Mac, copying from Firefox (61.0.1) into IP6 also works.

Still, for various reason I highly recommend upgrading to Igor 8 anyway!

On window, copying from IE11 to IP6.22 does not work..

It is not working on my system, but I found the reason anyway. :) Thank you guys.

In reply to by ChrLie

ChrLie wrote:

Unfortunately there is no MaxRows option...

I just saw that this exists now in IP8!

Thanks, A.G.!