function varargout = mergeRoiTool(varargin) % ROITOOL MATLAB code for mergeRoiTool.fig % ROITOOL, by itself, creates a new ROITOOL or raises the existing % singleton*. % % H = mergeRoiTool returns the handle to a new mergeRoiTool or the handle to % the existing singleton*. % % mergeRoiTool('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in mergeRoiTool.M with the given input arguments. % % mergeRoiTool('Property','Value',...) creates a new mergeRoiTool or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before mergeRoiTool_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to mergeRoiTool_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % set global variable mergeDebugVerbosity to >0 if you want more debug % % See also: GUIDE, GUIDATA, GUI % Edit the above text to modify the response to help mergeRoiTool % Last Modified by GUIDE v2.5 10-Apr-2024 08:12:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @mergeRoiTool_OpeningFcn, ... 'gui_OutputFcn', @mergeRoiTool_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before mergeRoiTool is made visible. function mergeRoiTool_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to mergeRoiTool (see VARARGIN) % Choose default command line output for mergeRoiTool global mergeDebugVerbosity if isempty(mergeDebugVerbosity) handles.debug=0; else handles.debug=mergeDebugVerbosity; end handles.output = hObject; handles.needsReload = 1; handles.roi = struct; handles.roiCoords = struct; handles.lungGridSize = -1; % Update handles structure guidata(hObject, handles); % This sets up the initial plot - only do when we are invisible % so window can get raised using mergeRoiTool. set(handles.progressAxes,'XTick',0,'YTick',0); %{ if strcmp(get(hObject,'Visible'),'off') plot(rand(5)); end %} % UIWAIT makes mergeRoiTool wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = mergeRoiTool_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % --- Executes on button press in pushbutton_save. function pushbutton_save_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_save (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) lungMatrix = handles.lungMatrix; savePath = [handles.path '/mergeLungROI']; fname = handles.curName; if exist(savePath,'dir') ~= 7 mkdir(savePath); end try save([savePath '/mergeLung-' fname '.mat'],'lungMatrix') set(handles.checkbox_saved,'Value',1,'BackgroundColor','g'); axes(handles.axes1); %warn('here') h = imagesc([0 0; 0 0]); %set(h,'HitTest','off') %get(h); %set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) handles.needsReload = 1; msgbox('ROI Saved Successfully'); catch h = warndlg('Save failed. Nothing saved'); end guidata(hObject, handles); %% old save function %{ roi = handles.roi; roiCoords = handles.roiCoords; if (~checkReload(hObject,handles)) elseif (max(roi.liver(:)) == 0 ... || max(roi.muscle(:)) == 0 ... || get(handles.checkbox_liver,'Value') == 0 ... || get(handles.checkbox_musc,'Value') == 0 ) h = warndlg('One of the ROIs is all zero or hasn''t been performed. Nothing saved'); else savePath = [handles.path '/ROI']; fname = handles.curName; if exist(savePath,'dir') ~= 7 mkdir(savePath); end try save([savePath '/liver-' fname '.mat'],'roi','roiCoords') set(handles.checkbox_saved,'Value',1,'BackgroundColor','g'); axes(handles.axes1); warn('here') h = imagesc([0 0; 0 0]) %set(h,'HitTest','off') get(h) %set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) handles.needsReload = 1; msgbox('ROI Saved Successfully') catch h = warndlg('Save failed. Nothing saved'); end end guidata(hObject, handles); %} % end old save function %popup_sel_index = get(handles.popupmenu1, 'Value'); %{ switch popup_sel_index case 1 plot(rand(5)); case 2 plot(sin(1:0.01:25.99)); case 3 bar(1:.5:10); case 4 plot(membrane); case 5 surf(peaks); end %} % -------------------------------------------------------------------- function FileMenu_Callback(hObject, eventdata, handles) % hObject handle to FileMenu (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % -------------------------------------------------------------------- function OpenMenuItem_Callback(hObject, eventdata, handles) % hObject handle to OpenMenuItem (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %[file, path] = uigetfile('*'); %try % img = dicomread([path file]); % nfo = dicominfo([path file]); %catch % disp('Not a dicom'); %end if( ~isfield(handles, 'path') ) path = uigetdir(); else path = uigetdir(handles.path); end handles.path = path; handles.needsReload = 1; files = dir(path); dcmlist = struct; setProgress(hObject, eventdata, handles,0,'Loading...'); for n=3:length(files); fp = [path '/' files(n).name]; if ~files(n).isdir && isdicom(fp) && (isempty(strfind(files(n).name,'XX')) && isempty(strfind(files(n).name,'PS'))) nfo=dicominfo(fp); dcmlist(end+1).path = fp; dcmlist(end).fname = files(n).name; dcmlist(end).protocol = nfo.ProtocolName; end setProgress(hObject, eventdata, handles,n/length(files),[]); end setProgress(hObject, eventdata, handles,1,'Finished'); if length(dcmlist) < 1 error('no dicoms found'); else dcmlist = dcmlist(2:end); end % prep the listbox for n=1:length(dcmlist) fileStrings{n} = dcmlist(n).protocol; end set(handles.listbox1,'String',fileStrings); handles.roi.liver = 0; handles.roi.muscle = 0; set(handles.checkbox_liver,'Value',0,'BackgroundColor','r'); set(handles.checkbox_musc,'Value',0,'BackgroundColor','r'); set(handles.checkbox_saved,'Value',0,'BackgroundColor','r'); handles.dcmlist = dcmlist; handles.needsReload = 1; %ha = axes(handles.axes1); ha = handles.axes1; h = imagesc(ha,zeros(330)); colormap('gray'); %get(h) set(h,'HitTest','off'); set(h,'PickableParts','none'); %get(ha); set(ha,'ButtonDownFcn',@axes1_ButtonDownFcn); handles.imageHandle = h; guidata(hObject,handles); % -------------------------------------------------------------------- function PrintMenuItem_Callback(hObject, eventdata, handles) % hObject handle to PrintMenuItem (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) printdlg(handles.figure1) % -------------------------------------------------------------------- function CloseMenuItem_Callback(hObject, eventdata, handles) % hObject handle to CloseMenuItem (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],... ['Close ' get(handles.figure1,'Name') '...'],... 'Yes','No','Yes'); if strcmp(selection,'No') return; end delete(handles.figure1) % --- Executes on selection change in popupmenu1. function popupmenu1_Callback(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array % contents{get(hObject,'Value')} returns selected item from popupmenu1 % --- Executes during object creation, after setting all properties. function popupmenu1_CreateFcn(hObject, eventdata, handles) % hObject handle to popupmenu1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end set(hObject, 'String', {'plot(rand(5))', 'plot(sin(1:0.01:25))', 'bar(1:.5:10)', 'plot(membrane)', 'surf(peaks)'}); % --- Executes on button press in buttonLiverROI. function buttonLiverROI_Callback(hObject, eventdata, handles) % hObject handle to buttonLiverROI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if checkReload(hObject,handles) [a x y] = roipoly(); imageNum = get(handles.slider2,'Value'); handles.roi.liver(:,:,imageNum) = a; handles.roiCoords.liver(imageNum).x = x; handles.roiCoords.liver(imageNum).y = y; guidata(hObject,handles); set(handles.checkbox_liver,'Value',1,'BackgroundColor','g'); end % --- Executes on button press in buttonLiverROI. function buttonMuscROI_Callback(hObject, eventdata, handles) % hObject handle to buttonLiverROI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) if checkReload(hObject,handles) [a x y] = roipoly(); imageNum = get(handles.slider2,'Value'); handles.roi.muscle(:,:,imageNum) = a; handles.roiCoords.muscle(imageNum).x = x; handles.roiCoords.muscle(imageNum).y = y; guidata(hObject,handles); set(handles.checkbox_musc,'Value',1,'BackgroundColor','g'); end % --- If Enable == 'on', executes on mouse press in 5 pixel border. % --- Otherwise, executes on mouse press in 5 pixel border or over buttonLiverROI. function buttonLiverROI_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to buttonLiverROI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % --- Executes on selection change in listbox1. function listbox1_Callback(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: contents = cellstr(get(hObject,'String')) returns listbox1 contents as cell array % contents{get(hObject,'Value')} returns selected item from listbox1 % --- Executes during object creation, after setting all properties. function listbox1_CreateFcn(hObject, eventdata, handles) % hObject handle to listbox1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: listbox controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in buttonLoad. function buttonLoad_Callback(hObject, eventdata, handles) % hObject handle to buttonLoad (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) set(handles.checkbox_liver,'Value',0,'BackgroundColor','r'); set(handles.checkbox_musc,'Value',0,'BackgroundColor','r'); set(handles.checkbox_saved,'Value',0,'BackgroundColor','r'); imagenum = get(handles.listbox1,'Value'); path = handles.dcmlist(imagenum).path; axes(handles.axes1); images = dicomread(path); dcminfo = dicominfo(path); %h = imagesc(images(:,:,1,1),'HitTest','off');\ handles.dcminfo = dcminfo; set(handles.imageHandle,'CData',images(:,:,1,1)); %h = imagesc(images(:,:,1,1)); set(handles.sliceCount,'String',sprintf('/ %i',size(images,4))); %get(gca,'HitTest') %get(gca,'Children') %get(h) %set(h,'HitTest','off') %set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) tsize = size(images); if handles.debug display("matrix size"); display(tsize); end if max(size(tsize)) > 2 tsize = tsize([1:2 4]); end roi = zeros(tsize); if size(images,4) > 1 sliderVal = size(images,4); sH = handles.slider2; set(sH, 'SliderStep',[1/(sliderVal-1) 1], 'Min', 1, 'Max', sliderVal, 'Value', 1); else sH = handles.slider2; set(sH, 'SliderStep',[.1 1], 'Min', 1, 'Max', 1.1, 'Value', 1); end handles.curName = handles.dcmlist(imagenum).fname; handles.roiCoords = struct; handles.roi.liver = roi; handles.roi.muscle = roi; handles.imageMat = images; handles.currentSlice = 1; handles.needsReload = 0; handles.climval = get(handles.axes1,'CLim'); set(handles.slider_color,'Value',1); guidata(hObject,handles); function setProgress(hObject, eventdata, handles,value,text) if ~isempty(value) axes(handles.progressAxes); vxlow=0; vxhigh = value; vylow = 0; vyhigh = 1; fillhandle = fill([vxlow,vxlow,vxhigh,vxhigh], [vyhigh,vylow,vylow,vyhigh],[.3,.4,0]); %creates the plot of a box. If you reverse the order of one of the sets of points, you get an hourglass shape set(fillhandle,'FaceAlpha',.2,'EdgeAlpha',.2);%set edge color set(gca,'Ylim',[0,1],'Xlim',[0,1],'XTick',0,'YTick',0); end if ~isempty(text) set(handles.progressText,'String',text); end function redrawImage(hObject, eventdata, handles) axes(handles.axes1); images = handles.imageMat; %h = imagesc(images(:,:,1,1),'HitTest','off'); cs = handles.currentSlice; gridsize = handles.lungGridSize; newim = repmat(images(:,:,1,cs),1,1,3); newim = double(newim); newim = newim ./ max(newim(:)); lms = handles.lungGridSize; imsize = size(images); overlay = zeros(size(newim)); if lms > -1 for n=1:size(handles.lungMatrix,1)-1 for m=1:size(handles.lungMatrix,2)-1 xx = n*lms; yy = m*lms; switch handles.lungMatrix(m,n,1,handles.currentSlice) case 1 cd = [0.2, 0.2, 0.0]; case 2 cd = [0.4,0,0]; case 3 cd = [0,0.4,0]; case 4 cd = [0.1,0.1,0.5]; otherwise cd = [0 0 0]; end overlay(yy:yy+lms, xx:xx+lms,1)=cd(1); overlay(yy:yy+lms, xx:xx+lms,2)=cd(2); overlay(yy:yy+lms, xx:xx+lms,3)=cd(3); end end end %size(newim) %size(overlay) newim = newim + overlay; %set(handles.imageHandle,'CData',newim) h = imagesc(newim); set(h,'HitTest','off') set(h,'PickableParts','none') set(handles.sliceNum, 'String', num2str(handles.currentSlice)); set(handles.sliceCount,'String',sprintf('/ %i',size(images,4))); if lms > -1 hold on; for n=0:gridsize:imsize(1); h = plot([n,n],[0,imsize(2)],'g'); set(h,'HitTest','off') set(h,'PickableParts','none') %set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) end for n=0:gridsize:imsize(2); h = plot([0,imsize(1)],[n,n],'g'); set(h,'HitTest','off') set(h,'PickableParts','none') %set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) end %handles end % --- Executes on slider movement. function slider2_Callback(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) sv = round(get(handles.slider2,'Value')); set(handles.slider2,'Value',sv); handles.currentSlice = sv; % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider if get(handles.slider2,'Max') ~= 1.1 axes(handles.axes1); images = handles.imageMat; h = imagesc(images(:,:,1,get(handles.slider2,'Value'))); colormap('gray') set(h,'ButtonDownFcn',@axes1_ButtonDownFcn); redrawImage(hObject,eventdata,handles); end guidata(hObject,handles); % --- Executes during object creation, after setting all properties. function slider2_CreateFcn(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on slider movement. function slider_color_Callback(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider %handles.climval %get(handles.slider_color,'Value') set(handles.axes1,'CLim',handles.climval .* [1 get(handles.slider_color,'Value')]); function out = checkReload(hObject,handles) if handles.needsReload ~= 0 warndlg('Please load an image'); out = 0; else out = 1; end % --- Executes during object creation, after setting all properties. function slider_color_CreateFcn(hObject, eventdata, handles) % hObject handle to slider_color (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end % --- Executes on button press in buttonSelectAirway. function buttonSelectAirway_Callback(hObject, eventdata, handles) % hObject handle to buttonSelectAirway (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) axes(handles.axes1); [x_coord, y_coord]=ginput(2); gridsize = sqrt((x_coord(2)-x_coord(1)).^2 + (y_coord(2)-y_coord(1)).^2); gridsize = ceil(gridsize); imsize = size(handles.imageMat); lungMatrix = zeros(floor(imsize(1)./gridsize),floor(imsize(2)./gridsize),imsize(3),imsize(4)); handles.lungMatrix = lungMatrix; handles.lungGridSize = gridsize; hold on; for n=0:gridsize:imsize(1); h = plot([n,n],[0,imsize(2)],'g'); %set(h,'HitTest','off') set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) end for n=0:gridsize:imsize(2); h = plot([0,imsize(1)],[n,n],'g'); set(h,'HitTest','off') set(h,'ButtonDownFcn',@axes1_ButtonDownFcn) end %handles guidata(hObject,handles); redrawImage(hObject,eventdata,handles); %set(gca, 'ButtonDownFcn', @axes1_ButtonDownFcn); %ax = gca; %im.PickableParts = 'none'; %ax.ButtonDownFcn = @mouseClick; % --- Executes on mouse press over axes background. function axes1_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %gca; drawnow handles = guidata(hObject); %colormap('gray'); if handles.debug > 3 disp('yes it ran') datetime end currentPoint = get(gca, 'currentpoint'); currentBox = currentPoint(1,1:2); if handles.debug > 3 currentPoint currentBox handles end %handles2 = guihandles(hObject) %handles2 %size(handles.lungMatrix) lungGridSize = handles.lungGridSize; lungGridMatSize = size(handles.lungMatrix); lungMatLoc = floor(currentBox); lmy = floor(lungMatLoc(1)./size(handles.imageMat,2)*lungGridMatSize(2)); lmx = floor(lungMatLoc(2)./size(handles.imageMat,1)*lungGridMatSize(1)); currentSlice = get(handles.slider2,'Value'); if handles.debug > 3 lungGridMatSize lungMatLoc lmy lmx currentSlice end handles.lungMatrix(lmx,lmy,1,currentSlice) = mod(handles.lungMatrix(lmx,lmy,1,currentSlice)+1,5); handles.lungMatrix(:,:,1,currentSlice); guidata(hObject, handles); redrawImage(hObject, eventdata, handles); %r = rectangle('Position',[lungMatLoc.*lungGridSize lungMatLoc.*lungGridSize+[lungGridSize,lungGridSize]],'FaceColor',[0.5 0.5 0.5] ) %SliderLocation = round(get(handles.slider1,'Value')); %[xlist ylist]=ginput(5); %tableData = {xlist(1),ylist(1),SliderLocation}; %set(handles.CoordinateTable,'Data',tableData) % Update handles structure guidata(hObject, handles); function mouseClick(~,~) disp('yep') get(gca,'CurrentPoint') function clicker(h,~) get(h, 'selectiontype') % 'normal' for left moue button % 'alt' for right mouse button % 'extend' for middle mouse button % 'open' on double click get(h, 'currentpoint') % Current mouse location, in pixels from the lower left. % When the units of the figure are 'normalized', the % coordinates will be [0 0] inb lower left, and [1 1] in % the upper right. function sliceNum_Callback(hObject, eventdata, handles) % hObject handle to sliceNum (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of sliceNum as text % str2double(get(hObject,'String')) returns contents of sliceNum as a double % --- Executes during object creation, after setting all properties. function sliceNum_CreateFcn(hObject, eventdata, handles) % hObject handle to sliceNum (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on key press with focus on sliceNum and none of its controls. function sliceNum_KeyPressFcn(hObject, eventdata, handles) % hObject handle to sliceNum (see GCBO) % eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL) % Key: name of the key that was pressed, in lower case % Character: character interpretation of the key(s) that was pressed % Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed % handles structure with handles and user data (see GUIDATA) set(handles.slider2,'Value',get(handles.sliceNum,'Value')); % --- Executes on button press in statsButton. function statsButton_Callback(hObject, eventdata, handles) % hObject handle to statsButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %stats text variable st = "Statistics"; lungVoxels = size(find(handles.lungMatrix),1); lungNormal = size(find(handles.lungMatrix==1),1); lungHypo = size(find(handles.lungMatrix==2),1); lungHyper = size(find(handles.lungMatrix==3),1); lungBronchodyslasia = size(find(handles.lungMatrix==4),1); lungVol = -1; if strcmp(handles.dcminfo.SOPClassUID,'1.2.840.10008.5.1.4.1.1.4.1') %this is an enhanced dicom d = handles.dcminfo; sliceThickness = d.PerFrameFunctionalGroupsSequence.Item_1.PixelMeasuresSequence.Item_1.SliceThickness; sliceSpacing = d.PerFrameFunctionalGroupsSequence.Item_1.PixelMeasuresSequence.Item_1.SpacingBetweenSlices; if sliceThickness ~= sliceSpacing warndlg("Slice thickness does not equal slice spacing, lung volume may be very wrong"); end pixelSpacing = d.PerFrameFunctionalGroupsSequence.Item_1.PixelMeasuresSequence.Item_1.PixelSpacing; pixelsPerLungMatVox = handles.lungGridSize^2; lmVoxVol = pixelSpacing(1)*pixelSpacing(2)*sliceThickness*pixelsPerLungMatVox; lungVol = lungVoxels * lmVoxVol; elseif strcmp(handles.dcminfo.SOPClassUID,'1.2.840.10008.5.1.4.1.1.4') % this is a classic dicom warndlg('Classic dicom does not compute lung volume stats yet'); else error('SOPClassUID %s not equal to MR Classic or Enhance DICOM SOPClassUID',handles.dcminfo.SOPClassUID ); end st = st + sprintf("Counts:\n"); st = st + sprintf(" Total Lung Voxels: %d (%03.2f%%)\n",lungVoxels, 100*lungVoxels/lungVoxels); st = st + sprintf(" Normal Lung Voxels: %d (%03.2f%%)\n",lungNormal, 100*lungNormal/lungVoxels); st = st + sprintf(" Hypointense Voxels: %d (%03.2f%%)\n",lungHypo, 100*lungHypo/lungVoxels); st = st + sprintf(" Hyperintense Voxels: %d (%03.2f%%)\n",lungHyper, 100*lungHyper/lungVoxels); st = st + sprintf(" Bronchodyspl Voxels: %d (%03.2f%%)\n",lungBronchodyslasia, 100*lungBronchodyslasia/lungVoxels); st = st + sprintf("\nVolumes:\n"); st = st + sprintf(" Estimated Total Lung Volume: %06.1f cc", lungVol); set(handles.statsTextbox,'String',st);