RnkPic21() ! Measures correlation Pearson, Rank & Manders, Hcoef ! doicq=1 do the ICQ ! domand=1 do the MOC ! zpp=1 delete images at end of prog dF1Pic, Mf1pic, c1his, F1mappic also those from F2Pic ! correct Hcoef - for when ROI is not the whole image ! includes ranking method ! 8 bit data ! Returns : Rank-fast (rs) (1-6...), Rank-Pearson-calc (rp), Pearson (r), Manders (Mnd), Li (icq) ! Rank-fast bypassed Mnd=99 rp=98 r=97 icq=96 ! NO Print Option - turned off ! PICS ! need 3 input pics, F1Pic F2Pic MPic; ! 2 intensities & analysis Mask ! C1His - histogram ! F1MapPic- mapping table for ranking ! Mf1Pic - mapped pic ! same for F2 image set ! Variables ! Npixels - number used in analysis ! NNpixels- number of pixels not used in anal ! zppics - keep all images etc if zppics=0 ! need to add in mask to calculations if set(doMand)=0 doMand=0; ! bypass Manders if set(doICQ)=0 doICQ=0; ! bypass ICQ (Li) local Npi,NNp,mea,nx,ny, max,min ! local xod, yod, rod, r2o ! local xevn, yevn, revn, r2evn if set(zppics)=0 zppics=1; ! zap pics bse=22; ! base for lib nextfree ! find data siz from Mask picture ver=0;pic MPic siz; sur MPic full; ver=1 Npixels=mea*nx*ny;; ! number of pixels to be analysed NNpixels=nx*ny-Npixels; ! number of pixels outside mask - not used ! typ Npixels,NNpixels ! dis F1Pic to dis:2 ver=0;sur F2Pic; ver=1 if max >min dis F2Pic to dis:3 ! min=0 max=1 dis MPic to dis:4 pre ! uns for; ! wait ! Mask Pics cal :F1Pic*:MPic tit F1Pic text ' F1Pic Masked' cal :F2Pic*:MPic tit F1Pic text ' F2Pic Masked' ! dis F1Pic to dis:2 ver=0;sur F2Pic; ver=1 ! if max>min dis F2Pic to dis:3 !uns for;! wait ! RANK data, by intensity, mapping table ! - highest rank most intense, equal given average rank ! F1Pic ver=0 lib nextfree; C1His=nxt; min=0 max=255 his F1Pic to C1His pre p 0=p(0)-NNpixels;! dis C1His to dis:2 lib nextfree; F1mapPic=nxt; cre F1mapPic siz 256,1 val 0 fp; ori left; tit tex 'C1 map pic' ndone=0; ! dis C1His for n=255,0,-1 sel C1His; vn=p(n); ! number intensity n if vn=0 next n sel F1mapPic Avrank=(Npixels*2-ndone*2-vn)/2+.5; ! average rank p n=Avrank; ! insert average rank ! typ n,' ',Avrank,' ',vn ndone=ndone+vn loop ! dis F1mapPic to dis:3 lib nextfree; Mf1Pic=nxt map from F1Pic to Mf1Pic fp with F1mapPic range 0,255; tit Mf1Pic add tex ' Ranked X ' ! dis Mf1Pic to dis:2 ! F2Pic lib nextfree; C2His=nxt; min=0 max=255 his F2Pic to C2His pre p 0=p(0)-NNpixels; ! dis C2His to dis:2 lib nextfree; F2mapPic=nxt; cre F2mapPic siz 256,1 val 0 fp; ori left; tit tex 'C2 map pic' ndone=0; ! dis C2His for n=255,0,-1 sel C2His; vn=p(n); ! number intensity n if vn=0 next n sel F2mapPic Avrank=(Npixels*2-ndone*2-vn)/2+.5; ! average rank p n=Avrank; ! insert average rank ! typ n,' ',Avrank,' ',vn ndone=ndone+vn loop ! dis F2mapPic to dis:3 lib nextfree; Mf2Pic=nxt map from F2Pic to Mf2Pic fp with F2mapPic range 0,255; tit Mf2Pic add tex ' Ranked X ' ! dis Mf2Pic to dis:2 jump nquick ! Cal Spearman Rank- quick method ! typ 'Rank-simple' ! sum the squarred differences in rank ! mark on display lib nextfree; RPic=nxt cal :Mf1Pic-:Mf2Pic to RPic fp; ! dis RPic to dis:2 cal :RPic^2; ! dis RPic to dis:3 sur RPic full; pic RPic siz D=mea*nx*ny;! typ D rs=1-6*D/(Npixels^3-Npixels) !typ ' Spearman Fast rs ',rs; ! typ nquick: ! Rank Correlation Coef Pic method 2 -Pearson ! typ 'Pearson-Rank' ! dis Mf1pic; ! dis Mf2pic pic Mf2Pic siz ver=0 ! find mean - can derive from npi for ranked data ! sur Mf1Pic full ! m1=mea*nx*ny/Npixels m1=(npi+1)/2 ! sur Mf2Pic full ! m2=mea*nx*ny/Npixels m2=m1 ! typ 'mean 2 ',m2,(npi+1)/2 ! top of equation cal (:Mf1Pic-m1) to 999 fp;! 999 to dis:1 cal (:Mf2Pic-m2) to 998 fp;! 998 to dis:2 cal :999*:998 to 997;cal :997*:MPic sur 997 full;ver=1; Em=mea*nx*ny; ! typ Em if zpp=1 del 997,999 ! underside of eq pic F1Pic siz cal (:Mf1Pic-m1)^2 to 996 fp cal :996*:MPic ver=0;sur 996 full; E1=root(mea*nx*ny); ! typ 'E1 ',E1 cal (:Mf2Pic-m2)^2 to 995 fp cal :995*:MPic ver=0; sur 995 full; E2=root(mea*nx*ny); ! typ 'E2 ',E2 if E1=0 | E2=0 end rp= em/(E1*E2) if zpp=1 del 995,996 ! Pearson Correlation Coef Pic - unranked data ! typ 'Pearson from pics' ! calculated from images ! Requires that F1Pic and F2Pic are already masked ! Npixels - number of pixels to be analysed - from MPic pic MPic siz; sur MPic full Npixels=mea*nx*ny ! dis F1Pic; ! dis F2Pic pic F2Pic siz ver=0 sur F1Pic full; m1=mea*nx*ny/Npixels; ! typ 'mean 1 ',m1 sur F2Pic full; m2=mea*nx*ny/Npixels; ! typ 'mean 2 ',m2 ! top of equation cal (:F1Pic-m1) to 999 fp;! 999 to dis:1 cal (:F2Pic-m2) to 998 fp; ! 998 to dis:2 cal :999*:998 to 997;cal :997*:MPic sur 997 full;ver=1; Em=mea*nx*ny; ! typ Em ! underside of eq pic F1Pic siz cal (:F1Pic-m1)^2 to 996 fp cal :996*:MPic ver=0;sur 996 full; E1=root(mea*nx*ny); ! typ 'E1 ',E1 cal (:F2Pic-m2)^2 to 995 fp cal :995*:MPic ver=0; sur 995 full; E2=root(mea*nx*ny); ! typ 'E2 ',E2 if E1=0 | E2=0 end r= em/(E1*E2) if zpp=1 del 995,996 ! Li - ICQ method uses data from Pearson if doicq=0 jump nicq typ 'ICQ ',m1,m2 cal :F1Pic>m1 to 999 byt cal :F2Pic>m2 to 998 byt cal :999=:998 to 997 int cal :997*:Mpic; ! 997 min=0 max=1 dis 999 to dis:2 min=0 max=1 dis 998 to dis:3 min=0 max=1 dis 997 to dis:4 pre uns for; wait min=-10 max=10 his 997 to 996 pre min=-10 max=10 dis 996 to dis:2 pre uns for; wait !typ ' ICQ histrogram' !for n=9,12;!v=p(n); !typ n,v;!loo v1=p(11) v2=p(10) typ 'icq v1 ',v1,' v2 ',v2,' Npixels ',npixels icq=v1/Npixels-0.5 typ 'icq = ',v1/Npixels-0.5,(v1/(v1+v2))-.5 !typ 'n pixels ',npix,v1,v1+v2 sur 997 full typ 'icq from mea ',mea-.5 typ nicq: ! Manders Correlation Coef Pic - unranked data if doMand=0 jump nMnders ! typ 'Manders correlation from pics' ! calculated from images ! Requires that F1Pic and F2Pic are already masked ! Npixels - number of pixels to be analysed - from MPic pic MPic siz; sur MPic full Npixels=mea*nx*ny ! dis F1Pic; ! dis F2Pic pic F2Pic siz ver=0 ! top of equation cal :F1Pic*:F2Pic to 997 fp;cal :997*:MPic sur 997 full;ver=1; Em=mea*nx*ny; ! typ Em ! underside of eq pic F1Pic siz cal (:F1Pic)^2 to 996 fp cal :996*:MPic ver=0;sur 996 full; E1=root(mea*nx*ny); ! typ 'E1 ',E1 E11=mea*nx*ny cal (:F2Pic)^2 to 995 fp cal :995*:MPic ver=0; sur 995 full; E2=root(mea*nx*ny); ! typ 'E2 ',E2 E12=mea*nx*ny if E1=0 | E2=0 end Mnd= Em/(E1*E2) Md1=Em/root(E11*E12) ! typ Em,E11,E12,root(E11*E12) nMnders: ! Hp Coef Pic - unranked data trap=25 if doHp=0 jump nHp if rc=25 jump nHp ! typ 'Manders correlation from pics' ! calculated from images ! Requires that F1Pic and F2Pic are already masked ! Npixels - number of pixels to be analysed - from MPic pic MPic siz; sur MPic full Npixels=mea*nx*ny ! dis F1Pic; ! dis F2Pic pic F2Pic siz ver=0 ! top of equation - same as MOC cal :F1Pic*:F2Pic to 997 fp;cal :997*:MPic sur 997 full;ver=1; Em=mea*nx*ny; ! typ Em ! underside of eq pic F1Pic siz cal :F1Pic*:Mpic to 996 ver=0;sur 996 full; E1=mea*nx*ny; ! typ 'E1 ',E1 cal :F2Pic*:MPic to 995 ver=0; sur 995 full; E2=mea*nx*ny; ! typ 'E2 ',E2 if E1=0 | E2=0 end Hp= Em/(E1*E2) Hcoef=npix*Hp ! typ Em,E11,E12,root(E11*E12) nHp: ! final output - Pictures ! exa F1Pic ! typ rou(r*1000)/1000,' ',rou(rs*1000)/1000,' ',rou(rp*1000)/1000 ! Print OFF ! typ rou(r*1000)/1000,' ',rou(rp*1000)/1000 ! Tidy Up if zppics=0 jump nozap del F1Pic; del Mf1pic; del c1his; del F1mappic del F2Pic; del Mf2pic; del c2his; del F2mappic ! del RPic nozap: end ***********************************************************