Changeset 910 for trunk/src/uvmat.m
 Timestamp:
 Jun 13, 2015, 7:20:37 PM (8 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/src/uvmat.m
r909 r910 1469 1469 flag=1; 1470 1470 if ~isfield(UvData.Field,'A') 1471 1472 return1471 msgbox_uvmat('ERROR','an image needs to be opened to set the mask size'); 1472 return 1473 1473 end 1474 1474 npx=size(UvData.Field.A,2); … … 1477 1477 yi=0.5:npy0.5; 1478 1478 [Xi,Yi]=meshgrid(xi,yi); 1479 for iobj=1:length(UvData.ProjObject) 1480 ObjectData=UvData.ProjObject{iobj}; 1481 if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')isequal(ObjectData.ProjMode,'mask_outside')); 1482 flagobj=1; 1483 testphys=0; %coordinates in pixels by default 1484 if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel') 1485 if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') 1486 Calib=UvData.XmlData{1}.GeometryCalib; 1487 testphys=1; 1479 for iobj=1:length(UvData.ProjObject) 1480 ObjectData=UvData.ProjObject{iobj}; 1481 if isfield(ObjectData,'ProjMode') &&(isequal(ObjectData.ProjMode,'mask_inside')isequal(ObjectData.ProjMode,'mask_outside')); 1482 flagobj=1; 1483 testphys=0; %coordinates in pixels by default 1484 if isfield(ObjectData,'CoordUnit') && ~isequal(ObjectData.CoordUnit,'pixel') 1485 if isfield(UvData,'XmlData')&& isfield(UvData.XmlData{1},'GeometryCalib') 1486 Calib=UvData.XmlData{1}.GeometryCalib; 1487 testphys=1; 1488 end 1489 end 1490 if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type') 1491 if isequal(ObjectData.Type,'polygon') 1492 X=ObjectData.Coord(:,1); 1493 Y=ObjectData.Coord(:,2); 1494 if testphys 1495 pos=[X Y zeros(size(X))]; 1496 if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3 1497 if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0]) 1498 om=norm(Calib.SliceAngle);%norm of rotation angle in radians 1499 OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis 1500 cos_om=cos(pi*om/180); 1501 sin_om=sin(pi*om/180); 1502 pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1cos_om)*(OmAxis*pos')*OmAxis; 1503 end 1504 pos(:,1)=pos(:,1)+Calib.SliceCoord(1); 1505 pos(:,2)=pos(:,2)+Calib.SliceCoord(2); 1506 pos(:,3)=pos(:,3)+Calib.SliceCoord(3); 1507 end 1508 [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3)); 1488 1509 end 1510 flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside 1511 elseif isequal(ObjectData.Type,'ellipse') 1512 if testphys 1513 %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys 1514 end 1515 RangeX=max(ObjectData.RangeX); 1516 RangeY=max(ObjectData.RangeY); 1517 X2Max=RangeX*RangeX; 1518 Y2Max=RangeY*RangeY; 1519 distX=(XiObjectData.Coord(1,1)); 1520 distY=(YiObjectData.Coord(1,2)); 1521 flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; 1522 elseif isequal(ObjectData.Type,'rectangle') 1523 if testphys 1524 %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys 1525 end 1526 distX=abs(XiObjectData.Coord(1,1)); 1527 distY=abs(YiObjectData.Coord(1,2)); 1528 flagobj=distX>max(ObjectData.RangeX)  distY>max(ObjectData.RangeY); 1489 1529 end 1490 if isfield(ObjectData,'Coord')&& isfield(ObjectData,'Type') 1491 if isequal(ObjectData.Type,'polygon') 1492 X=ObjectData.Coord(:,1); 1493 Y=ObjectData.Coord(:,2); 1494 if testphys 1495 pos=[X Y zeros(size(X))]; 1496 if isfield(Calib,'SliceCoord') && length(Calib.SliceCoord)>=3 1497 if isfield(Calib,'SliceAngle')&&~isequal(Calib.SliceAngle,[0 0 0]) 1498 om=norm(Calib.SliceAngle);%norm of rotation angle in radians 1499 OmAxis=Calib.SliceAngle/om; %unit vector marking the rotation axis 1500 cos_om=cos(pi*om/180); 1501 sin_om=sin(pi*om/180); 1502 pos=cos_om*pos+sin_om*cross(OmAxis,pos)+(1cos_om)*(OmAxis*pos')*OmAxis; 1503 end 1504 pos(:,1)=pos(:,1)+Calib.SliceCoord(1); 1505 pos(:,2)=pos(:,2)+Calib.SliceCoord(2); 1506 pos(:,3)=pos(:,3)+Calib.SliceCoord(3); 1507 end 1508 [X,Y]=px_XYZ(Calib,pos(:,1),pos(:,2),pos(:,3)); 1509 end 1510 flagobj=~inpolygon(Xi,Yi,X',Y');%=0 inside the polygon, 1 outside 1511 elseif isequal(ObjectData.Type,'ellipse') 1512 if testphys 1513 %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys 1514 end 1515 RangeX=max(ObjectData.RangeX); 1516 RangeY=max(ObjectData.RangeY); 1517 X2Max=RangeX*RangeX; 1518 Y2Max=RangeY*RangeY; 1519 distX=(XiObjectData.Coord(1,1)); 1520 distY=(YiObjectData.Coord(1,2)); 1521 flagobj=(distX.*distX/X2Max+distY.*distY/Y2Max)>1; 1522 elseif isequal(ObjectData.Type,'rectangle') 1523 if testphys 1524 %[X,Y]=px_XYZ(Calib,X,Y,0);% TODO:create a polygon boundary and transform to phys 1525 end 1526 distX=abs(XiObjectData.Coord(1,1)); 1527 distY=abs(YiObjectData.Coord(1,2)); 1528 flagobj=distX>max(ObjectData.RangeX)  distY>max(ObjectData.RangeY); 1529 end 1530 if isequal(ObjectData.ProjMode,'mask_outside') 1531 flagobj=~flagobj; 1532 end 1533 flag=flag & flagobj; 1530 if isequal(ObjectData.ProjMode,'mask_outside') 1531 flagobj=~flagobj; 1534 1532 end 1535 end 1536 end 1533 flag=flag & flagobj; 1534 end 1535 end 1536 end 1537 1537 %mask name 1538 1538 RootPath=get(handles.RootPath,'String'); … … 1548 1548 imflag=uint8(255*(0.392+0.608*flag));% =100 for flag=0 (vectors not computed when 20<imflag<200) 1549 1549 imflag=flipdim(imflag,1); 1550 1550 1551 1551 %display the mask 1552 1552 hfigmask=figure; … … 1570 1570 end 1571 1571 end 1572 imwrite(imflag,answer,'BitDepth',8); 1572 try 1573 imwrite(imflag,answer,'BitDepth',8); 1574 catch ME 1575 msgbox_uvmat('ERROR',ME.message) 1576 end 1573 1577 end 1574 1578 set(handles.ListObject,'Value',1)
Note: See TracChangeset
for help on using the changeset viewer.