Info

此问题已关闭。 请重新打开它进行编辑或回答。

Problem with memory not clearing properly in an image loading GUI callback

2 次查看(过去 30 天)
Good afternoon! I'm having some trouble with a medical image processing program I've written using GUIDE. I have a button that, when pressed, prompts the user to select a folder of DICOM images to load, which it does into a field called handles.img. They can then do some processing, and when they press that button again, handles.img is supposed to be cleared and new images loaded. The problem I'm running in to is that the previous handles.img data aren't cleared until the full callback completes, so it essentially tries to hold 2 data sets in memory. Usually not a big deal, but some approach 40GB and can cause problems. Can anyone help me figure out how to get handles.img to clear before the callback is finished? Code is below.
Thanks!
try set(handles.textBusy,'String','Busy'); if isfield(handles,'img') == 1 handles.img = []; guidata(hObject, handles); drawnow(); end if isfield(handles,'bwContour') == 1 clear handles.bwContour;handles=rmfield(handles,'bwContour'); end
handles.pathstr = uigetdir(pwd,'Please select the folder containing your DICOM files');
handles.files = dir(fullfile(handles.pathstr, '*.dcm*'));
handles.info = dicominfo(fullfile(handles.pathstr,handles.files(1).name));
handles.img = zeros(handles.info.Height,handles.info.Width,length(handles.files),'uint16');
for i = 1:length(handles.files)
set(handles.textPercentLoaded,'String',num2str(i/length(handles.files)));
drawnow();
handles.img(:,:,i) = dicomread(fullfile(handles.pathstr,handles.files(i).name));
end
guidata(hObject, handles);
catch
set(handles.textBusy,'String','Failed');
end

回答(0 个)

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by