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