Home > fmri > utils > vanhorn > FindLocalMax.m

FindLocalMax

PURPOSE ^

Function to Return Image Volume Local Maxima

SYNOPSIS ^

function LocalMax=FindLocalMax(image, XDIM, YDIM, ZDIM, Sx, Sy, Sz, Resels, Thresh)

DESCRIPTION ^

 Function to Return Image Volume Local Maxima
 That are, on average, Separated by One FWHM of the Image
 Autocorrelation Function.  Coordinates Given
 in Voxel Units.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Function to Return Image Volume Local Maxima
0002 % That are, on average, Separated by One FWHM of the Image
0003 % Autocorrelation Function.  Coordinates Given
0004 % in Voxel Units.
0005 
0006 % LocalMax = [Voxel Value, X location, Y location, Z location];
0007 
0008 function LocalMax=FindLocalMax(image, XDIM, YDIM, ZDIM, Sx, Sy, Sz, Resels, Thresh)
0009      %fid=fopen(image,'r');
0010      %X=fread(fid,'float32');
0011      %fclose(fid);
0012      
0013      %X=reshape(image,XDIM,YDIM,ZDIM);
0014 
0015      LocalMax=[];
0016 
0017      LMax=0.;
0018      tmp=zeros(1,4);
0019      for x=ceil(Sx/2):ceil(Sx):XDIM-ceil(Sx/2),
0020      for y=ceil(Sy/2):ceil(Sy):YDIM-ceil(Sy/2),
0021          for z=ceil(Sz/2):ceil(Sz):ZDIM-ceil(Sz/2),
0022             
0023          for i=(-ceil(Sx/2)+1):(ceil(Sx/2)-1),
0024              for j=(-ceil(Sy/2)+1):(ceil(Sy/2)-1),
0025              for k=(-ceil(Sz/2)+1):(ceil(Sz/2)-1),
0026                                   
0027                  Index=((z+k-1)*YDIM+(y+j))*XDIM+(x+i);
0028                  if( (image(Index)>=Thresh) & (image(Index)>LMax) )
0029                                LMax=image(Index);
0030                                tmp=[LMax, (x+i), (y+j), (z+k), Index];
0031                              end
0032 
0033                          end
0034                      end
0035                  end
0036 
0037              if(sum(tmp(2:4))>0)
0038                     LocalMax=[LocalMax;tmp];
0039                  end
0040 
0041                  LMax=0.;
0042                  tmp=[0 0 0 0];
0043 
0044               end
0045           end
0046       end
0047 
0048 % Sort in Descending Order of the First Column
0049 [a, I]=sort(-LocalMax(:,1));
0050 LocalMax=LocalMax(I,:);
0051 
0052 
0053 return;
0054 
0055

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003