在matlab中打开dicom文件时我得到了黑色图像
我打开dicom文件的代码
[real_image,real_path] = uigetfile( ...
{'*.*;','File Dicom (*.dcm)';},...
'Open Image');
if ~isequal(real_image,0)
handles.image = dicomread(fullfile(real_path,real_image));
guidata(hObject,handles);
axes(handles.axes1);
imshow(handles.image);
set(handles.text5,'String',real_image);
set(handles.text6,'String',real_path);
[row,column]=size(handles.image);
set(handles.text7,'String',row);
set(handles.text8,'String',column);
else
return;
end
答案 0 :(得分:0)
我已经通过创建GUI(R2012b)并在按钮回调中插入代码来测试您的代码,它运行正常。
所以我可以看到两种可能性:
- 您以某种方式加载的dcom
图像已损坏
- dcom
图片很好,这是contrast
我会选择第二种可能性。
我使用从DICOM sample image sets下载的dcom
图片“CARDIX”作为示例。
当加载其中一个图像时,它似乎是黑色,轴的clim
是[0 65535
]。
如果您将clim
范围分别设置为dcom图像数据值的minimum
和maximum
值,则可以开始“看到某些内容”。
要进一步增强图像的可见性,您可以使用imcontrast tool。
在下文中,您可以找到GUI的.m
文件:imcontrast tool
可以通过pushbutton
运行。
function varargout = adjust_contrast(varargin)
% ADJUST_CONTRAST MATLAB code for adjust_contrast.fig
% ADJUST_CONTRAST, by itself, creates a new ADJUST_CONTRAST or raises the existing
% singleton*.
%
% H = ADJUST_CONTRAST returns the handle to a new ADJUST_CONTRAST or the handle to
% the existing singleton*.
%
% ADJUST_CONTRAST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ADJUST_CONTRAST.M with the given input arguments.
%
% ADJUST_CONTRAST('Property','Value',...) creates a new ADJUST_CONTRAST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before adjust_contrast_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to adjust_contrast_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help adjust_contrast
% Last Modified by GUIDE v2.5 26-Dec-2015 10:44:54
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @adjust_contrast_OpeningFcn, ...
'gui_OutputFcn', @adjust_contrast_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 adjust_contrast is made visible.
function adjust_contrast_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 adjust_contrast (see VARARGIN)
% Choose default command line output for adjust_contrast
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes adjust_contrast wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = adjust_contrast_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 pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[real_image,real_path] = uigetfile( ...
{'*.dcm;','File Dicom (*.dcm)';},...
'Open Image');
if ~isequal(real_image,0)
handles.image = dicomread(fullfile(real_path,real_image));
guidata(hObject,handles);
axes(handles.axes1);
imshow(handles.image);
set(handles.text5,'String',real_image);
set(handles.text6,'String',real_path);
[row,column]=size(handles.image);
set(handles.text7,'String',row);
set(handles.text8,'String',column);
else
return;
end
% Set the "Clim" scale to the [min max] image values
set(gca,'clim',[min(min(handles.image)) max(max(handles.image))])
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
imcontrast
在下图中您可以看到:
- 显示为已加载的“黑色”图像
- 更新clim
范围后的第一个增强点
- 使用imcontrast tool
注意:您可以从MATLAB Central下载DCOMViewer。
希望这有帮助。