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

📄 imlook3d.m

📁 CT等医学图像的分割及其三维重建的MATLAB源代码
💻 M
📖 第 1 页 / 共 3 页
字号:
    drawnow  
end
% --------------------------------------------------------------------
function imageProcessMenu_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function imageThresholdManual_Callback(hObject, eventdata, handles)
img = getimage(gcbf);
th = cell2mat(inputdlg('Enter Threshold','Threshold',1,{'100'}));
if ~isempty(th)
    th = str2num(th);
    figure;imagesc(img>th);axis image;axis off
    title('Thresholded Image');
end
% --------------------------------------------------------------------
function automatedThresholding_Callback(hObject, eventdata, handles)
img = getimage(gcbf);
th=otsu_th(single(img(:)),64);
figure;imagesc(img>th);axis image;axis off
title('Thresholded Image');
% --------------------------------------------------------------------
% READS DICOM IMAGE SINGLE OR VOLUME
% --------------------------------------------------------------------
function readSingleDicomImage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.dcm';'*.*'},'Image');
if isequal(filename,0)|isequal(pathname,0)
    setstatus('File not found');
else
    cd(pathname)
    info = dicominfo(filename);  
    if isfield(info,'NumberOfSlices')
        z = info.NumberOfSlices;
    elseif isfield(info,'NumberOfFrames')
        z = info.NumberOfFrames;
    end
    if isfield(info,'SliceThickness')
        handles.SliceThickness= info.SliceThickness;
    end 
    % Reading dicom image
    nimg = squeeze(dicomread(info));
    [r,c,z]=size(nimg);
    handles.image.CData = nimg;
    handles.image.Xdata = [1 c];
    handles.image.Ydata = [1 r];
    handles.imSize = [r,c,z];
    
    if z >1
        turnDisplayButtons(handles,'on');
        set(handles.SliceNumSlider,'Min',1,'Max',z,'Value',...
            round(z/2),'SliderStep',[1.0/double(z-1) 1.0/double(z-1)]);
        set(handles.SliceNumEdit,'String',num2str(round(z/2)));
        turnDisplayButtons(handles,'on');
        cimg = handles.image.CData(:,:,round(z/2));
    else
        turnDisplayButtons(handles,'off');
        cimg = handles.image.CData;
    end
    fields = {'Filename','FileModDate','FileSize','ImageType','Width','Height','BitDepth',...
        'NumberOfFrames','Rows','Columns','BitsAllocated','SmallestImagePixelValue',...
        'LargestImagePixelValue','PixelDataGroupLength','StudyDescription','SeriesDescription',...
        'StudyID','ImageID','PatientID','SliceThickness','StudyDate','AcquisitionDate','AcquisitionTime','PixelSpacing'};
    myinfo = keepfield(info,fields);
    handles.imageInfo = myinfo;
   
    % Set the properties of the axes and image object
    set(handles.ImgObject,'XData',[1 c],'YData',[1 r],'CData',cimg);
    set(handles.axes1,'XLim',[1 c],'YLim',[1 r],'PlotBoxAspectRatio',[c r 1],'DataAspectRatio',...
        [1 info.PixelSpacing(2)/info.PixelSpacing(1)  1]);
    handles.oimage = handles.image;
    guidata(hObject, handles);
    clear nimg;
    drawnow  
end
% --------------------------------------------------------------------
% --- Executes on selection change in popup_flip.
function popup_flip_Callback(hObject, eventdata, handles)
v = get(hObject,'value');
switch v
    case 1
       handles.image.CData = flipdim(handles.image.CData,2);
    case 2
        handles.image.CData = flipdim(handles.image.CData,1);
    case 3
        handles.image.CData = flipdim(handles.image.CData,3);
    case 4
    handles.image.CData = handles.oimage.CData;
    otherwise
end
guidata(hObject,handles);

% --- Executes during object creation, after setting all properties.
function popup_flip_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

function turnDisplayButtons(handles,bmode)
set(handles.SliceNumSlider,'visible',bmode);
set(handles.SliceNumEdit,'visible',bmode);
set(handles.popup_view,'visible',bmode);
set(handles.popup_flip,'visible',bmode);
set(handles.text1,'visible',bmode);
set(handles.text2,'visible',bmode);
set(handles.text3,'visible',bmode);
set(handles.popup_flip,'visible',bmode);     
return


% --------------------------------------------------------------------
function helpCallback_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
% --------------------------------------------------------------------
function helpMenu_Callback(hObject, eventdata, handles)
% --------------------------------------------------------------------
function helpAboutImlook3d_Callback(hObject, eventdata, handles)
s = sprintf(['IMLOOK3D: 3D Image Display Tool\n',...
    'Version 1.2, Copyright (2006 - Inf and Beyond)\n',...
    'Omer Demirkaya, KFSH&RC']);
msgbox(s,'About IMLOOK3D Tool','modal');
% --------------------------------------------------------------------
function helpDisclaimer_Callback(hObject, eventdata, handles)
s = {'This SOFTWARE DOES NOT (A) MAKE ANY WARRANTY, EXPRESS OR IMPLIED',
    'WITH RESPECT TO THE USE OF THE INFORMATION PROVIDED HEREBY; NOR (B)', 
    'GUARANTEE THE ACCURACY,COMPLETENESS,USEFULNESS,OR ADEQUACY OF ANY',
    'RESOURCES, INFORMATION,SYSTEM,PRODUCT,OR PROCESS AVAILABLE - AT OR', 
    'THROUGH THIS SOFTWARE.'};
msgbox(s,'Disclaimer','modal');

% --------------------------------------------------------------------
function imageInformation_Callback(hObject, eventdata, handles)
if ~isempty(handles.imageInfo)
    imageinfo(handles.imageInfo);
else
    msgbox('There is no image or no information about it','Image Info..','modal');
end

% --------------------------------------------------------------------
function readSingleOrdinaryImage_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.*'},'Image');
if isequal(filename,0)|isequal(pathname,0)
    setstatus('File not found');
else
    cd(pathname)
    info = imfinfo(filename);  
    [img, map]=imread(filename);
    [r,c,z] = size(img);
    handles.image.CData = img;
    handles.image.Xdata = [1 c];
    handles.image.Ydata = [1 r];
    handles.imSize = [r,c,z];
    
    if z > 1   % single slice
    set(handles.SliceNumSlider,'Min',1,'Max',z,'Value',...
        round(z/2),'SliderStep',[1.0/double(z-1) 1.0/double(z-1)]);
    set(handles.SliceNumEdit,'String',num2str(round(z/2)));
    turnDisplayButtons(handles,'on');
    cimg = handles.image.CData(:,:,round(z/2));
    else
        turnDisplayButtons(handles,'off');
        cimg = handles.image.CData;
    end
    handles.imageInfo = info;
   % Set the properties of the axes and image object
    set(handles.ImgObject,'XData',[1 c],'YData',[1 r],'CData',cimg);
    set(handles.axes1,'XLim',[1 c],'YLim',[1 r],'PlotBoxAspectRatio',[c r 1],'DataAspectRatio',[1 1 1]);
    handles.oimage = handles.image;
    guidata(hObject, handles);
    clear nimg;
    drawnow  
end
% --------------------------------------------------------------------
% SMOOTH IMAGE
% --------------------------------------------------------------------
function smoothVolume_Callback(hObject, eventdata, handles)
if size(handles.image.CData,3) > 1
h = waitbar(0,'Smoothing, please wait...');
handles.image.CData= smooth3(handles.image.CData,'gaussian');
close(h);
set(handles.ImgObject,'Cdata',handles.image.CData(:,:,handles.currentSliceNumber));
guidata(hObject,handles);
end
% --------------------------------------------------------------------
% Voxel dimensions
% --------------------------------------------------------------------
function voxelSize_Callback(hObject, eventdata, handles)
prompt = {'X Size:','Y Size:', 'Z Size'};
dlg_title = 'Enter Voxel Sizes'; num_lines = 1; def = {'1','1','1'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
if ~isempty(answer)
    voxdim(1) = str2num(cell2mat(answer(1,1)));
    voxdim(2) = str2num(cell2mat(answer(2,1)));
    voxdim(3) = str2num(cell2mat(answer(3,1)));
    bw = voxdim > 0; % checking for zero or negative
    if prod(double(bw))
        handles.imageInfo.PixelSpacing(1) = voxdim(1);
        handles.imageInfo.PixelSpacing(2) = voxdim(2);
        handles.imageInfo.SliceThickness  = voxdim(3);
        if handles.viewtype == 2
            set(handles.axes1,'DataAspectRatio',[1 voxdim(1)/voxdim(3)  1]);
        elseif handles.viewtype == 3
            set(handles.axes1,'DataAspectRatio',[1 voxdim(2)/voxdim(3)  1]);
        else
            set(handles.axes1,'DataAspectRatio',[1 voxdim(2)/voxdim(1)  1]);
        end

    end
end
guidata(hObject,handles);
% --------------------------------------------------------------------
% Horizontal Profile
% --------------------------------------------------------------------
function horizontalProfile_Callback(hObject, eventdata, handles)
h = warndlg('Double-click on the row','Pixel Selection');
uiwait;
[c,r,P] = impixel;
f = get(findobj(gcf,'Type','image'));
txt = ['Profile for row: ' num2str(r)];
figure;
plot(f.CData(r,:));title(txt);xlabel('Pixel location');ylabel('Intensity');
% --------------------------------------------------------------------
% Vertical Profile
% --------------------------------------------------------------------
function verticalProfile_Callback(hObject, eventdata, handles)
h = warndlg('Double-click on the column','Pixel Selection');
uiwait;
[c,r,P] = impixel;
f = get(findobj(gcf,'Type','image'));
txt = ['Profile for column: ' num2str(c)];
figure;
plot(f.CData(:,c));title(txt);xlabel('Pixel location');ylabel('Intensity');

% --------------------------------------------------------------------
% --- Executes during object creation, after setting all properties.
% --------------------------------------------------------------------
function popupmenu_imageModality_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --------------------------------------------------------------------
% --- Image modality selection
% --------------------------------------------------------------------
function popupmenu_imageModality_Callback(hObject, eventdata, handles)
imMod = get(hObject,'value');
handles.imageModality = imMod;

% --------------------------------------------------------------------
%  Executes MATLAB IMTOOL 
% --------------------------------------------------------------------
function imtoolMATLAB_Callback(hObject, eventdata, handles)
f = get(findobj(gcf,'Type','image'));
imtool(f.CData,[min(f.CData(:)) max(f.CData(:))]);
% --------------------------------------------------------------------
%  helpMenu on Imlook3D
% --------------------------------------------------------------------
function helpIMLOOK3D_Callback(hObject, eventdata, handles)
warndlg('Under Construction and needs help :)');
% --------------------------------------------------------------------
%  Reading MRI images
% --------------------------------------------------------------------
function readDICOMMRISeries_Callback(hObject, eventdata, handles)
[filename, pathname] = uigetfile({'*.dcm';'*.*'},'Image');
if isequal(filename,0)|isequal(pathname,0)
    setstatus('File not found');
else
    cd(pathname)
    k = findstr(filename,'.');
    fnames = dir(['*' filename(k+1:end)]);
    info = dicominfo(filename);
    r = info.Width;
    c = info.Height;
    numSlices = length(fnames);
    nimg = zeros([r,c,numSlices]);
    hwb = waitbar(0,'Reading Images, please wait...');
    for i=1:numSlices
        waitbar(i/numSlices, hwb);
        info = dicominfo(fnames(i).name);
        nimg(:,:,i) = dicomread(info);
    end
    close(hwb);
    
    fields = {'Filename','FileModDate','FileSize','ImageType','Width','Height','BitDepth',...
        'NumberOfFrames','Rows','Columns','BitsAllocated','SmallestImagePixelValue',...
        'LargestImagePixelValue','PixelDataGroupLength','StudyDescription','SeriesDescription',...
        'StudyID','ImageID','PatientID','SliceThickness','StudyDate','AcquisitionDate','AcquisitionTime','PixelSpacing'};
    
    myinfo = keepfield(info,fields);
    handles.imageInfo = myinfo;
    
    [r,c,z]=size(nimg);
    handles.image.CData = nimg;
    handles.image.Xdata = [1 c];
    handles.image.Ydata = [1 r];
    handles.imSize = [r,c,z];
    set(handles.SliceNumSlider,'Min',1,'Max',z,'Value',...
        round(z/2),'SliderStep',[1.0/double(z-1) 1.0/double(z-1)]);
    set(handles.ImgObject,'Xdata',[1 c],'Ydata',[1 r]);
    % Set the properties of the axes
    set(handles.axes1,'XLim',[1 c],'YLim',[1 r],'PlotBoxAspectRatio',[c r 1]);
    set(handles.SliceNumEdit,'String',num2str(round(z/2)));
    cimg = handles.image.CData(:,:,round(z/2));
    set(handles.ImgObject,'Cdata',cimg);
    handles.oimage = handles.image;
    guidata(hObject, handles);
    clear nimg;
    if z>1
        turnDisplayButtons(handles,'on')
    end
    handles.imageModality = 4;
    set(handles.popupmenu_imageModality,'visible','on');
    set(handles.popupmenu_imageModality,'value',4);
    drawnow  
end

% --------------------------------------------------------------------
function cropVolume_Callback(hObject, eventdata, handles)
% hObject    handle to cropVolume (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

[I,rect] = imcrop; 
s = handles.image.CData;
switch handles.viewtype
    case 1
        [r,c,z]  = size(s); 
        oimg = crop3d(s,rect,[1 z]);
    case 2
%         s = permute(img,[3 2 1]);
%         s = flipdim(s,1);
        [r,c,z]  = size(s); 
        oimg = crop3d(s,rect,[1 z]);
    case 3
%         s = permute(img,[3 1 2]);
%         s = flipdim(s,1);
        [r,c,z]  = size(s); 
        oimg = crop3d(s,rect,[1 z]);
    otherwise;
end
imlook3d(oimg);



⌨️ 快捷键说明

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