source: trunk/src/series/sub_background_special.m @ 1124

Last change on this file since 1124 was 1124, checked in by sommeria, 13 months ago

series/sub_background corrected for long series of j index

File size: 8.3 KB
RevLine 
[1097]1%'bed_scan': get the bed shape from laser ipact
2
3%------------------------------------------------------------------------
4% function GUI_input=bed_scan(Param)
5%
6%------------------------------------------------------------------------
7%%%%%%%%%%% GENERAL TO ALL SERIES ACTION FCTS %%%%%%%%%%%%%%%%%%%%%%%%%%%
8%
9%OUTPUT
10% ParamOut: sets options in the GUI series.fig needed for the function
11%
12%INPUT:
13% In run mode, the input parameters are given as a Matlab structure Param copied from the GUI series.
14% In batch mode, Param is the name of the corresponding xml file containing the same information
15% when Param.Action.RUN=0 (as activated when the current Action is selected
16% in series), the function ouput paramOut set the activation of the needed GUI elements
17%
18% Param contains the elements:(use the menu bar command 'export/GUI config' in series to
19% see the current structure Param)
20%    .InputTable: cell of input file names, (several lines for multiple input)
21%                      each line decomposed as {RootPath,SubDir,Rootfile,NomType,Extension}
22%    .OutputSubDir: name of the subdirectory for data outputs
23%    .OutputDirExt: directory extension for data outputs
24%    .Action: .ActionName: name of the current activated function
25%             .ActionPath:   path of the current activated function
26%             .ActionExt: fct extension ('.m', Matlab fct, '.sh', compiled   Matlab fct
27%             .RUN =0 for GUI input, =1 for function activation
28%             .RunMode='local','background', 'cluster': type of function  use
29%             
30%    .IndexRange: set the file or frame indices on which the action must be performed
31%    .FieldTransform: .TransformName: name of the selected transform function
32%                     .TransformPath:   path  of the selected transform function
33%    .InputFields: sub structure describing the input fields withfields
34%              .FieldName: name(s) of the field
35%              .VelType: velocity type
36%              .FieldName_1: name of the second field in case of two input series
37%              .VelType_1: velocity type of the second field in case of two input series
38%              .Coord_y: name of y coordinate variable
39%              .Coord_x: name of x coordinate variable
40%    .ProjObject: %sub structure describing a projection object (read from ancillary GUI set_object)
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42
43%=======================================================================
[1107]44% Copyright 2008-2022, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[1097]45%   http://www.legi.grenoble-inp.fr
46%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
47%
48%     This file is part of the toolbox UVMAT.
49%
50%     UVMAT is free software; you can redistribute it and/or modify
51%     it under the terms of the GNU General Public License as published
[1098]52%     by the Free Software Foundation; either version 2 of the license,series
[1097]53%     or (at your option) any later version.
54%
55%     UVMAT is distributed in the hope that it will be useful,
56%     but WITHOUT ANY WARRANTY; without even the implied warranty of
57%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
58%     GNU General Public License (see LICENSE.txt) for more details.
59%=======================================================================
60
61function ParamOut=sub_background_special (Param)
62
63%% set the input elements needed on the GUI series when the action is selected in the menu ActionName or InputTable refreshed
64if isstruct(Param) && isequal(Param.Action.RUN,0)
65    ParamOut.NbViewMax=1;% max nbre of input file series (default , no limitation)
66    ParamOut.AllowInputSort='off';% allow alphabetic sorting of the list of input file SubDir (options 'off'/'on', 'off' by default)
67    ParamOut.WholeIndexRange='on';% prescribes the file index ranges from min to max (options 'off'/'on', 'off' by default)
[1098]68    ParamOut.NbSlice='on'; %nbre of slices ('off' by default)
[1097]69    ParamOut.VelType='off';% menu for selecting the velocity type (options 'off'/'one'/'two',  'off' by default)
70    ParamOut.FieldName='off';% menu for selecting the field (s) in the input file(options 'off'/'one'/'two', 'off' by default)
71    ParamOut.FieldTransform = 'off';%can use a transform function
72    ParamOut.ProjObject='off';%can use projection object(option 'off'/'on',
73    ParamOut.Mask='off';%can use mask option   (option 'off'/'on', 'off' by default)
74    ParamOut.OutputDirExt='.sback';%set the output dir extension
75    ParamOut.OutputFileMode='NbInput';% ='=NbInput': 1 output file per input file index, '=NbInput_i': 1 file per input file index i, '=NbSlice': 1 file per slice
76    %check the type of the existence and type of the first input file:
77return
78end
79
80%%%%%%%%%%%% STANDARD PART (DO NOT EDIT) %%%%%%%%%%%%
81%% read input parameters from an xml file if input is a file name (batch mode)
82ParamOut=[];
83RUNHandle=[];
84WaitbarHandle=[];
85checkrun=1;
86if ischar(Param)% case of batch: Param is the name of the xml file containing the input parameters
87    Param=xml2struct(Param);% read Param as input file (batch case)
88    checkrun=0;
89else% interactive mode in Matlab
90    hseries=findobj(allchild(0),'Tag','series');
91    RUNHandle=findobj(hseries,'Tag','RUN');%handle of RUN button in GUI series
92    WaitbarHandle=findobj(hseries,'Tag','Waitbar');%handle of waitbar in GUI series
93end
94%% estimate the position of bottom and mask for each Z Index
[1098]95NbSlice=Param.IndexRange.NbSlice;
96switch NbSlice
97    case 11
98        BottomIndex=[1900 1800 1700 1650 1650 1600 1600 1600 1600 1600 1600];
99    case 4
100        BottomIndex=[1950 1850 1740 1700];
101end
[1097]102MaxIndex=BottomIndex+100;
103MinIndex=BottomIndex-100;
[1098]104
[1097]105maskindex=[665 1080];% range of x index perturbed by shadows
106Bfilter=ones(1,20)/20;
107%% root input file names and nomenclature type (cell arrays with one element)
[1124]108OutputDir=[Param.OutputSubDir Param.OutputDirExt];
[1097]109nbj=numel(Param.IndexRange.first_i:Param.IndexRange.last_i);
110for i_ind=Param.IndexRange.first_i:Param.IndexRange.last_i
111    ZIndex=mod(i_ind-1,NbSlice)+1;
112    for j_ind=Param.IndexRange.first_j:Param.IndexRange.last_j
113        % read the current image
114        InputFile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
115        A=imread(InputFile);
116        % get the bottom as the max of luminosity along vertical lines   
117        IndexMax=ones(1,size(A,2));%initiate the index position of the bottom
118        if j_ind==Param.IndexRange.first_j
119            indexMax_j=ones(nbj,size(A,2));%initiate the matrix of index position of the bottom
120        end
121        for icolumn=1:maskindex(1)
122            [M,IndexMax(icolumn)] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),icolumn),[],1);
123        end
124        [M,IndexMax(maskindex(2))] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),maskindex(2)),[],1);
125        for icolumn=maskindex(1)+1:maskindex(2)-1 % linear interpolation in the masked region
126            IndexMax(icolumn)= IndexMax(maskindex(1))*(maskindex(2)-icolumn)+IndexMax(maskindex(2))*(icolumn-maskindex(1));
127            IndexMax(icolumn)=IndexMax(icolumn)/(maskindex(2)-maskindex(1));
128        end
129        for icolumn=maskindex(2)+1:size(A,2)
130            [M,IndexMax(icolumn)] = max(A(MinIndex(ZIndex)+1:MaxIndex(ZIndex),icolumn),[],1);
131        end
132        IndexFilt=filter(Bfilter,1,IndexMax);% smoothed IndexMax
133        peakdetect=find(abs(IndexFilt-IndexMax)>5);% detect strong departures from the filtered values
134        IndexMax(peakdetect)=IndexFilt(peakdetect);%replace the peaks by the filtered values
135        IndexMax_j(j_ind,:)=round(filter(Bfilter,1,IndexMax));%filter again and take the closest integer
136        % get the background image as the min at each point in the j series
137        if j_ind==Param.IndexRange.first_j
138            Amin=A;
139        else
140            Amin=min(Amin,A);
141        end
142    end
143   
144    for j_ind=Param.IndexRange.first_j:Param.IndexRange.last_j
145        InputFile=fullfile_uvmat(Param.InputTable{1,1},Param.InputTable{1,2},Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
146        A=imread(InputFile);
147        A=A-Amin;
148        for icolumn=1:size(A,2)
149            A(MinIndex(ZIndex)+IndexMax_j(j_ind,icolumn):end,icolumn)=0;
150        end
151        OutputFile=fullfile_uvmat(Param.InputTable{1,1},OutputDir,Param.InputTable{1,3},Param.InputTable{1,5},Param.InputTable{1,4},i_ind,i_ind,j_ind);
152        imwrite(A,OutputFile)
153        disp([OutputFile ' written'])
154    end
155end
156
157
158
159
160
161
162 
163
Note: See TracBrowser for help on using the repository browser.