Changeset 697 for trunk


Ignore:
Timestamp:
Nov 6, 2013, 10:52:01 PM (10 years ago)
Author:
sommeria
Message:

bug corrected in geometry_calib: more precise determination ofcalib points
xml2struct corrected to work in background

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/geometry_calib.m

    r696 r697  
    848848corners_Y=(Coord(end:-1:end-3,5));
    849849
     850%%%%%%
     851%   corners_X=1000*[1.5415  1.7557 1.7539 1.5415]';
     852%   corners_Y=1000*[1.1515 1.1509 1.3645  1.3639]';
     853
    850854%reorder the last two points (the two first in the list) if needed
    851855angles=angle((corners_X-corners_X(1))+1i*(corners_Y-corners_Y(1)));
     
    859863end
    860864
    861 %% initiate the grid
     865%% initiate the grid in phys coordinates
    862866CalibData=get(handles.geometry_calib,'UserData');%get information stored on the GUI geometry_calib
    863867grid_input=[];%default
     
    867871[T,CalibData.grid,CalibData.grid.CheckWhite]=create_grid(grid_input,'detect_grid');%display the GUI create_grid, read the set of phys coordinates T
    868872set(handles.geometry_calib,'UserData',CalibData)%store the phys grid parameters for later use
     873X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
     874Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
    869875
    870876%% read the current image, displayed in the GUI uvmat
     
    873879A=UvData.Field.A;%currently displayed image
    874880npxy=size(A);
    875 X=[CalibData.grid.x_0 CalibData.grid.x_1 CalibData.grid.x_0 CalibData.grid.x_1]';%corner absissa in the phys coordinates (cm)
    876 Y=[CalibData.grid.y_0 CalibData.grid.y_0 CalibData.grid.y_1 CalibData.grid.y_1]';%corner ordinates in the phys coordinates (cm)
    877 
    878 %calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
     881
     882%% calculate transform matrices for plane projection: rectangle assumed to be viewed in perspective
    879883% reference: http://alumni.media.mit.edu/~cwren/interpolator/ by Christopher R. Wren
    880884B = [ X Y ones(size(X)) zeros(4,3)        -X.*corners_X -Y.*corners_X ...
     
    887891C = [l(7:8)' 1];
    888892
    889 % transform grid image into 'phys' coordinates
     893%% transform grid image into 'phys' coordinates
    890894GeometryCalib.CalibrationType='3D_linear';
    891895GeometryCalib.fx_fy=[1 1];
     
    908912DataOut=phys(Data,Calib);
    909913rmpath(fullfile(path_UVMAT,'transform_field'))
    910 Amod=DataOut.A;% current imgage expressed in 'phys' coord
    911 Rangx=DataOut.AX;
    912 Rangy=DataOut.AY;
     914Amod=DataOut.A;% current image expressed in 'phys' coord
     915Rangx=DataOut.AX;% x coordinates of first and last pixel centres in phys
     916Rangy=DataOut.AY;% y coordinates of first and last pixel centres in phys
    913917if CalibData.grid.CheckWhite
    914918    Amod=double(Amod);%case of white grid markers: will look for image maxima
     
    923927ind_range_y=ceil(abs(GeometryCalib.R(2,2)*CalibData.grid.Dy/3));% range of search of image ma around each point obtained by linear interpolation from the marked points
    924928nbpoints=size(T,1);
    925 %lokk for image maxima around each expected pgrid point
     929TIndex=ones(size(T));% image indices corresponding to point coordinates
     930%look for image maxima around each expected grid point
    926931for ipoint=1:nbpoints
    927     i0=1+round((T(ipoint,1)-Rangx(1))/Dx);%round(Xpx(ipoint));
    928     j0=1+round((T(ipoint,2)-Rangy(1))/Dy);%round(Xpx(ipoint));
    929     j0min=max(j0-ind_range_y,1);
    930     j0max=min(j0+ind_range_y,size(Amod,1));
    931     i0min=max(i0-ind_range_x,1);
    932     i0max=min(i0+ind_range_x,size(Amod,2));
    933     Asub=Amod(j0min:j0max,i0min:i0max);
    934  
    935 
    936    
     932    i0=1+round((T(ipoint,1)-Rangx(1))/Dx);% x index of the expected point in the phys image Amod
     933    j0=1+round((T(ipoint,2)-Rangy(1))/Dy);% y index of the expected point in the phys image Amod
     934    j0min=max(j0-ind_range_y,1);% min y index selected for the subimage (cut at the edge to avoid index <1)
     935    j0max=min(j0+ind_range_y,size(Amod,1));% max y index selected for the subimage (cut at the edge to avoid index > size)
     936    i0min=max(i0-ind_range_x,1);% min x index selected for the subimage (cut at the edge to avoid index <1)
     937    i0max=min(i0+ind_range_x,size(Amod,2));% max x index selected for the subimage (cut at the edge to avoid index > size)
     938    Asub=Amod(j0min:j0max,i0min:i0max); %subimage used to find brigthness extremum
    937939    x_profile=sum(Asub,1);%profile of subimage summed over y
    938940    y_profile=sum(Asub,2);%profile of subimage summed over x
    939     %%%%
    940 %     if ipoint==5
    941 %                 figure(10)
    942 %   imagesc(Asub)
    943 %     figure(11)
    944 %     plot(x_profile,'r')
    945 %     hold on
    946 %     plot(y_profile,'b')
    947 %     end
    948     %%%%
    949     [tild,ind_x_max]=max(x_profile);
    950     [tild,ind_y_max]=max(y_profile);
     941
     942    [tild,ind_x_max]=max(x_profile);% index of max for the x profile
     943    [tild,ind_y_max]=max(y_profile);% index of max for the y profile
    951944    %sub-pixel improvement using moments
    952945    x_shift=0;
     
    960953        y_shift=sum(Atop.*[-2 -1 0 1 2]')/sum(Atop);
    961954    end
    962     Delta(ipoint,1)=(i0min+ind_x_max-1+x_shift-i0)*Dx;%shift from the initial guess
    963     Delta(ipoint,2)=(j0min+ind_y_max-1+y_shift-j0)*Dy;
    964 end
    965 Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points
    966 Tmod(:,2)=flipdim(Tmod(:,2),1);% inverse the order of y coordinates
     955        %%%%
     956%     if ipoint==9
     957%                 figure(11)
     958%   imagesc(Asub)
     959%     figure(12)
     960%     plot(x_profile,'r')
     961%     hold on
     962%     plot(y_profile,'b')
     963%     grid on
     964%     end
     965    %%%%
     966    TIndex(ipoint,1)=(i0min+ind_x_max-1+x_shift);% x position of the maximum (in index of Amod)
     967    TIndex(ipoint,2)=(j0min+ind_y_max-1+y_shift);% y position of the maximum (in index of Amod)
     968end
     969Tmod(:,1)=(TIndex(:,1)-1)*Dx+Rangx(1);
     970Tmod(:,2)=(TIndex(:,2)-1)*Dy+Rangy(1);
     971%Tmod=T(:,(1:2))+Delta;% 'phys' coordinates of the detected points
    967972[Xpx,Ypx]=px_XYZ(GeometryCalib,Tmod(:,1),Tmod(:,2));% image coordinates of the detected points
    968973Coord=[T Xpx Ypx zeros(size(T,1),1)];
     
    970975PLOT_Callback(hObject, eventdata, handles)
    971976set(handles.APPLY,'BackgroundColor',[1 0 1])
     977
     978% figure(10)
     979% hold off
     980% imagesc(Rangx,Rangy,Amod)
     981% hold on
     982% plot(Tmod(:,1),Tmod(:,2),'+')
     983
    972984
    973985%-----------------------------------------------------------------------
  • trunk/src/xml2struct.m

    r687 r697  
    6060        end
    6161    case 'char'
    62         out=ss; %reproduce the input string
    6362        % try to convert to number if the char does not correspond to a function (otherwise str2num calls this function as it uses 'eval')
    6463        if ~isempty(regexp(ss,'^(-*\d+\.*\d*\ *)+$')) || ~isempty(regexp(ss,'\d+e(-|+)\d+')) % if the string corresponds to a set of numbers (with possible sign and decimal, or scientific notation) separated by blanks
     
    6867            if ~isempty(sep_ind)
    6968                sep_ind=[-2 sep_ind length(ss)+1];
     69                out={};
    7070                for icolumn=1:length(sep_ind)-1
    71                     out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);
     71                    out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1);% get info between separators as a cell array
    7272                end
    7373            else
     
    7676        end
    7777    case 'cell'
    78         out=[];%default
     78        out={};%default
    7979        check_numeric=zeros(size(ss));
    8080        for ilist=1:numel(ss)
Note: See TracChangeset for help on using the changeset viewer.