Changeset 836


Ignore:
Timestamp:
Dec 6, 2014, 4:42:43 PM (9 years ago)
Author:
sommeria
Message:

phys mofidifed. phys_ima put as an outside fct

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/transform_field/phys.m

    r810 r836  
    144144%% transform the scalar(s) or image(s)
    145145if iscalar~=0
    146     [A,Coord_x,Coord_y]=phys_Ima(A,Calib,ZIndex);%TODO : introduire interp2_uvmat ds phys_ima
     146    [A,Coord_x,Coord_y]=phys_ima(A,XmlData,ZIndex);%TODO : introduire interp2_uvmat ds phys_ima
    147147    if iscalar==1 && ~isempty(DataOut_1) % case for which only the second field is a scalar
    148148         DataOut_1.A=A{1};
     
    238238
    239239%%%%%%%%%%%%%%%%%%%%
    240 function [A_out,Rangx,Rangy]=phys_Ima(A,CalibIn,ZIndex)
    241 xcorner=[];
    242 ycorner=[];
    243 npx=[];
    244 npy=[];
    245 dx=ones(1,numel(A));
    246 dy=ones(1,numel(A));
    247 for icell=1:numel(A)
    248     siz=size(A{icell});
    249     npx=[npx siz(2)];
    250     npy=[npy siz(1)];
    251     Calib=CalibIn{icell};
    252     xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners
    253     yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];
    254     [xcorner_new,ycorner_new]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates
    255     dx(icell)=(max(xcorner_new)-min(xcorner_new))/(siz(2)-1);
    256     dy(icell)=(max(ycorner_new)-min(ycorner_new))/(siz(1)-1);
    257     xcorner=[xcorner xcorner_new];
    258     ycorner=[ycorner ycorner_new];
    259 end
    260 Rangx(1)=min(xcorner);
    261 Rangx(2)=max(xcorner);
    262 Rangy(2)=min(ycorner);
    263 Rangy(1)=max(ycorner);
    264 test_multi=(max(npx)~=min(npx)) || (max(npy)~=min(npy)); %different image lengths
    265 npX=1+round((Rangx(2)-Rangx(1))/min(dx));% nbre of pixels in the new image (use the finest resolution min(dx) in the set of images)
    266 npY=1+round((Rangy(1)-Rangy(2))/min(dy));
    267 x=linspace(Rangx(1),Rangx(2),npX);
    268 y=linspace(Rangy(1),Rangy(2),npY);
    269 [X,Y]=meshgrid(x,y);%grid in physical coordiantes
    270 %vec_B=[];
    271 A_out=cell(1,numel(A));
    272 for icell=1:length(A)
    273     Calib=CalibIn{icell};
    274     % rescaling of the image coordinates without change of the image array
    275     if strcmp(Calib.CalibrationType,'rescale') && isequal(Calib,CalibIn{1})
    276         A_out{icell}=A{icell};%no transform
    277         Rangx=[0.5 npx-0.5];%image coordiantes of corners
    278         Rangy=[npy-0.5 0.5];
    279         [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],ZIndex);%case of translations without rotation and quadratic deformation
    280         [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,ZIndex);
    281     else         
    282         % the image needs to be interpolated to the new coordinates
    283         zphys=0; %default
    284         if isfield(Calib,'SliceCoord') %.Z= index of plane
    285            SliceCoord=Calib.SliceCoord(ZIndex,:);
    286            zphys=SliceCoord(3); %to generalize for non-parallel planes
    287            if isfield(Calib,'InterfaceCoord') && isfield(Calib,'RefractionIndex')
    288                 H=Calib.InterfaceCoord(3);
    289                 if H>zphys
    290                     zphys=H-(H-zphys)/Calib.RefractionIndex; %corrected z (virtual object)
    291                 end
    292            end
    293         end
    294         xima=0.5:npx-0.5;%image coordinates of corners
    295         yima=npy-0.5:-1:0.5;
    296         [XIMA_init,YIMA_init]=meshgrid(xima,yima);%grid of initial image in px coordinates
    297         [XIMA,YIMA]=px_XYZ(CalibIn{icell},X,Y,zphys);% image coordinates for each point in the real
    298         %[XPHYS_init,YPHYS_init]=phys_XYZ(Calib,XIMA_init,YIMA_init,ZIndex);
    299         testuint8=isa(A{icell},'uint8');
    300         testuint16=isa(A{icell},'uint16');
    301         if ndims(A{icell})==2 %(B/W images)
    302         A_out{icell}=interp2(XIMA_init,YIMA_init,double(A{icell}),XIMA,YIMA);
    303 %         [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],ZIndex);%case of translations without rotation and quadratic deformation
    304 %         [XIMA_init,YIMA_init]=px_XYZ(CalibIn{icell},X,Y,zphys);% image coordinates for each point in the real space grid
    305 %         
    306 %         XIMA=reshape(round(XIMA),1,npX*npY);%indices reorganized in 'line'
    307 %         YIMA=reshape(round(YIMA),1,npX*npY);
    308 %         flagin=XIMA>=1 & XIMA<=npx(icell) & YIMA >=1 & YIMA<=npy(icell);%flagin=1 inside the original image
    309 
    310 %         if numel(siz)==2 %(B/W images)
    311 %             vec_A=reshape(A{icell},1,npx(icell)*npy(icell));%put the original image in line
    312 %             %ind_in=find(flagin);
    313 %             ind_out=find(~flagin);
    314 %             ICOMB=((XIMA-1)*npy(icell)+(npy(icell)+1-YIMA));
    315 %             ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
    316 %             %vec_B(ind_in)=vec_A(ICOMB);
    317 %             vec_B(flagin)=vec_A(ICOMB);
    318 %             vec_B(~flagin)=zeros(size(ind_out));
    319 % %             vec_B(ind_out)=zeros(size(ind_out));
    320 %             A_out{icell}=reshape(vec_B,npY,npX);%new image in real coordinates
    321          elseif ndims(A{icell})==3     
    322              for icolor=1:size(A{icell},3)
    323                  A{icell}=double(A{icell});
    324                  A_out{icell}(:,:,icolor)=interp2(XIMA_init,YIMA_init,A{icell}(:,:,icolor),XIMA,YIMA);
    325 %                 vec_A=reshape(A{icell}(:,:,icolor),1,npx*npy);%put the original image in line
    326 %                % ind_in=find(flagin);
    327 %                 ind_out=find(~flagin);
    328 %                 ICOMB=((XIMA-1)*npy+(npy+1-YIMA));
    329 %                 ICOMB=ICOMB(flagin);%index corresponding to XIMA and YIMA in the aligned original image vec_A
    330 %                 vec_B(flagin)=vec_A(ICOMB);
    331 %                 vec_B(~flagin)=zeros(size(ind_out));
    332 %                 A_out{icell}(:,:,icolor)=reshape(vec_B,npy,npx);%new image in real coordinates
    333              end
    334          end
    335         if testuint8
    336             A_out{icell}=uint8(A_out{icell});
    337         end
    338         if testuint16
    339             A_out{icell}=uint16(A_out{icell});
    340         end     
    341     end
    342 end
    343 
     240
Note: See TracChangeset for help on using the changeset viewer.