source: trunk/src/transform_field/ima_filter.m

Last change on this file was 1127, checked in by g7moreau, 11 months ago

Update Joel email

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