Changeset 1168 for trunk/src/transform_field
- Timestamp:
- Dec 9, 2024, 7:40:14 PM (3 months ago)
- Location:
- trunk/src/transform_field
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/transform_field/FFT2_detrend.m
r1127 r1168 1 % 'FFT2_detrend': calculate the 2D spectrum of the input scalar after removing the linear trend1 % 'FFT2_detrend': calculate the 2D spectrum of the input scalar or image after removing the linear trend 2 2 %------------------------------------------------------------------------ 3 3 %%%% Use the general syntax for transform fields with a single input %%%% … … 34 34 end 35 35 %%%%%%%%%%%%%%%%%%%%%%%%% 36 [CellInfo,NbDim,errormsg]=find_field_cells(DataIn); 36 [CellInfo,NbDim,errormsg]=find_field_cells(DataIn);% detect the input fields 37 37 if ~isempty(errormsg) 38 38 DataOut.Txt=errormsg; … … 42 42 DataOut.VarDimName={}; 43 43 for ilist=1:numel(CellInfo) 44 if NbDim(ilist)==2 && numel(CellInfo{ilist}.CoordIndex)==2 % field with structured coordinates 44 if NbDim(ilist)==2 && numel(CellInfo{ilist}.CoordIndex)==2 % field with structured 2D coordinates 45 %process scalar 46 ivar=CellInfo{ilist}.VarIndex_scalar(1); 47 VarName=DataIn.ListVarName{ivar};% name o the scalar field 48 z=double(DataIn.(VarName));% transform integer input to double real 49 z(isnan(z))=0;% set NaN values to 0 50 [npy,npx]=size(z); 51 45 52 %process coordinates 46 53 CoordName=DataIn.ListVarName(CellInfo{ilist}.CoordIndex); 47 x1 = DataIn.(CoordName{2}); y1 = DataIn.(CoordName{1});48 [x y] = meshgrid(x1,y1);49 coeff(1,1) = sum(sum(x.^2)); coeff(1,2) = sum(sum(x.*y)); coeff(1,3) = sum(sum(x));50 coeff(2,1) = sum(sum(x.*y)); coeff(2,2) = sum(sum(y.^2)); coeff(2,3) = sum(sum(y));51 coeff(3,1) = sum(sum(x)); coeff(3,2) = sum(sum(y)); coeff(3,3) = length(x1)*length(y1);54 x1 = linspace(DataIn.(CoordName{2})(1),DataIn.(CoordName{2})(end),npx); 55 y1 =linspace(DataIn.(CoordName{1})(1),DataIn.(CoordName{1})(end),npy); 56 [x,y] = meshgrid(x1,y1);% 2D grid of coordinates 57 58 % prepare the grid of wave vectors 52 59 delta_x = x1(2) - x1(1); delta_y = y1(2) - y1(1); 53 60 Nx = length(x1); Ny = length(y1); … … 55 62 ssx = find(Nxa<Nx/2); ssy = find(Nya<Ny/2); 56 63 Nxa(Nx-ssx+1) = -Nxa(ssx)+1; Nya(Ny-ssy+1) = -Nya(ssy)+1; 57 [Nxa Ix] = sort(Nxa); [Nya Iy] = sort(Nya);64 [Nxa, Ix] = sort(Nxa); [Nya, Iy] = sort(Nya); 58 65 kx1 = (2*pi/delta_x/Nx)*(Nxa-1); ky1 = (2*pi/delta_y/Ny)*(Nya-1); 59 66 ss = find(ky1>=0); ky1 = ky1(ss); 60 [kx 67 [kx,ky] = meshgrid(kx1,ky1); 61 68 DataOut.(CoordName{2}) = kx1; DataOut.(CoordName{1}) = ky1; 62 69 if isfield(DataIn,'CoordUnit') 63 DataOut.CoordUnit=[DataIn.CoordUnit '^{-1}']; 70 DataOut.CoordUnit=[DataIn.CoordUnit '^{-1}'];%unit of wave vectors 64 71 DataOut.ListGlobalAttribute={'CoordUnit'}; 65 72 end 66 %process scalar67 ivar=CellInfo{ilist}.VarIndex_scalar(1);68 VarName=DataIn.ListVarName{ivar};69 z=DataIn.(VarName);70 z(isnan(z))=0;% set to 0 NaN values73 74 % get the coeff to calulate the linear trend 75 coeff(1,1) = sum(sum(x.^2)); coeff(1,2) = sum(sum(x.*y)); coeff(1,3) = sum(sum(x)); 76 coeff(2,1) = sum(sum(x.*y)); coeff(2,2) = sum(sum(y.^2)); coeff(2,3) = sum(sum(y)); 77 coeff(3,1) = sum(sum(x)); coeff(3,2) = sum(sum(y)); coeff(3,3) = length(x1)*length(y1); 71 78 rhs(1) = sum(sum(x.*z)); rhs(2) = sum(sum(y.*z)); rhs(3) = sum(sum(z)); 72 lin_coeff = inv(coeff)*rhs'; 79 % lin_coeff = inv(coeff)*rhs'; 80 lin_coeff = coeff\rhs'; 73 81 lin_trend = lin_coeff(1)*x + lin_coeff(2)*y + lin_coeff(3); 74 z2 = z - lin_trend; 75 spec2 = abs(fft2(z2)).^2; 82 z2 = z - lin_trend;% substract the linear trend to the input field 83 84 spec2 = abs(fft2(z2)).^2;% get spectrum as squared of fft modulus 76 85 spec2 = spec2(Iy,Ix); 77 86 spec2 = spec2(ss,:); 78 DataOut.(VarName) = log10(spec2); 87 DataOut.(VarName) = log10(spec2);% take the log10 of spectrum 79 88 %DataOut.(VarName) = spec2; 80 spec_sum=sum(sum(spec2));81 kx_mean=sum(sum(spec2.*kx))/spec_sum;82 ky_mean=sum(sum(spec2.*ky))/spec_sum;83 theta=atand(ky_mean/kx_mean);84 lambda=2*pi/(sqrt(kx_mean*kx_mean+ky_mean*ky_mean));89 % spec_sum=sum(sum(spec2)); 90 % kx_mean=sum(sum(spec2.*kx))/spec_sum; 91 % ky_mean=sum(sum(spec2.*ky))/spec_sum; 92 % theta=atand(ky_mean/kx_mean); 93 % lambda=2*pi/(sqrt(kx_mean*kx_mean+ky_mean*ky_mean)); 85 94 86 95 DataOut.ListVarName=[CoordName {VarName}];%list of variables -
trunk/src/transform_field/ima_filter.m
r1127 r1168 39 39 dlg_title = 'get the filter size in x and y'; 40 40 num_lines= 2; 41 def = { '2 0';'20'};41 def = { '21';'21'}; 42 42 if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&... 43 43 isfield(Param.TransformInput,'FilterBoxSize_y') … … 74 74 else 75 75 DataOut.(VarName)=filter2(Mfiltre,DataIn.(VarName)); 76 %DataOut.(VarName)=filter2_uvmat(Param.TransformInput.FilterBoxSize_x,Param.TransformInput.FilterBoxSize_y,DataIn.(VarName)); 76 77 DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format 77 78 end
Note: See TracChangeset
for help on using the changeset viewer.