source: trunk/src/transform_field/ima_filter.m @ 783

Last change on this file since 783 was 753, checked in by sommeria, 11 years ago

signal spectrum analysis and various improvements in transform

File size: 2.3 KB
Line 
1% 'ima_filter': example of image transform with input parameters: low-pass filter of an image
2
3%------------------------------------------------------------------------
4%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
5% OUTPUT:
6% DataOut:   output field structure
7
8%INPUT:
9% DataIn:  input field structure
10% Param: matlab structure whose field Param.TransformInput contains the filter parameters
11%-----------------------------------
12
13%-------------------------------------
14function DataOut=ima_filter(DataIn,Param)
15
16%% request input parameters
17if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
18    prompt = {'npx';'npy'};
19    dlg_title = 'get the filter size in x and y';
20    num_lines= 2;
21    def     = { '20';'20'};
22    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
23            isfield(Param.TransformInput,'FilterBoxSize_y')
24        def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y)};
25    end
26    answer = inputdlg(prompt,dlg_title,num_lines,def);
27    DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
28    DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
29    return
30end
31
32DataOut=DataIn; %default
33
34%definition of the cos shape matrix filter
35ix=[1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2];%
36iy=[1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2];%
37%del=np/3;
38%fct=exp(-(ix/del).^2);
39fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
40fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
41%Mfiltre=(ones(5,5)/5^2);
42Mfiltre=fct2_y'*fct2_x;
43Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
44
45Atype=class(DataIn.A);% detect integer 8 or 16 bits
46if numel(size(DataIn.A))==3
47    DataOut.A=filter2(Mfiltre,sum(DataIn.A,3));%filter the input image, after summation on the color component (for color images)
48    DataOut.A=uint16(DataOut.A); %transform to 16 bit images
49else
50    DataOut.A=filter2(Mfiltre,DataIn.A)
51    DataOut.A=feval(Atype,DataOut.A);%transform to the initial image format
52end
53 
Note: See TracBrowser for help on using the repository browser.