⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mia_gui.m

📁 医学图像处理matlab工具箱
💻 M
📖 第 1 页 / 共 5 页
字号:
        handles.CurrentImgIdx = handles.scaninfo.num_of_slice*(handles.scaninfo.Frames-1)+handles.CurrentSlice;
    end
elseif strcmp(event,'NextFrame')% Frame+
    if handles.CurrentImgIdx < handles.scaninfo.num_of_slice*(handles.scaninfo.Frames-1)
        handles.CurrentImgIdx = handles.CurrentImgIdx + handles.scaninfo.num_of_slice;
    else
        handles.CurrentImgIdx = handles.CurrentSlice;
    end
end
CurrentImage = handles.imaVOL(:,:,handles.CurrentImgIdx);
SliderPosMin = get(handles.ColorBarMinSlider,'Value');
SliderPosMax = get(handles.ColorBarMaxSlider,'Value');
CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn1);
set(handles.ImaHandler,'CData',CurrentImage_RGB);
% set the currentimage for gVOIpixval
gVOIpixval.CurrentImage = CurrentImage;

if isfield(handles,'FileNames2')
    SliderPosMax = get(handles.ColorBarMax2Slider,'Value');
    SliderPosMin = get(handles.ColorBarMin2Slider,'Value');
    CurrentImage = double(handles.imaVOL2(:,:,handles.CurrentSlice));
    CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn2);
    set(handles.ImaHandler2,'CData',CurrentImage_RGB);    
end

handles.CurrentSlice = mod(handles.CurrentImgIdx,handles.scaninfo.num_of_slice);
handles.CurrentFrame = fix(handles.CurrentImgIdx/handles.scaninfo.num_of_slice)+1; 
if handles.CurrentSlice == 0
    handles.CurrentSlice = handles.scaninfo.num_of_slice;
    handles.CurrentFrame = handles.CurrentFrame -1;
end
set(handles.CurrentFrameEdit,'String',handles.CurrentFrame);
set(handles.CurrentSliceEdit,'String',handles.CurrentSlice);
set(handles.SliceSlider,'value',handles.CurrentSlice);
if handles.scaninfo.Frames > 1 % dynamic scan
    set(handles.CurrentFrameTimeEdit,'String', ...
        sprintf('%1.2f',handles.scaninfo.tissue_ts(handles.CurrentFrame)/60));%min
    set(handles.CurrentFrameLengthEdit,'String', ... 
        sprintf('%1.2f',handles.scaninfo.frame_lengths(handles.CurrentFrame)/60));%min
    set(handles.FrameSlider,'value',handles.CurrentFrame);
end

%redraw the ROI if exist on the current slide
for j = 1: handles.ROINumOfColor
	if ~isempty(handles.Lines(PreviousSlice,j).lh)
        set(handles.Lines(PreviousSlice,j).lh,'visible','off');    
	end
	if ~isempty(handles.Lines(handles.CurrentSlice,j).lh)
        set(handles.Lines(handles.CurrentSlice,j).lh,'visible','on');    
	end
end
	
% Update handles structure
guidata(handles.mia_figure1, handles); 


% --- Executes during object creation, after setting all properties.
function SliceSlider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to SliceSlider (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, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function SliceSlider_Callback(hObject, eventdata, handles)
% hObject    handle to SliceSlider (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
global gVOIpixval;
if isfield(handles,'FileNames')
    PreviousSlice = handles.CurrentSlice;
	handles.CurrentSlice = round(get(handles.SliceSlider,'Value'));
    set(handles.CurrentSliceEdit,'String',num2str(handles.CurrentSlice));
	handles.CurrentFrame = str2double(get(handles.CurrentFrameEdit,'String'));
	handles.CurrentImgIdx = handles.scaninfo.num_of_slice*(handles.CurrentFrame-1) + handles.CurrentSlice;
	%refresh the image
    SliderPosMax = get(handles.ColorBarMaxSlider,'Value');
    SliderPosMin = get(handles.ColorBarMinSlider,'Value');
    CurrentImage = double(handles.imaVOL(:,:,handles.CurrentImgIdx));
    CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn1);
    set(handles.ImaHandler,'CData',CurrentImage_RGB);
    % set the currentimage for gVOIpixval
    gVOIpixval.CurrentImage = CurrentImage;
    
    if isfield(handles,'FileNames2')
        SliderPosMax = get(handles.ColorBarMax2Slider,'Value');
        SliderPosMin = get(handles.ColorBarMin2Slider,'Value');
        CurrentImage = double(handles.imaVOL2(:,:,handles.CurrentSlice));
        CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn2);
        set(handles.ImaHandler2,'CData',CurrentImage_RGB);    
    end
	set(handles.ImaAxes,'selected','on');
    set(handles.CurrentFrameEdit,'String',handles.CurrentFrame);
	set(handles.CurrentSliceEdit,'String',handles.CurrentSlice);
    if handles.scaninfo.Frames > 1 % dynamic scan
        set(handles.CurrentFrameTimeEdit,'String', ...
            sprintf('%1.2f',handles.scaninfo.tissue_ts(handles.CurrentFrame)/60));%min
        set(handles.CurrentFrameLengthEdit,'String', ... 
            sprintf('%1.2f',handles.scaninfo.frame_lengths(handles.CurrentFrame)/60));%min
        set(handles.FrameSlider,'value',handles.CurrentFrame);
    end
    
    %redraw the ROI if exist on the current slide
    for j = 1: handles.ROINumOfColor
		if ~isempty(handles.Lines(PreviousSlice,j).lh)
            set(handles.Lines(PreviousSlice,j).lh,'visible','off');    
		end
		if ~isempty(handles.Lines(handles.CurrentSlice,j).lh)
            set(handles.Lines(handles.CurrentSlice,j).lh,'visible','on');    
		end
	end
    
    % Update handles structure
    guidata(hObject, handles);
end


% --- Executes during object creation, after setting all properties.
function FrameSlider_CreateFcn(hObject, eventdata, handles)
% hObject    handle to FrameSlider (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, change
%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.
usewhitebg = 1;
if usewhitebg
    set(hObject,'BackgroundColor',[.9 .9 .9]);
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


% --- Executes on slider movement.
function FrameSlider_Callback(hObject, eventdata, handles)
% hObject    handle to FrameSlider (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
global gVOIpixval;
if isfield(handles,'FileNames')
    PreviousSlice = handles.CurrentSlice;
	handles.CurrentSlice = str2double(get(handles.CurrentSliceEdit,'String'));
	handles.CurrentFrame = round(get(hObject,'Value'));;
    set(handles.CurrentFrameEdit,'String',num2str(handles.CurrentFrame));
	handles.CurrentImgIdx = handles.scaninfo.num_of_slice*(handles.CurrentFrame-1) + handles.CurrentSlice;
	%refresh the image
    SliderPosMax = get(handles.ColorBarMaxSlider,'Value');
    SliderPosMin = get(handles.ColorBarMinSlider,'Value');
    CurrentImage = double(handles.imaVOL(:,:,handles.CurrentImgIdx));
    CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn1);
    set(handles.ImaHandler,'CData',CurrentImage_RGB);
    % set the currentimage for gVOIpixval
    gVOIpixval.CurrentImage = CurrentImage;
    if isfield(handles,'FileNames2')
        SliderPosMax = get(handles.ColorBarMax2Slider,'Value');
        SliderPosMin = get(handles.ColorBarMin2Slider,'Value');
        CurrentImage = double(handles.imaVOL2(:,:,handles.CurrentSlice));
        CurrentImage_RGB = ImageRefresh(CurrentImage,SliderPosMax,SliderPosMin,handles.ColorRes,handles.ColormapIn2);
        set(handles.ImaHandler2,'CData',CurrentImage_RGB);    
    end
	set(handles.ImaAxes,'selected','on');
    set(handles.CurrentFrameEdit,'String',handles.CurrentFrame);
	set(handles.CurrentSliceEdit,'String',handles.CurrentSlice);
    if handles.scaninfo.Frames > 1 % dynamic scan
        set(handles.CurrentFrameTimeEdit,'String', ...
            sprintf('%1.2f',handles.scaninfo.tissue_ts(handles.CurrentFrame)/60));%min
        set(handles.CurrentFrameLengthEdit,'String', ... 
            sprintf('%1.2f',handles.scaninfo.frame_lengths(handles.CurrentFrame)/60));%min
    end
    
     %redraw the ROI if exist on the current slide
    for j = 1: handles.ROINumOfColor
		if ~isempty(handles.Lines(PreviousSlice,j).lh)
            set(handles.Lines(PreviousSlice,j).lh,'visible','off');    
		end
		if ~isempty(handles.Lines(handles.CurrentSlice,j).lh)
            set(handles.Lines(handles.CurrentSlice,j).lh,'visible','on');    
		end
	end
    % Update handles structure
    guidata(hObject, handles);
end


% --- Executes on button press in VOITACbutton.
function VOITACbutton_Callback(hObject, eventdata, handles)
% hObject    handle to VOITACbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if not(isfield(handles,'FileNames'));return;end % 1st file should be opened first

% if ROIs no exist then return
ROINotExist = 1;
for j=1:handles.ROINumOfColor
    for i = 1 : handles.scaninfo(1).num_of_slice
        if ~isempty(handles.ROI(i,j).BW )
			ROINotExist = 0;
            break;
		end
    end
end
if ROINotExist;return;end 

%roi.area(:,roiIndex) = polyarea(xi,yi);
%roi.center(:,roiIndex) = [mean(Xin(:)), mean(Yin(:))];

if isempty(handles.scaninfo(1).tissue_ts);
   tac_timescale = 1;
else
   tac_timescale = handles.scaninfo(1).tissue_ts;
end
temp_as = zeros(handles.scaninfo(1).Frames,handles.scaninfo(1).num_of_slice);
temp_std = zeros(handles.scaninfo(1).Frames,handles.scaninfo(1).num_of_slice);
px_num = [];
matsize1 = handles.scaninfo.imfm(1);matsize2 = handles.scaninfo.imfm(2);
tacmaxs = zeros(1,handles.ROINumOfColor);
tacmins = zeros(1,handles.ROINumOfColor);
handles.VOI(handles.ROINumOfColor).tac = [];
handles.VOI(handles.ROINumOfColor).tacstd = [];
handles.VOI(handles.ROINumOfColor).tacmin = [];
handles.VOI(handles.ROINumOfColor).tacmax = [];
handles.VOI(handles.ROINumOfColor).tacvolume = [];

for k=1:handles.ROINumOfColor
    VOItissue_as = []; VOItissue_std = [];px_num = [];
	for i=1:handles.scaninfo(1).num_of_slice
        if ~isempty(handles.ROI(i,k).BW )
			roimask = poly2mask(handles.ROI(i,k).xi*double(matsize1), ...
                handles.ROI(i,k).yi*double(matsize2),double(matsize1),double(matsize2));
			px = find(roimask); px_num(i) = length(px);
			for j =1 : handles.scaninfo(1).Frames
                imgt = handles.imaVOL(:,:,(j-1)*handles.scaninfo(1).num_of_slice+i);
				imgt_masked=imgt(px);
				temp_as(j,i) = mean(imgt_masked)*px_num(i);
                temp_std(j,i) = std(double(imgt_masked))*px_num(i);
            end
        end
	end
	if not(isempty(px_num))
		if size(temp_as,2) ~= 1
			VOItissue_as = sum(temp_as')'/sum(px_num);
            VOItissue_std = sum(temp_std')'/sum(px_num);
		else
			VOItissue_as = temp_as/sum(px_num);
            VOItissue_std = temp_std/sum(px_num);
		end
        tacmaxs(k) = max(VOItissue_as); tacmins(k) = min(VOItissue_as); 
	    handles.VOI(k).tac  = VOItissue_as';
        handles.VOI(k).tacstd  = VOItissue_std';
        handles.VOI(k).tacmin  = tacmins(k);
        handles.VOI(k).tacmax  = tacmaxs(k);
        if length(handles.scaninfo.pixsize) == 3
            handles.VOI(k).tacvolume = sum(px_num)*handles.scaninfo.pixsize(1)* ...
                handles.scaninfo.pixsize(2)*handles.scaninfo.pixsize(3);
        elseif length(handles.scaninfo.pixsize) == 2
            handles.VOI(k).tacvolume = sum(px_num)*handles.scaninfo.pixsize(1)* ...
                handles.scaninfo.pixsize(2);
        end
    end
end
tacmax = max(tacmaxs); tacmin = max(tacmins);
if tacmin > 0; tacmin = 0;end

% Update handles structure
guidata(hObject, handles);


tac_fh = figure('NumberTitle','off','name','ROI(VOI) curves');
if length(tac_timescale) == 1 
    axis([0 2 tacmin round(1.2*tacmax) ]);
    set(get(tac_fh,'children'),'Xtick',[0 1]);
    title(['ROI means. ','patientID = ',num2str(handles.scaninfo(1).brn)]);
else
    axis([0 max(tac_timescale) tacmin round(1.2*tacmax) ]);
    xlabel('Time [sec]');
    title(['VOI curves  ','patientID= ',num2str(handles.scaninfo(1).brn)]);
end
%ylabel('Activity concentration [nCi/ml]');
ylabel('Pixel unit');
hold on;
for j = 1 :handles.ROINumOfColor
    if not(isempty(handles.VOI(j).tac))
        labelcolor = [handles.ROIColorStrings(j),'*'];
        linecolor = [handles.ROIColorStrings(j),'-'];
		plot(tac_timescale,handles.VOI(j).tac,labelcolor);
		plot(tac_timescale,handles.VOI(j).tac,linecolor);
    end
end
hold off;
set(handles.ImaAxes,'selected','on');

% --- Executes on button press in ROIstatbutton.
function ROIstatbutton_Callback(hObject, eventdata, handles)
% hObject    handle to ROIstatbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% ha

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -