Home > NoiseTools > nt_morton.m

nt_morton

PURPOSE ^

[iMorton,toMorton]=nt_morton(nrows,ncols) - indices for Morton scan of image

SYNOPSIS ^

function [iMorton,toMorton]=nt_morton(nrows,ncols)

DESCRIPTION ^

[iMorton,toMorton]=nt_morton(nrows,ncols) - indices for Morton scan of image
 
  iMorton: matrix of indices in Morton order
  toMorton: indices to put pixels in Morton order

  nrows,ncols: dimensions of image

 NoiseTools

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [iMorton,toMorton]=nt_morton(nrows,ncols)
0002 %[iMorton,toMorton]=nt_morton(nrows,ncols) - indices for Morton scan of image
0003 %
0004 %  iMorton: matrix of indices in Morton order
0005 %  toMorton: indices to put pixels in Morton order
0006 %
0007 %  nrows,ncols: dimensions of image
0008 %
0009 % NoiseTools
0010 nt_greetings;
0011 
0012 if nargin<2; error('!'); end
0013 
0014 % morton order for square of side N power of 2
0015 N=2^ceil(log2(max(nrows,ncols)));
0016 if N==2
0017    iMorton = [1 2; 3 4];
0018 else
0019    b = nt_morton(N/2,N/2);
0020    iMorton = [b b+(N/2)^2; b+(N/2)^2*2 b+(N/2)^2*3];
0021 end
0022 
0023 % clip to bounds
0024 iMorton=iMorton(1:nrows,1:ncols);
0025 
0026 % adjust to avoid skipped values
0027 [~,idx]=sort(iMorton(:));
0028 iMorton(idx)=1:numel(iMorton);
0029 
0030 [~,toMorton]=sort(iMorton(:));

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005