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 | %------------------------------------------------------------------------
|
---|
5 | %%%% Use the general syntax for transform fields with a single input and parameters %%%%
|
---|
6 | % OUTPUT:
|
---|
7 | % DataOut: output field structure
|
---|
8 |
|
---|
9 | %INPUT:
|
---|
10 | % DataIn: input field structure
|
---|
11 | % Param: matlab structure whose field Param.TransformInput contains the filter parameters
|
---|
12 | %-----------------------------------
|
---|
13 |
|
---|
14 | %-------------------------------------
|
---|
15 | function DataOut=ima_noise_rms(DataIn,Param)
|
---|
16 |
|
---|
17 | %% request input parameters
|
---|
18 | if isfield(DataIn,'Action') && isfield(DataIn.Action,'RUN') && isequal(DataIn.Action.RUN,0)
|
---|
19 | prompt = {'npx';'npy'};
|
---|
20 | dlg_title = 'get the filter size in x and y';
|
---|
21 | num_lines= 2;
|
---|
22 | def = { '20';'20'};
|
---|
23 | if isfield(Param,'TransformInput')&&isfield(Param.TransformInput,'FilterBoxSize_x')&&...
|
---|
24 | isfield(Param.TransformInput,'FilterBoxSize_y')
|
---|
25 | def={num2str(Param.TransformInput.FilterBoxSize_x);num2str(Param.TransformInput.FilterBoxSize_y)};
|
---|
26 | end
|
---|
27 | answer = inputdlg(prompt,dlg_title,num_lines,def);
|
---|
28 | DataOut.TransformInput.FilterBoxSize_x=str2num(answer{1}); %size of the filtering window
|
---|
29 | DataOut.TransformInput.FilterBoxSize_y=str2num(answer{2}); %size of the filtering window
|
---|
30 | return
|
---|
31 | end
|
---|
32 |
|
---|
33 | DataOut=DataIn; %default
|
---|
34 |
|
---|
35 | %definition of the cos shape matrix filter
|
---|
36 | ix=[1/2-Param.TransformInput.FilterBoxSize_x/2:-1/2+Param.TransformInput.FilterBoxSize_x/2];%
|
---|
37 | iy=[1/2-Param.TransformInput.FilterBoxSize_y/2:-1/2+Param.TransformInput.FilterBoxSize_y/2];%
|
---|
38 | %del=np/3;
|
---|
39 | %fct=exp(-(ix/del).^2);
|
---|
40 | fct2_x=cos(ix/((Param.TransformInput.FilterBoxSize_x-1)/2)*pi/2);
|
---|
41 | fct2_y=cos(iy/((Param.TransformInput.FilterBoxSize_y-1)/2)*pi/2);
|
---|
42 | %Mfiltre=(ones(5,5)/5^2);
|
---|
43 | Mfiltre=fct2_y'*fct2_x;
|
---|
44 | Mfiltre=Mfiltre/(sum(sum(Mfiltre)));%normalize filter
|
---|
45 |
|
---|
46 | Atype=class(DataIn.A);% detect integer 8 or 16 bits
|
---|
47 | B=filter2(Mfiltre,DataIn.A);
|
---|
48 | B(B==0)=1; %set to 1 the zero values
|
---|
49 | C=(double(DataIn.A)-B)./B;
|
---|
50 | C=filter2(Mfiltre,C.*C);% take variance integrated in the filtering area
|
---|
51 | C=1000000*sqrt(C); % take the root and *10^6 to get an image with integer values (parts per million)
|
---|
52 | DataOut.A=feval(Atype,C);%transform to the initial image format
|
---|
53 |
|
---|
54 |
|
---|
55 | |
---|