% % % 3D to 2D Projection 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::BP3Dto2DProjection(%i) % % % % % % Description: % % Resize the dataset to 2 dimensions. % 2 dialog boxes ask the projection plane XY, XZ or YZ) and the % projection mode (MIP or Mean) if their values are not specified % as input parameters. % % function BP3Dto2DProjection(aImarisApplicationID, aProjectionPlane, aProjectionMode) % vImarisApplication = actxserver('Imaris.Application'); vImarisApplication.mVisible = true; if isa(aImarisApplicationID, 'COM.Imaris_Application') vImarisApplication = aImarisApplicationID; else % connect to Imaris Com interface vImarisServer = actxserver('ImarisServer.Server'); vImarisApplication = vImarisServer.GetObject(aImarisApplicationID); end vImarisApplication.DataSetPushUndo('Projection to 2D'); % get the data set vDataSet = vImarisApplication.mDataSet.Clone; vNumberOfTimePoints = vDataSet.mSizeT; vNumberOfChannels = vDataSet.mSizeC; % projection plane vPlaneNames = ['XY'; 'XZ'; 'YZ']; if nargin<2 [vAnswer, vOk] = listdlg('ListString',{vPlaneNames},... 'SelectionMode','single',... 'ListSize',[200 50],... 'Name','3D to 2D Projection',... 'PromptString',{'Please select the projection plane:'}); if vOk<1 return; end vProjectionPlane = vAnswer; else vProjectionPlane = aProjectionPlane; end vProjectionAxis = 4-vProjectionPlane; % MIP or Mean projection if nargin<3 vAnswer = questdlg('Please select the projection mode:', '3D to 2D Projection', ... 'MIP', 'Mean','Cancel', 'MIP'); if strcmp(vAnswer, 'Cancel') return; else vProjectionMode = vAnswer; end else vProjectionMode = aProjectionMode; end vTotalCount = vNumberOfChannels*vNumberOfTimePoints; vProgressDisplay = waitbar(0,['Projecting to ',vPlaneNames(vProjectionPlane,:),'-plane']); vProgressCount = 0; vImage = zeros(vDataSet.mSizeX,vDataSet.mSizeY,vDataSet.mSizeZ); if strcmp(vDataSet.mType,'eTypeUInt8') vImage = uint8(vImage); elseif strcmp(vDataSet.mType, 'eTypeUInt16') vImage = uint16(vImage); elseif strcmp(vDataSet.mType, 'eTypeFloat') vImage = single(vImage); end for vChannelIndex = 1:vNumberOfChannels for vTimeIndex = 1:vNumberOfTimePoints for vSlice = 1:vDataSet.mSizeZ vImage(:,:,vSlice) = vDataSet.GetDataSlice( ... vSlice-1,vChannelIndex-1,vTimeIndex-1); end if strcmp(vProjectionMode, 'MIP') % MIP vImageSlice = max(vImage, [], vProjectionAxis); else % Mean vImageSlice = mean(vImage, vProjectionAxis); end % original size must be preserved because resizing the first layer % would resize every layer (losing data) switch vProjectionPlane case 1, vImage(:,:,1) = vImageSlice; case 2, vImage(:,1,:) = vImageSlice; case 3, vImage(1,:,:) = vImageSlice; end vProgressCount = vProgressCount + 1; waitbar(vProgressCount/vTotalCount) vDataSet.SetDataVolume(vImage,vChannelIndex-1,vTimeIndex-1); end end % resize layers switch vProjectionPlane case 1, vDataSet.mSizeZ = 1; case 2, vDataSet.mSizeY = 1; case 3, vDataSet.mSizeX = 1; end vImarisApplication.mDataSet = vDataSet; close(vProgressDisplay);