function lm = locmax(input_file,threshold); %LOCMAX % % LM = LOCMAX( INOUT_FILE, THRESHOLD) % % Finds local maxima of INPUT_FILE above THRESHOLD. A local maximum % is a voxel which is greater than or equal to all its 6 neighbours, % and strictly greater than at least one of them. % % LM is a matrix with 4 columns. % Col 1: values of local maxima, sorted in descending order. % Cols 2-4: x,y,z voxels of local maxima in C notation i.e. starting at 0. % If x or y step sizes are negative, then their voxel indices are reversed % so that they agree with 'register'. input_file=[deblank(input_file_base(1,:)) extension]; d=fmris_read_image(input_file,1); numslices=d.dim(3) numys=d.dim(2) numxs=d.dim(1) xm1=[1 1:(numxs-1)]; xp1=[2:numxs numxs]; ym1=[1 1:(numys-1)]; yp1=[2:numys numys]; zp1=[2:numslices numslices]; X=squeeze(d.data); X2=X; imat=(1:numxs)'*ones(1,numys)-1; if d.vox(1)<0 imat=numxs-1-imat; end jmat=ones(numxs,1)*(1:numys)-1; if d.vox(2)<0 jmat=numys-1-jmat; end lm=[]; for slice=1:numslices X1=X; X=X2; d=fmris_read_image(input_file,zp1(slice)); X2=d.data; X3=X(xm1,:); X4=X(xp1,:); X5=X(:,ym1); X6=X(:,yp1); islm=(X>=X1)&(X>=X2)&(X>=X3)&(X>=X4)&(X>=X5)&(X>=X6) ... &((X>X1)+(X>X2)+(X>X3)+(X>X4)+(X>X5)+(X>X6)>0) ... &(X>threshold); i=imat(islm); j=jmat(islm); k=(slice-1)*ones(length(i),1); Xlm=X(islm); lm=[lm; [Xlm i j k]]; end lm=flipud(sortrows(lm,1)); % end