[1122] | 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
|
---|
[574] | 3 |
|
---|
| 4 | %------------------------------------------------------------------------
|
---|
[730] | 5 | %%%% Use the general syntax for transform fields with a single input and parameters %%%%
|
---|
[1122] | 6 | % OUTPUT:
|
---|
| 7 | % DataOut: output field structure
|
---|
[810] | 8 | %
|
---|
[574] | 9 | %INPUT:
|
---|
[730] | 10 | % DataIn: input field structure
|
---|
[1122] | 11 | %
|
---|
[730] | 12 | % Param: matlab structure whose field Param.TransformInput contains the filter parameters
|
---|
[1122] | 13 | % DataIn_1: variables possibly introduced as a second input field
|
---|
[730] | 14 | %-----------------------------------
|
---|
| 15 |
|
---|
[810] | 16 | %=======================================================================
|
---|
[1126] | 17 | % Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
[810] | 18 | % http://www.legi.grenoble-inp.fr
|
---|
[1127] | 19 | % Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
|
---|
[810] | 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 |
|
---|
[1119] | 34 | function DataOut=ima_filter(DataIn,Param,DataIn_1)
|
---|
[753] | 35 |
|
---|
[957] | 36 | %% request input parameters
|
---|
| 37 | if 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;
|
---|
[1168] | 41 | def = { '21';'21'};
|
---|
[957] | 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
|
---|
| 50 | end
|
---|
| 51 |
|
---|
[730] | 52 | DataOut=DataIn; %default
|
---|
| 53 |
|
---|
[40] | 54 | %definition of the cos shape matrix filter
|
---|
[957] | 55 | ix=1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2;%
|
---|
| 56 | iy=1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2;%
|
---|
[730] | 57 | %del=np/3;
|
---|
[40] | 58 | %fct=exp(-(ix/del).^2);
|
---|
[730] | 59 | fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
|
---|
| 60 | fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
|
---|
[40] | 61 | %Mfiltre=(ones(5,5)/5^2);
|
---|
[730] | 62 | Mfiltre=fct2_y'*fct2_x;
|
---|
[40] | 63 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
|
---|
| 64 |
|
---|
[1081] | 65 | [CellInfo,NbDim,errormsg]=find_field_cells(DataIn)
|
---|
| 66 | for 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));
|
---|
[1168] | 76 | %DataOut.(VarName)=filter2_uvmat(Param.TransformInput.FilterBoxSize_x,Param.TransformInput.FilterBoxSize_y,DataIn.(VarName));
|
---|
[1081] | 77 | DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format
|
---|
| 78 | end
|
---|
| 79 | end
|
---|
| 80 | end
|
---|
[93] | 81 | end
|
---|
[1119] | 82 | if exist('DataIn_1','var')
|
---|
| 83 | [CellInfo,NbDim,errormsg]=find_field_cells(DataIn_1);
|
---|
[1122] | 84 | for icell=1:numel(CellInfo)
|
---|
| 85 | if isfield(CellInfo{icell},'CoordType')&& strcmp(CellInfo{icell}.CoordType,'grid')
|
---|
| 86 | for ivar=1:numel(CellInfo{icell}.VarIndex)
|
---|
| 87 | VarName=DataIn_1.ListVarName{CellInfo{icell}.VarIndex(ivar)};
|
---|
| 88 | Atype=class(DataIn_1.(VarName));% detect integer 8 or 16 bits
|
---|
| 89 | if numel(size(DataIn_1.(VarName)))==3
|
---|
| 90 | DataOut.(VarName)=filter2(Mfiltre,sum(DataIn_1.(VarName),3));%filter the input image, after summation on the color component (for color images)
|
---|
| 91 | DataOut.(VarName)=uint16(DataOut.(VarName)); %transform to 16 bit images
|
---|
| 92 | else
|
---|
| 93 | DataOut.(VarName)=filter2(Mfiltre,DataIn_1.(VarName));
|
---|
| 94 | DataOut.(VarName)=feval(Atype,DataOut.(VarName));%transform to the initial image format
|
---|
| 95 | end
|
---|
[1119] | 96 | end
|
---|
| 97 | end
|
---|
| 98 | end
|
---|
| 99 | end
|
---|
| 100 |
|
---|
[810] | 101 |
|
---|