2d wave normalization every row to its maximum
greenriver
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
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
February 21, 2018 at 10:43 pm - Permalink
MatrixOP
scale
operations. Execute the following from the command line: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.
February 21, 2018 at 11:04 pm - Permalink
February 21, 2018 at 11:49 pm - Permalink
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
February 22, 2018 at 02:29 am - Permalink
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.
July 18, 2018 at 11:27 pm - Permalink
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.
// 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
July 19, 2018 at 11:59 pm - Permalink
In reply to This is a fully standalone… by olelytken
Strangely, your function does not execute in my igor version 6.22. I'm trying to find the problem.
Thank you for your time and efforts. :)
July 23, 2018 at 09:22 pm - Permalink
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).
July 24, 2018 at 05:53 am - Permalink
In reply to There seems to be some… by ChrLie
No problem of this kind on Windows 10, copying from IE11 into procedure window on IP6.37. No compile error and the function ran without error as well.
July 24, 2018 at 06:11 am - Permalink
In reply to There seems to be some… by ChrLie
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.
July 24, 2018 at 07:03 am - Permalink
In reply to Quote: There seems to be… by hrodstein
On Mac, copying from Firefox (61.0.1) into IP6 also works.
Still, for various reason I highly recommend upgrading to Igor 8 anyway!
July 24, 2018 at 11:31 pm - Permalink
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.
July 31, 2018 at 09:41 pm - Permalink
In reply to by ChrLie
I just saw that this exists now in IP8!
Thanks, A.G.!
July 31, 2018 at 11:12 pm - Permalink