% % % Spots Split Into Surface Objects Function for Imaris % % Copyright Bitplane AG 2006 % % % Installation: % % - Copy this file into the XTensions folder in the Imaris installation directory. % - You will find this function in the Image Processing menu % % % % % % Matlab::BPSpotsSplitIntoSurfaceObjects(%i) % % % % % % % Matlab::BPSpotsSplitIntoSurfaceObjects(%i) % % % % % % % Description: % % For each surface object in the same folder of the spots, create a new % spots object containing the spots that lies inside the surface. % Works on surface objects: To obtain them, Split Isosurface or % Create Surface Object from Contour Surface. % % function BPSpotsSplitIntoSurfaceObjects(aImarisApplicationID) % connect to Imaris Com interface if ~isa(aImarisApplicationID, 'COM.Imaris_Application') vImarisServer = actxserver('ImarisServer.Server'); vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); else vImarisApplication = aImarisApplicationID; end vImarisApplication.DataSetPushUndo('Spots Split Into Surface Objects'); % the user has to create a scene with some spots vSurpassScene = vImarisApplication.mSurpassScene; if isequal(vSurpassScene, []) msgbox('Please create some Spots in the Surpass scene!'); return; end % get the spots vSpots = vImarisApplication.mFactory.ToSpots(vImarisApplication.mSurpassSelection); if ~vImarisApplication.mFactory.IsSpots(vSpots) msgbox('Please select some Spots!'); return; end % get the spots coordinates [vSpotsXYZ,vSpotsTime,vSpotsRadius] = vSpots.Get; vNumberOfSpots = length(vSpotsRadius); vSpotsName = vSpots.mName; vSpots.mVisible = false; % get the parent group vParentGroup = vSpots.GetParent; % mask volume vMin = min(vSpotsXYZ); vMax = max(vSpotsXYZ); % add 4% border to be sure to include all spots (avoid edge effects) vDelta = vMax-vMin; vMin = vMin-vDelta*0.02; vMax = vMax+vDelta*0.02; vMaskSize = 350; vMaxMaskSize = vMaskSize/max(vMax-vMin); % spots coordinates on the mask vSpotsOnMaskXYZ(:,1) = ceil((vSpotsXYZ(:,1)-vMin(1))*vMaxMaskSize); vSpotsOnMaskXYZ(:,2) = ceil((vSpotsXYZ(:,2)-vMin(2))*vMaxMaskSize); vSpotsOnMaskXYZ(:,3) = ceil((vSpotsXYZ(:,3)-vMin(3))*vMaxMaskSize); % the zeros belongs to the first interval vSpotsOnMaskXYZ = max(vSpotsOnMaskXYZ,1); vMaskSize = max(vSpotsOnMaskXYZ); vProgressDisplay = waitbar(0,'Splitting spots into isosurfaces'); % loop over the children of the parent looking for the isosurfaces vNumberOfChildren = vParentGroup.GetNumberOfChildren; for vChildIndex = 1:vNumberOfChildren vDataItem = vParentGroup.GetChild(vChildIndex - 1); if vImarisApplication.mFactory.IsSurface(vDataItem) vSurface = vDataItem; vMask = vSurface.GetMask(vMin(1), vMin(2), vMin(3), vMax(1), vMax(2), vMax(3),... vMaskSize(1), vMaskSize(2), vMaskSize(3)); % search the element of the spot that lies inside the surface vIndexSpotsInside = []; vNumberOfSpotsInside = 0; for vSpotsIndex = 1:vNumberOfSpots vSlice = vMask.GetDataSlice(vSpotsOnMaskXYZ(vSpotsIndex,3)-1, 0, 0); if vSlice(vSpotsOnMaskXYZ(vSpotsIndex,1),... vSpotsOnMaskXYZ(vSpotsIndex,2))==1 vNumberOfSpotsInside = vNumberOfSpotsInside+1; vIndexSpotsInside(vNumberOfSpotsInside) = vSpotsIndex; end end vSpotsInside = vImarisApplication.mFactory.CreateSpots; if vNumberOfSpotsInside>0 vSpotsInside.Set(vSpotsXYZ(vIndexSpotsInside,:),vSpotsTime(vIndexSpotsInside),... vSpotsRadius(vIndexSpotsInside)); end vSpotsInside.mName = sprintf('%s inside %s', vSpotsName, vSurface.mName); vSpotsInside.SetColor(0.0, 1.0, 0.0, 0.0); vParentGroup.AddChild(vSpotsInside); end waitbar(vChildIndex/vNumberOfChildren); end close(vProgressDisplay);