Changeset 730 for trunk/src


Ignore:
Timestamp:
Mar 4, 2014, 10:23:22 PM (11 years ago)
Author:
sommeria
Message:

ima_filter put as example of transform function with input parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/transform_field/ima_filter.m

    r574 r730  
    1 % 'ima_filter': low-pass filtr of an image (builtin filtering parameter)
     1% 'ima_filter': example of image transform with input parameters: low-pass filter of an image
    22
    33%------------------------------------------------------------------------
    4 %%%%  Use the general syntax for transform fields with a single input %%%%
     4%%%%  Use the general syntax for transform fields with a single input and parameters %%%%
    55% OUTPUT:
    66% DataOut:   output field structure
    77
    88%INPUT:
    9 % DataIn:  first input field structure
    10 %------------------------------------------------------------------------
    11 function DataOut=ima_filter(DataIn)
    12 np=20 %size of the filtering window
     9% DataIn:  input field structure
     10% Param: matlab structure whose field Param.TransformInput contains the filter parameters
     11%-----------------------------------
     12
     13%-------------------------------------
     14function DataOut=ima_test(DataIn,Param)
     15if isequal(DataIn,'*')
     16    prompt = {'npx';'npy'};
     17    dlg_title = 'get the filter size in x and y';
     18    num_lines= 2;
     19    def     = { '20';'20'};
     20    if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
     21            isfield(Param.TransformInput,'FilterBoxSize_y')
     22        def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y)};
     23    end
     24    answer = inputdlg(prompt,dlg_title,num_lines,def);
     25    DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
     26    DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
     27    return
     28end
     29
     30DataOut=DataIn; %default
     31
    1332%definition of the cos shape matrix filter
    14 ix=[1/2-np/2:-1/2+np/2];%
    15 del=np/3;
     33ix=[1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2];%
     34iy=[1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2];%
     35%del=np/3;
    1636%fct=exp(-(ix/del).^2);
    17 fct2=cos(ix/((np-1)/2)*pi/2);
     37fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
     38fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
    1839%Mfiltre=(ones(5,5)/5^2);
    19 Mfiltre=fct2'*fct2;
     40Mfiltre=fct2_y'*fct2_x;
    2041Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
    2142
    22 DataOut=DataIn; %default
    23 Atype=class(DataIn.A)% detect integer 8 or 16 bits
     43Atype=class(DataIn.A);% detect integer 8 or 16 bits
    2444if numel(size(DataIn.A))==3
    2545    DataOut.A=filter2(Mfiltre,sum(DataIn.A,3));%filter the input image, after summation on the color component (for color images)
Note: See TracChangeset for help on using the changeset viewer.