% % % Filament Split Into Branches 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::BPFilamentSplitIntoBranches(%i) % % % % % % % Matlab::BPFilamentSplitIntoBranches(%i) % % % % % % % Description: % % Split one filament object in different filaments. % The new filaments go from the root to a terminal of the original % filament and they do not have branches. % The number of filaments created is equal to the number of terminals % of the original filament. % function BPFilamentSplitIntoBranches(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 spots coordinates [vFilamentXYZ, vFilamentRadius, vFilamentEdges] = vFilament.Get; vNumberOfSpots = length(vFilamentRadius); % find the terminals vNumberOfTerminals = 0; vTerminals = []; vProgressDisplay = waitbar(0, 'Splitting filament into branches'); for vSpots = 1:vNumberOfSpots vEdge = find(vFilamentEdges==vSpots-1); if length(vEdge)==1 vNumberOfTerminals = vNumberOfTerminals + 1; vTerminals(vNumberOfTerminals) = vSpots; end end waitbar(0.3); vParent = vImarisApplication.mFactory.CreateDataContainer; vParent.mName = sprintf('%s Branches', vFilament.mName); vFilament.GetParent.AddChild(vParent); vFilament.mVisible = 0; % get the jet colormap vColorMap = jet; vColorMapSize = size(vColorMap,1); % close the figure opened by jet close; for vTerminalIndex = 1:vNumberOfTerminals vLength = 1; vTerminal = vTerminals(vTerminalIndex); vPath = vTerminal; vFound = true; while vFound [vEdge, vSide] = find(vFilamentEdges==vTerminal-1); vFound = false; for vNeighborIndex = 1:length(vEdge) vNeighbor = vFilamentEdges(vEdge(vNeighborIndex), 3-vSide(vNeighborIndex))+1; if vNeighbor root-terminal vPath = fliplr(vPath); vNewFilament = vImarisApplication.mFactory.CreateFilament; vNewFilament.mIndexT = vImarisApplication.mVisibleIndexT; vNewFilament.Set(vFilamentXYZ(vPath,:),vFilamentRadius(vPath), ... [0:vLength-2;1:vLength-1]'); vNewFilament.mName = sprintf('%s [branch %i]', vFilament.mName, vTerminalIndex); % computes the color vPercent = (vTerminalIndex-1)/max(vNumberOfTerminals-1,1)*(vColorMapSize-1)+1; vFloor = floor(vPercent); vColor = vColorMap(vFloor,:); if vFloor