Changeset 1078 for trunk/src/phys_ima.m


Ignore:
Timestamp:
Mar 30, 2020, 3:48:19 PM (4 years ago)
Author:
sommeria
Message:

various updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/phys_ima.m

    r972 r1078  
    2222    XmlData={XmlData};
    2323end
     24
    2425for icell=1:numel(A)
    2526    siz=size(A{icell});
     
    2728    npy=[npy siz(1)];
    2829    Calib=XmlData{icell}.GeometryCalib;
    29     xima=[0.5 siz(2)-0.5 0.5 siz(2)-0.5];%image coordinates of corners
    30     yima=[0.5 0.5 siz(1)-0.5 siz(1)-0.5];
    31     [xcorner_new,ycorner_new]=phys_XYZ(Calib,xima,yima,ZIndex);%corresponding physical coordinates
     30    coord_x=[0.5 siz(2)-0.5];
     31    coord_y=[0.5 siz(1)-0.5];
     32    x_edge=[linspace(coord_x(1),coord_x(end),npx(icell)) coord_x(end)*ones(1,npy(icell))...
     33        linspace(coord_x(end),coord_x(1),npx(icell)) coord_x(1)*ones(1,npy(icell))];%x coordinates of the image edge(four sides)
     34    y_edge=[coord_y(1)*ones(1,npx(icell)) linspace(coord_y(1),coord_y(end),npy(icell))...
     35        coord_y(end)*ones(1,npx(icell)) linspace(coord_y(end),coord_y(1),npy(icell))];%y coordinates of the image edge(four sides)
     36    [xcorner_new,ycorner_new]=phys_XYZ(Calib,x_edge,y_edge,ZIndex);%corresponding physical coordinates
    3237    dx(icell)=(max(xcorner_new)-min(xcorner_new))/(siz(2)-1);
    3338    dy(icell)=(max(ycorner_new)-min(ycorner_new))/(siz(1)-1);
     
    4045Rangy(1)=max(ycorner);
    4146test_multi=(max(npx)~=min(npx)) || (max(npy)~=min(npy)); %different image lengths
    42 % 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)
    43 % npY=1+round((Rangy(1)-Rangy(2))/min(dy));
    4447
    4548npX=1+round((Rangx(2)-Rangx(1))/max(dx));% nbre of pixels in the new image (use the largest resolution max(dx) in the set of images)
    4649npY=1+round((Rangy(1)-Rangy(2))/max(dy));
    4750
    48 
    4951x=linspace(Rangx(1),Rangx(2),npX);
    5052y=linspace(Rangy(1),Rangy(2),npY);
    51 [X,Y]=meshgrid(x,y);%grid in physical coordiantes
    52 %vec_B=[];
     53[X,Y]=meshgrid(x,y);%grid in physical coordinates
    5354A_out=cell(1,numel(A));
    54 for icell=1:length(A)
     55
     56for icell=1:length(A)
    5557    Calib=XmlData{icell}.GeometryCalib;
    5658    % rescaling of the image coordinates without change of the image array
     
    6062        Rangy=[npy-0.5 0.5];
    6163        [Rangx]=phys_XYZ(Calib,Rangx,[0.5 0.5],ZIndex);%case of translations without rotation and quadratic deformation
    62         [xx,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,ZIndex);
     64        [~,Rangy]=phys_XYZ(Calib,[0.5 0.5],Rangy,ZIndex);
    6365    else
    6466        % the image needs to be interpolated to the new coordinates
    65         zphys=0; %default
     67        Z=0; %default
    6668        if isfield(Calib,'SliceCoord') %.Z= index of plane
    6769            SliceCoord=Calib.SliceCoord(ZIndex,:);
    68             zphys=SliceCoord(3); %to generalize for non-parallel planes
    69             if isfield(Calib, 'SliceAngle') && ~isequal(Calib.SliceAngle,[0 0 0]) && ~isequal(Calib.SliceAngle(ZIndex,:),[0 0 0])
    70                 testangle=1;
    71                 om=norm(Calib.SliceAngle(ZIndex,:));%norm of rotation angle in radians
    72                 OmAxis=Calib.SliceAngle(ZIndex,:)/om; %unit vector marking the rotation axis
    73                 cos_om=cos(pi*om/180);
    74                 sin_om=sin(pi*om/180);
    75                 coeff=OmAxis(3)*(1-cos_om);
    76                 norm_plane(1)=OmAxis(1)*coeff+OmAxis(2)*sin_om;
    77                 norm_plane(2)=OmAxis(2)*coeff-OmAxis(1)*sin_om;
    78                 norm_plane(3)=OmAxis(3)*coeff+cos_om;
    79                 %Z0=norm_plane*Calib.SliceCoord(ZIndex,:)'/norm_plane(3);
    80                 Z0=Calib.SliceCoord(ZIndex,3);
    81                 zphys=Z0-(norm_plane(1)*X-norm_plane(2)*Y)/norm_plane(3);
     70            Z=SliceCoord(3);
     71            if isfield(Calib, 'SliceAngle') && size(Calib.SliceAngle,1)>=ZIndex && ~isequal(Calib.SliceAngle(ZIndex,:),[0 0 0])
     72                norm_plane=angle2normal(Calib.SliceAngle(ZIndex,:));
     73                Z=Z-(norm_plane(1)*(X-SliceCoord(1))+norm_plane(2)*(Y-SliceCoord(2)))/norm_plane(3);
    8274            end
    83 %             if isfield(Calib,'InterfaceCoord') && isfield(Calib,'RefractionIndex')
    84 %                 H=Calib.InterfaceCoord(3);
    85 %                 if H>zphys
    86 %                     zphys=H-(H-zphys)/Calib.RefractionIndex; %corrected z (virtual object)
    87 %                 end
    88 %             end
    8975        end
    9076        xima=0.5:npx(icell)-0.5;%image coordinates of corners
    9177        yima=npy(icell)-0.5:-1:0.5;
    9278        [XIMA_init,YIMA_init]=meshgrid(xima,yima);%grid of initial image in px coordinates
    93         [XIMA,YIMA]=px_XYZ(XmlData{icell}.GeometryCalib,X,Y,zphys);% image coordinates for each point in the real
     79        [XIMA,YIMA]=px_XYZ(XmlData{icell}.GeometryCalib,X,Y,Z);% image coordinates for each point in the real
    9480        testuint8=isa(A{icell},'uint8');
    9581        testuint16=isa(A{icell},'uint16');
    96         if ndims(A{icell})==2 %(B/W images)
    97         A_out{icell}=interp2(XIMA_init,YIMA_init,double(A{icell}),XIMA,YIMA);
    98          elseif ndims(A{icell})==3     
    99              for icolor=1:size(A{icell},3)
    100                  A{icell}=double(A{icell});
    101                  A_out{icell}(:,:,icolor)=interp2(XIMA_init,YIMA_init,A{icell}(:,:,icolor),XIMA,YIMA);
    102              end
    103          end
     82        if ismatrix(A{icell}) %(B/W images)
     83            A_out{icell}=interp2(XIMA_init,YIMA_init,double(A{icell}),XIMA,YIMA);
     84        elseif ndims(A{icell})==3
     85            for icolor=1:size(A{icell},3)
     86                A{icell}=double(A{icell});
     87                A_out{icell}(:,:,icolor)=interp2(XIMA_init,YIMA_init,A{icell}(:,:,icolor),XIMA,YIMA);
     88            end
     89        end
    10490        if testuint8
    10591            A_out{icell}=uint8(A_out{icell});
     
    10793        if testuint16
    10894            A_out{icell}=uint16(A_out{icell});
    109         end     
     95        end
    11096    end
    11197end
Note: See TracChangeset for help on using the changeset viewer.