You are on page 1of 10

Anexo:

Programa de Tratamiento de Imgenes Mdicas


function varargout = Tratamiento_de_Imagenes_Medicas(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn',
@Tratamiento_de_Imagenes_Medicas_OpeningFcn, ...
'gui_OutputFcn',
@Tratamiento_de_Imagenes_Medicas_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
function Tratamiento_de_Imagenes_Medicas_OpeningFcn(hObject, eventdata,
handles, varargin)
axes(handles.axes2)
handles.output = hObject;
handles.hidden = [];
guidata(hObject, handles);
colormap gray(256)
if isempty(varargin) && ischar (varargin{1})
handles.dfolder = varargin{1};

SetFolder(handles);
ListBox_Callback(hObject, eventdata, handles);
else
newFolder_Callback(hObject, eventdata, handles)
end
function newFolder_Callback(hObject, eventdata, handles)
axes(handles.axes2)
P = fileparts(mfilename('fullpath'));
nfolder=uigetdir(P,'Select DICOM Directory');
if ~ischar(nfolder)
disp('no valid Directory selected.')
return;
end
handles.dfolder=nfolder;
guidata(hObject, handles);
SetFolder(handles);
ListBox_Callback(hObject, eventdata, handles)
function SetFolder (handles)
axes(handles.axes2)
dfiles=dir(handles.dfolder);
dfiles=dfiles(3:end);
% avoid . and ..
nfiles=length(dfiles);
if nfiles<1
disp('no files availabel.')
return;
end
set(handles.ListBox,'String',char(dfiles.name),'value',1);
s = [num2str(nfiles) ' files in: ' handles.dfolder];
set(handles.NofFiles,'String', s);
guidata(handles.figure1, handles);
function ListBox_CreateFcn(hObject)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function HeaderList_CreateFcn(hObject, eventdata, handles)
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in ListBox.
function ListBox_Callback(hObject, eventdata, handles)
axes(handles.axes2)
fname = get(handles.ListBox,'String');
fname = fname(get(handles.ListBox,'value'),:);
try
metadata = dicominfo([handles.dfolder '\' fname]);
catch

disp ('apparently not a DICOM file');


return
end
img
= dicomread([handles.dfolder '\' fname]);
imagesc(img);
axis off
ch = get(handles.HeaderList, 'value');
fields=char(fieldnames(metadata));
len = setdiff (1:size(fields,1), handles.hidden);
id=0;
for k=len,
estr=eval(['metadata.' fields(k,:)]);
if ischar(estr)
str=[fields(k,:) ' : ' estr];
elseif isnumeric(estr)
str=[fields(k,:) ' : ' num2str(estr(1:min(3,end))')];
else
str=[fields(k,:) ' : ...'];
end
id = id+1;
cstr{id}=sprintf('%3d %s',k,str);
end
set(handles.HeaderList,'Value',ch);
set(handles.HeaderList,'String',cstr);
guidata(hObject, handles);
return;
function cmdHide_Callback(hObject, eventdata, handles)
st = get (handles.HeaderList, 'string');
hide = get(handles.HeaderList, 'value');
if length(hide)==length(st)
disp ('WARNING: at least one field must be shown');
return
end
hidev=[];
for id=hide
hidev = [hidev str2num(st{id}(1:3))];
end
handles.hidden = union (handles.hidden, hidev);
set(handles.HeaderList,'Value',1);
guidata (hObject, handles);
ListBox_Callback(hObject, eventdata, handles);
function cmdShowAll_Callback(hObject, eventdata, handles)
handles.hidden = [];
guidata (hObject, handles);
ListBox_Callback(hObject, eventdata, handles);
function axes2_CreateFcn(hObject, eventdata, handles)
axis off
function axes1_CreateFcn(hObject, eventdata, handles)
[x,map]=imread('Dibujo7.bmp','bmp');
image(x)
colormap(map)
axis off

function pushbutton4_Callback(hObject, eventdata, handles)


opc=questdlg('Desea salir del programa?','SALIR','Si','No','No');
if strcmp(opc,'No')
return;
end
clear,clc,close all
function popupmenu2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function popupmenu3_Callback(hObject, eventdata, handles)
guidata(hObject,handles)
a=get(hObject,'Value');
set(handles.popupmenu3,'Value',a);
switch a
case 2
[FileName Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName,0)
return
else
a=imread(strcat(Path,FileName));
imshow(a);
end
rgb=strcat(Path,FileName);
[FileName_2 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName_2,0)
return
else
a=imread(strcat(Path,FileName_2));
imshow(a);
end
rgb2=strcat(Path,FileName_2);
axes(handles.axes2)
subplot(1,2,1); imshow(rgb);
subplot(1,2,2); imshow(rgb2);
case 3
[FileName Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName,0)
return
else
a=imread(strcat(Path,FileName));
imshow(a);
end
rgb=strcat(Path,FileName);
[FileName_2 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName_2,0)
return
else
a=imread(strcat(Path,FileName_2));
imshow(a);
end
rgb2=strcat(Path,FileName_2);

[FileName_3 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');


if isequal(FileName_3,0)
return
else
a=imread(strcat(Path,FileName_3));
imshow(a);
end
rgb3=strcat(Path,FileName_3);
axes(handles.axes2)
subplot(1,3,1), imshow(rgb);
subplot(1,3,2), imshow(rgb2);
subplot(1,3,3), imshow(rgb3);
case 4
[FileName Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName,0)
return
else
a=imread(strcat(Path,FileName));
imshow(a);
end
rgb=strcat(Path,FileName);
[FileName_2 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName_2,0)
return
else
a=imread(strcat(Path,FileName_2));
imshow(a);
end
rgb2=strcat(Path,FileName_2);
[FileName_3 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName_3,0)
return
else
a=imread(strcat(Path,FileName_3));
imshow(a);
end
rgb3=strcat(Path,FileName_3);
[FileName_4 Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName_4,0)
return
else
a=imread(strcat(Path,FileName_4));
imshow(a);
end
rgb4=strcat(Path,FileName_4);
axes(handles.axes2)
subplot(2,2,1); imshow(rgb);
subplot(2,2,2); imshow(rgb2);
subplot(2,2,3); imshow(rgb3);
subplot(2,2,4); imshow(rgb4);
end
function popupmenu3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');

end
function pushbutton5_Callback(hObject, eventdata, handles)
[FileName Path]=uigetfile({'*.jpg;*.bmp'},'Abrir Imagen');
if isequal(FileName,0)
return
else
a=imread(strcat(Path,FileName));
imshow(a);
end
handles.direccion=strcat(Path,FileName);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
helpdlg('La ayuda esta en construcin','TRATAMIENTO DE IMAGENES MEDICAS')
% --- Executes on selection change in popupmenu4.
function popupmenu4_Callback(hObject, eventdata, handles)
color={'y';'m';'c';'r';'g';'b';'w';'k'};
whitebg(char(color(get(hObject,'value'))))
function popupmenu4_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit17_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function pushbutton9_Callback(hObject, eventdata, handles)
% f=imread('*.bmp','bmp');
% imwrite(f,'nombre_de_fichero')
% imwrite(f,'unidad:ruta\nombre_de_fichero')
function pushbutton12_Callback(hObject, eventdata, handles)
function axes2_DeleteFcn(hObject, eventdata, handles)
function radiobutton1_Callback(hObject, eventdata, handles)
axes(handles.axes3) %con esto selecciona el eje a utilizar.
set(hObject,'value',1);
set(handles.radiobutton2,'value',0);
function radiobutton2_Callback(hObject, eventdata, handles)
axes(handles.axes4) %con esto selecciona el eje a utilizar.
set(h,'value',1);
set(handles.radiobutton1,'value',0);
function popupmenu5_Callback(hObject, eventdata, handles)
guidata(hObject,handles)
a=get(hObject,'Value');
set(handles.popupmenu5,'Value',a);

switch a
case 2
axes(handles.axes3)
fname = get(handles.ListBox,'String');
fname = fname(get(handles.ListBox,'value'),:);
axes(handles.axes3)
imgtoread=1;%si se va a leer mas de una imagen dentro del ciclo el numero
cambia.
for i=imgtoread:-1:1
[D(:,:,i),map] = (dicomread(fname));
imshow(D(:,:,i),map)
axes(handles.axes3)
end
case 3
axes(handles.axes4)
%*******separated filter difference
H2=[0 0 0;1 0 -1;0 0 0];
V2=[0 -1 0;0 0 0;0 1 0];
%********roberts
H3=[0 0 -1;0 1 0;0 0 0];
V3=[-1 0 0;0 1 0;0 0 0];
%********prewitt
H4=0.3.*[1 0 -1;1 0 -1;1 0 -1];
V4=0.3.*[-1 -1 -1;0 0 0;1 1 1];
%*******sobel
H5=0.25.*[1 0 -1;2 0 -2;1 0 -1];
V5=0.25.*[-1 -2 -1;0 0 0;1 2 1];
%***************************
fname = get(handles.ListBox,'String');
fname = fname(get(handles.ListBox,'value'),:);
axes(handles.axes4)
filtertipe=get(handles.popupmenu2,'Value');%esta variable contrale el
filtro aplicado a la imagen.
imgtoread=1;%si se va a leer mas de una imagen dentro del ciclo el numero
cambia.
for i=imgtoread:-1:1
[D(:,:,i),map] = (dicomread(fname));
X=double(D(:,:,i))./255;%promediamor y convertimor el valor de la
imagen
if (filtertipe == 0)
cH=conv2(X,H2);
cV=conv2(X,V2);
c=cH+cV;
elseif (filtertipe == 1)
cH=conv2(X,H3);
cV=conv2(X,V3);
c=cH+cV;
elseif (filtertipe == 2)
cH=conv2(X,H4);
cV=conv2(X,V4);
c=cH+cV;
elseif (filtertipe == 3)
cH=conv2(X,H5);
cV=conv2(X,V5);
c=cH+cV;

end;
imshow(abs(c))
end
case 4
axes(handles.axes5)
fname = get(handles.ListBox,'String');
fname = fname(get(handles.ListBox,'value'),:);
imgtoread=3;%si se va a leer mas de una imagen dentro del ciclo el numero
cambia.
for i=imgtoread:-1:1
[D(:,:,i),map] = (dicomread(fname));
X=double(D(:,:,i))./255;%promediamor y convertimor el valor de la
images
bw=edge(X,'canny',0.5,1);
imshow(bw)
end
end
function popupmenu5_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function axes3_CreateFcn(hObject, eventdata, handles)
axis off
function axes4_CreateFcn(hObject, eventdata, handles)
axis off
function axes5_CreateFcn(hObject, eventdata, handles)
axis off
function popupmenu2_Callback(hObject, eventdata, handles)
guidata(hObject,handles)
a=get(hObject,'Value');
set(handles.popupmenu5,'Value',a);
switch a
case 2
handles.popupmenu2==1;
case 3
handles.popupmenu2==2;
case 4
handles.popupmenu2==3;
end