Ignore:
Timestamp:
Oct 20, 2025, 4:38:10 PM (7 weeks ago)
Author:
sommeria
Message:

bed_scan updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/series/bed_scan.m

    r1127 r1182  
    1 %'bed_scan': get the bed shape from laser ipact
     1%'bed_scan': get the bed shape from laser impact
     2% firts line input files = active images
     3% second line, reference images for the initial bed
    24
    35%------------------------------------------------------------------------
     
    8587        FileInfo=get_file_info(filecell{1,1});
    8688        FileType=FileInfo.FileType;
    87         if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})));% =1 for images
     89        if isempty(find(strcmp(FileType,{'image','multimage','mmreader','video'})))% =1 for images
    8890            msgbox_uvmat('ERROR',['bad input file type for ' mfilename ': an image is needed'])
    8991        end
     
    108110
    109111%% root input file names and nomenclature type (cell arrays with one element)
    110 RootPath=Param.InputTable{2,1};
    111 % RootFile=Param.InputTable(:,3);
    112 % SubDir=Param.InputTable(:,2);
    113 % NomType=Param.InputTable(:,4);
    114 % FileExt=Param.InputTable(:,5);
     112RootPath=Param.InputTable{1,1};
     113
    115114
    116115%% directory for output files
     
    127126nbfield_i=size(i1_series{1},2); %nb of fields for the i index
    128127
    129 %% frame index for movie or multimage file input 
     128%% set of y positions 
     129ycalib=[-51 -1 49];% calibration planes
     130y_scan=-51+(100/400)*(i1_series{1}-1);% transverse position given by the translating system: first view at y=-51, view 400 at y=+49
     131Mfiltre=ones(2,10)/20;%filter matrix for imnages
    130132
    131133%% calibration data and timing: read the ImaDoc files
    132 %not relevant for this function
    133 
    134 %% check coincidence in time for several input file series
     134XmlData_A=xml2struct(fullfile(RootPath,'planeA.xml'));
     135XmlData_B=xml2struct(fullfile(RootPath,'planeB.xml'));
     136XmlData_C=xml2struct(fullfile(RootPath,'planeC.xml'));
     137ycalib=[-51 -1 49];% the three y positions for calibration
     138fx(1)=XmlData_A.GeometryCalib.fx_fy(1);
     139fx(2)=XmlData_B.GeometryCalib.fx_fy(1);
     140fx(3)=XmlData_C.GeometryCalib.fx_fy(1);
     141fy(1)=XmlData_A.GeometryCalib.fx_fy(2);
     142fy(2)=XmlData_B.GeometryCalib.fx_fy(2);
     143fy(3)=XmlData_C.GeometryCalib.fx_fy(2);
     144Tx(1)=XmlData_A.GeometryCalib.Tx_Ty_Tz(1);
     145Tx(2)=XmlData_B.GeometryCalib.Tx_Ty_Tz(1);
     146Tx(3)=XmlData_C.GeometryCalib.Tx_Ty_Tz(1);
     147Ty(1)=XmlData_A.GeometryCalib.Tx_Ty_Tz(2);
     148Ty(2)=XmlData_B.GeometryCalib.Tx_Ty_Tz(2);
     149Ty(3)=XmlData_C.GeometryCalib.Tx_Ty_Tz(2);
     150R11(1)=XmlData_A.GeometryCalib.R(1,1);
     151R11(2)=XmlData_B.GeometryCalib.R(1,1);
     152R11(3)=XmlData_C.GeometryCalib.R(1,1);
     153R12(1)=XmlData_A.GeometryCalib.R(1,2);
     154R12(2)=XmlData_B.GeometryCalib.R(1,2);
     155R12(3)=XmlData_C.GeometryCalib.R(1,2);
     156R21(1)=XmlData_A.GeometryCalib.R(2,1);
     157R21(2)=XmlData_B.GeometryCalib.R(2,1);
     158R21(3)=XmlData_C.GeometryCalib.R(2,1);
     159R22(1)=XmlData_A.GeometryCalib.R(2,2);
     160R22(2)=XmlData_B.GeometryCalib.R(2,2);
     161R22(3)=XmlData_C.GeometryCalib.R(2,2);
     162pfx=polyfit(ycalib,fx,1);%get the linear interpolation of each parameter of the three calibrations
     163pfy=polyfit(ycalib,fy,1);
     164pTx=polyfit(ycalib,Tx,1);
     165pTy=polyfit(ycalib,Ty,1);
     166p11=polyfit(ycalib,R11,1);
     167p12=polyfit(ycalib,R12,1);
     168p21=polyfit(ycalib,R21,1);
     169p22=polyfit(ycalib,R22,1);
     170%get the calibration parameters at each position y by interpolation of the 3 calibration parameters
     171for img=1:nbfield_i
     172    Calib(img).fx_fy(1)=pfx(1)*y_scan(img)+pfx(2);
     173    Calib(img).fx_fy(2)=pfy(1)*y_scan(img)+pfy(2);
     174    Calib(img).Tx_Ty_Tz(1)=pTx(1)*y_scan(img)+pTx(2);
     175    Calib(img).Tx_Ty_Tz(2)=pTy(1)*y_scan(img)+pTy(2);
     176    Calib(img).Tx_Ty_Tz(3)=1;
     177    Calib(img).R=zeros(3,3);
     178    Calib(img).R(3,3)=-1;
     179    Calib(img).R(1,2)=p12(1)*y_scan(img)+p12(2);
     180    Calib(img).R(1,1)=p11(1)*y_scan(img)+p11(2);
     181    Calib(img).R(1,2)=p12(1)*y_scan(img)+p12(2);
     182    Calib(img).R(2,1)=p21(1)*y_scan(img)+p21(2);
     183    Calib(img).R(2,2)=p22(1)*y_scan(img)+p22(2);
     184end
     185
     186%% check coincdence in time for several input file series
    135187%not relevant for this function
    136188
     
    141193 % EDIT FROM HERE
    142194
    143  %% Extension and indexing nomenclature for output file
    144 
    145 % name=('EXP18OS_bed_init/im/');
    146 % name2=('EXP18OS_end/im/');
    147 % path_proj=['/.fsnet/project/coriolis/2018/18ADDUCE/SEDIM_SCANSIDE/']; 
    148 
    149 %nimages=1800;
    150 
    151195%% Load the init bed scan
    152 
    153 y=90.05-0.05*i1_series{1};
    154 Mfiltre=ones(2,10)/20;%filter matrix for imnages
    155196tic
    156 % y=zeros(1,nimages);
    157 % X_new=zeros(4096,nimages);
    158 x=1:4096;
    159 % img=1;
    160 %filecell{1,img}= list of the images _init
    161 %filecell{2,img}= list of the images _end
    162 for img=1:nbfield_i
     197nb_scan=10;
     198nb_scan=10;
     199for img=1:nb_scan
    163200     img
    164     image=flipud(imread(filecell{2,img}));
    165     a=image(700:1900,:);
     201    a=flipud(imread(filecell{1,img}));%image of the initial bed
     202    if img==1
     203        x=1:size(a,2);%image absissa in pixel coordinates
     204    end
    166205    % filtering
    167     a=filter2(Mfiltre,a);
    168     [imax,iy]=max(a);
    169     Z=squeeze(iy);
    170     iy(imax<50)=NaN;
    171     Z_s(:,img)=smooth(Z,40,'rloess');
    172 %     y(img)=y0-(0.05.*step);
    173 %     y0=y(img);
    174     X_new(:,img)=phys_scan(x,y(img));
     206    a=filter2(Mfiltre,a);%smoothed image
     207    [imax,iy]=max(a);% find the max along the first coordinate y, max values imax and the corresponding  y index iy along the first coordinate y
     208    Z_s(img,:)=smooth(iy,40,'rloess');%smooth Z, the image index of max luminosity (dependning on x)
     209    Yima=y_scan(img)*ones(size(x));%positions Y transformed into a vector
     210    X_new(img,:)=phys_XYZ(Calib(img),x,Yima,1);
     211    %X_new(:,img)=phys_scan(x,y(img));
    175212end
    176213
    177214toc
    178215
    179 nimages2=size(Z_s,2);
    180 %%
    181 y_y=1:size(a,1);
    182 
    183 % [Xx,Yy]=meshgrid(x,y_y);
    184 [X,Y]=meshgrid(x,y);
    185 
    186 % index=1;
    187 % [imax,iy]=max(a);
    188 %
    189 % Z=squeeze(iy);
    190 
    191 %%  smooth bed init
    192 % for i=2:dim(2)
    193 % if iy(i)<300
    194 %     imax(i)=imax(i-1);
    195 % end
    196 % end
    197 
    198 % for i=1:nimages2
    199 % Z_s(:,i)=smooth(Z(:,i),50,'rloess');
    200 % % Z_s_new(:,i)=phys_scanz(x,Z_s(:,i)',y(i));
    201 %
    202 % end
    203 
    204 %% Load the transit bed scan
    205 for img=1:nbfield_i
    206     img
    207      image=flipud(imread(filecell{1,img}));
    208     b=image(700:1900,:);
    209         % filtering
    210     b=filter2(Mfiltre,b);
     216[X,Y]=meshgrid(x,y_scan);
     217
     218
     219%% Load the current bed scan
     220for img=1:nb_scan
     221   b=flipud(imread(filecell{2,img}));%image of the current bed
     222    b=filter2(Mfiltre,b); % filtering
    211223    [imaxb,iyb]=max(b);
    212     Zb=squeeze(iyb);
    213     iyb(imaxb<50)=NaN;
    214     Z_sb(:,img)=smooth(Zb,20,'rloess');
    215 end
    216 
     224    Z_sb(img,:)=smooth(iyb,20,'rloess');
     225end
    217226
    218227%% bed change
    219 dZ=Z_s-Z_sb;
    220 dZ_new=zeros(4096,nimages2);
    221 for img=1:nimages2 
    222     dZ_new(:,img)=phys_scanz(dZ(:,img),y(img));
     228dZ=Z_s-Z_sb;% displacement between current position and initial
     229dZ_new=zeros(nb_scan,size(dZ,2));
     230for img=1:nb_scan 
     231    Yima=y_scan(img)*ones(1,size(dZ,2));
     232    [~,dZ_new(img,:)]=phys_XYZ(Calib(img),dZ(img,:),Yima,1);
     233   % dZ_new(:,img)=phys_scanz(dZ(:,img),y(img));
    223234end
    224235
    225236
    226237%% PLOTS
    227 coord_x=X_new(1,end):0.1:X_new(end,end);
    228 [Y_m,X_m]=meshgrid(y(1,:),coord_x);
    229 Y_new=Y';
    230 dZ_mesh=griddata(X_new,Y_new,dZ_new,X_m,Y_m);
     238coord_x=X_new(end,1):0.1:X_new(end,end);
     239[Y_m,X_m]=meshgrid(y_scan,coord_x);
     240%Y_new=Y';
     241dZ_mesh=griddata(X_new,Y,dZ_new,X_m,Y_m);
    231242
    232243if checkrun
     
    234245    hold on
    235246    plot(x,Z_s+700)
    236     xlim([0 4096])
    237     ylim([0 3000])
     247    % xlim([0 4096])
     248    % ylim([0 3000])
    238249   
    239250    figure(2)
     
    260271end
    261272
    262 save(fullfile(DirOut,'18OS_f.mat'),'dZ','dZ_new','X','Y','Z_s','Z_sb','y')
     273%save(fullfile(DirOut,'18OS_f.mat'),'dZ','dZ_new','X','Y','Z_s','Z_sb','y')
    263274
    264275% save netcdf
     
    276287struct2nc(fullfile(DirOut,'dZ.nc'),Data)
    277288
     289%% gives the physical position x from the image position X and the physical position y of the laser plane
    278290function F=phys_scan(X,y)
     291% linear fct of X whose coefficient depend on y in a quadratic way
    279292F=(9.4*10^(-7)*y.^2-3.09*10^(-4)*y+0.07).*X +(-0.001023*y.^2+0.469*y+186.9);
    280293
     294%% gives the physical position z from the image position Z and the physical position y of the laser plane
    281295function Fz=phys_scanz(Z,y)
     296% scale factor applied to Z depending on the physical position y of the laser plane
    282297Fz=(-1.4587*10^(-5)*y.^2 + 0.001072*y+0.0833).*Z; %+(-2.1*10^(-6)*x.^2+5.1*10^(-4)*x+0.0735).*Z;
    283298
    284299 
    285 
Note: See TracChangeset for help on using the changeset viewer.