% % % Filament Split Branch Levels 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::BPFilamentSplitBranchLevels(%i) % % % % % % % Matlab::BPFilamentSplitBranchLevels(%i) % % % % % % % Description: % % Split one filament object in different filaments. % The branches directly connected to the root are first-level branches; % The branches directly connected to the first-level branches are % second-level branches; and so on. % For each level, a new filament object, which collects the branches of % the level, is created. % The number of filaments created is equal to the maximal level of the % branches of the original filament. % % function BPFilamentSplitBranchLevels(aImarisApplicationID) % connect to Imaris Com interface if ~isa(aImarisApplicationID, 'COM.Imaris_Application') vImarisServer = actxserver('ImarisServer.Server'); vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); else vImarisApplication = aImarisApplicationID; end % get the filament vFilament = vImarisApplication.mFactory.ToFilament(vImarisApplication.mSurpassSelection); % search the filament if not previously selected vSurpassScene = vImarisApplication.mSurpassScene; if ~vImarisApplication.mFactory.IsFilament(vFilament) for vChildIndex = 1:vSurpassScene.GetNumberOfChildren vDataItem = vSurpassScene.GetChild(vChildIndex - 1); if vImarisApplication.mFactory.IsFilament(vDataItem) vFilament = vDataItem; break; end end % did we find the filament? if isequal(vFilament, []) msgbox('Please create some filament!'); return; end end % get the filament coordinates [vFilamentXYZ,vFilamentRadius,vFilamentEdges] = vFilament.Get; % new spots indices vSpotsIndex = 1; % level of each spot vSpotsLevel = 1; % index of the spots in the new subgroup vNewLabel = 1; % number of spots in each group vLabelHeight = 1; % total number of spots vNumberOfSpots = 1; vProgressDisplay = waitbar(0,'Splitting the filament'); vNumberOfEdges = size(vFilamentEdges,1); for vEdgeIndex = 1:vNumberOfEdges vEdge = vFilamentEdges(vEdgeIndex,:)+1; vRootFirst = find(vSpotsIndex==vEdge(1)); vRootSecond = find(vSpotsIndex==vEdge(2)); vFound = false; if isempty(vRootFirst) && length(vRootSecond)==1 vSpot = vEdge(1); vLevel = vSpotsLevel(vRootSecond); vFound = true; elseif length(vRootFirst)==1 && isempty(vRootSecond) vSpot = vEdge(2); vLevel = vSpotsLevel(vRootFirst); vFound = true; end if vFound vNumberOfSpots = vNumberOfSpots+1; vSpotsIndex(vNumberOfSpots) = vSpot; [vEdge, vSide] = find(vFilamentEdges==vSpot-1); if length(vEdge)>2 % is branch? vLevel = vLevel+1; end vSpotsLevel(vNumberOfSpots) = vLevel; if vLevel>numel(vLabelHeight) vLabelHeight(vLevel) = 1; else vLabelHeight(vLevel) = vLabelHeight(vLevel)+1; end vNewLabel(vNumberOfSpots) = vLabelHeight(vLevel); end waitbar(vEdgeIndex/vNumberOfEdges) end vEdgesLevel = 1:vNumberOfEdges; vNewEdges = vFilamentEdges; for vEdgeIndex = 1:vNumberOfEdges vEdge = vFilamentEdges(vEdgeIndex,:)+1; if vSpotsLevel(vEdge(1))==vSpotsLevel(vEdge(2)) vEdgesLevel(vEdgeIndex) = vSpotsLevel(vEdge(1)); %vNewEdges = [vNewEdges; vNewLabel(vEdge)-1]; vNewEdges(vEdgeIndex,:) = vNewLabel(vEdge)-1; else vEdgesLevel(vEdgeIndex) = -1; end end close(vProgressDisplay); vParent = vImarisApplication.mFactory.CreateDataContainer; vParent.mName = sprintf('%s Branch Levels', vFilament.mName); vFilament.GetParent.AddChild(vParent); % get the jet colormap vColorMap = jet; vColorMapSize = size(vColorMap,1); % close the figure opened by jet close; vNumberOfBranches = max(vSpotsLevel); for vBranchLevel = 1:vNumberOfBranches vNewFilament = vImarisApplication.mFactory.CreateFilament; vNewFilament.mIndexT = vImarisApplication.mVisibleIndexT; vThisSpots = vSpotsIndex(vSpotsLevel==vBranchLevel); vNewFilament.Set(vFilamentXYZ(vThisSpots,:),vFilamentRadius(vThisSpots), ... vNewEdges(vEdgesLevel==vBranchLevel,:)); vNewFilament.mName = sprintf('%s [level %i]', vFilament.mName, vBranchLevel); % computes the color vPercent = (vBranchLevel-1)/max(vNumberOfBranches-1,1)*(vColorMapSize-1)+1; vFloor = floor(vPercent); vColor = vColorMap(vFloor,:); if vFloor