[958] | 1 | % 'ima_filter': low-pass filter of an image followed by decimation
|
---|
| 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 | %=======================================================================
|
---|
| 14 | % Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
|
---|
| 15 | % http://www.legi.grenoble-inp.fr
|
---|
| 16 | % Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
|
---|
| 17 | %
|
---|
| 18 | % This file is part of the toolbox UVMAT.
|
---|
| 19 | %
|
---|
| 20 | % UVMAT is free software; you can redistribute it and/or modify
|
---|
| 21 | % it under the terms of the GNU General Public License as published
|
---|
| 22 | % by the Free Software Foundation; either version 2 of the license,
|
---|
| 23 | % or (at your option) any later version.
|
---|
| 24 | %
|
---|
| 25 | % UVMAT is distributed in the hope that it will be useful,
|
---|
| 26 | % but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 27 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 28 | % GNU General Public License (see LICENSE.txt) for more details.
|
---|
| 29 | %=======================================================================
|
---|
| 30 |
|
---|
| 31 | function DataOut=ima_filter(DataIn,Param)
|
---|
| 32 |
|
---|
| 33 | %% request input parameters
|
---|
| 34 | if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
|
---|
| 35 | prompt = {'npx';'npy'};
|
---|
| 36 | dlg_title = 'get the filter size in x and y';
|
---|
| 37 | num_lines= 2;
|
---|
| 38 | def = { '20';'20'};
|
---|
| 39 | if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
|
---|
| 40 | isfield(Param.TransformInput,'FilterBoxSize_y')
|
---|
| 41 | def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y)};
|
---|
| 42 | end
|
---|
| 43 | answer = inputdlg(prompt,dlg_title,num_lines,def);
|
---|
| 44 | DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
|
---|
| 45 | DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
|
---|
| 46 | return
|
---|
| 47 | end
|
---|
| 48 |
|
---|
| 49 | DataOut=DataIn; %default
|
---|
| 50 |
|
---|
| 51 | %definition of the cos shape matrix filter
|
---|
| 52 | bx=Param.TransformInput.FilterBoxSize_x;
|
---|
| 53 | by=Param.TransformInput.FilterBoxSize_y;
|
---|
| 54 | ix=1/2-bx/2:-1/2+bx/2;%
|
---|
| 55 | iy=1/2-by/2:-1/2+by/2;%
|
---|
| 56 | %del=np/3;
|
---|
| 57 | %fct=exp(-(ix/del).^2);
|
---|
| 58 | fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
|
---|
| 59 | fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
|
---|
| 60 | %Mfiltre=(ones(5,5)/5^2);
|
---|
| 61 | Mfiltre=fct2_y'*fct2_x;
|
---|
| 62 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
|
---|
| 63 |
|
---|
| 64 | Atype=class(DataIn.A);% detect integer 8 or 16 bits
|
---|
| 65 | if numel(size(DataIn.A))==3
|
---|
| 66 | DataOut.A=filter2(Mfiltre,sum(DataIn.A,3));%filter the input image, after summation on the color component (for color images)
|
---|
| 67 | DataOut.A=uint16(DataOut.A); %transform to 16 bit images
|
---|
| 68 | else
|
---|
| 69 | DataOut.A=filter2(Mfiltre,DataIn.A);
|
---|
| 70 | DataOut.A=feval(Atype,DataOut.A);%transform to the initial image format
|
---|
| 71 | end
|
---|
| 72 | %reduce the size of the image
|
---|
| 73 | [npy,npx]=size(DataOut.A);
|
---|
| 74 | ind_y=ceil(by/2):by:npy-ceil(by/2);
|
---|
| 75 | ind_x=ceil(bx/2):bx:npx-ceil(bx/2);
|
---|
| 76 | B=DataOut.A(ind_y,ind_x);
|
---|
| 77 | DataOut.A=B;
|
---|
| 78 |
|
---|