source: trunk/src/transform_field/ima_filter_high.m @ 1160

Last change on this file since 1160 was 1127, checked in by g7moreau, 9 months ago

Update Joel email

File size: 4.7 KB
Line 
1% 'ima_filter_high': high-pass filter of an image or other 2D fields defined on a regular grid
2% the size of the filtering window in x and y is interactivement defined
3
4%------------------------------------------------------------------------
5%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
6% OUTPUT:
7% DataOut:   output field structure
8%
9%INPUT:
10% DataIn:  input field structure
11% Param: matlab structure whose field Param.TransformInput contains the filter parameters
12% DataIn_1: variables possibly introduced as a second input field
13%-----------------------------------
14
15%=======================================================================
16% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
17%   http://www.legi.grenoble-inp.fr
18%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
19%
20%     This file is part of the toolbox UVMAT.
21%
22%     UVMAT is free software; you can redistribute it and/or modify
23%     it under the terms of the GNU General Public License as published
24%     by the Free Software Foundation; either version 2 of the license,
25%     or (at your option) any later version.
26%
27%     UVMAT is distributed in the hope that it will be useful,
28%     but WITHOUT ANY WARRANTY; without even the implied warranty of
29%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30%     GNU General Public License (see LICENSE.txt) for more details.
31%=======================================================================
32
33function DataOut=ima_filter_high(DataIn,Param,DataIn_1)
34
35%% request input parameters
36if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
37    prompt = {'npx';'npy'};
38    dlg_title = 'get the filter size in x and y';
39    num_lines= 2;
40    def     = { '20';'20'};
41    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
42            isfield(Param.TransformInput,'FilterBoxSize_y')
43        def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y)};
44    end
45    answer = inputdlg(prompt,dlg_title,num_lines,def);
46    DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
47    DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
48    return
49end
50
51DataOut=DataIn; %default
52
53%definition of the cos shape matrix filter
54ix=1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2;%
55iy=1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2;%
56%del=np/3;
57%fct=exp(-(ix/del).^2);
58fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
59fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
60%Mfiltre=(ones(5,5)/5^2);
61Mfiltre=fct2_y'*fct2_x;
62Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
63
64[CellInfo,NbDim,errormsg]=find_field_cells(DataIn)
65for icell=1:numel(CellInfo)
66    if isfield(CellInfo{icell},'CoordType')&& strcmp(CellInfo{icell}.CoordType,'grid')
67        for ivar=1:numel(CellInfo{icell}.VarIndex)
68            VarName=DataIn.ListVarName{CellInfo{icell}.VarIndex(ivar)};
69            Atype=class(DataIn.(VarName));% detect integer 8 or 16 bits
70            if numel(size(DataIn.(VarName)))==3
71                DataOut.(VarName)=filter2(Mfiltre,sum(DataIn.(VarName),3));%filter the input image, after summation on the color component (for color images)
72                DataOut.(VarName)=uint16(DataOut.(VarName)); %transform to 16 bit images
73            else
74                DataOut.(VarName)=DataIn.(VarName)-filter2(Mfiltre,DataIn.(VarName));
75                DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format
76            end
77        end
78    end
79end
80if exist('DataIn_1','var')
81    [CellInfo,NbDim,errormsg]=find_field_cells(DataIn_1);
82for icell=1:numel(CellInfo)
83    if isfield(CellInfo{icell},'CoordType')&& strcmp(CellInfo{icell}.CoordType,'grid')
84        for ivar=1:numel(CellInfo{icell}.VarIndex)
85            VarName=DataIn_1.ListVarName{CellInfo{icell}.VarIndex(ivar)};
86            Atype=class(DataIn_1.(VarName));% detect integer 8 or 16 bits
87            if numel(size(DataIn_1.(VarName)))==3
88                DataOut.(VarName)=filter2(Mfiltre,sum(DataIn_1.(VarName),3));%filter the input image, after summation on the color component (for color images)
89                DataOut.(VarName)=uint16(DataOut.(VarName)); %transform to 16 bit images
90            else
91                DataOut.(VarName)=filter2(Mfiltre,DataIn_1.(VarName));
92                DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format
93            end
94        end
95    end
96end
97end
98
99 
Note: See TracBrowser for help on using the repository browser.