function varargout = CompressedSensing(varargin) % COMPRESSEDSENSING MATLAB code for CompressedSensing.fig % COMPRESSEDSENSING, by itself, creates a new COMPRESSEDSENSING or raises the existing % singleton*. % % H = COMPRESSEDSENSING returns the handle to a new COMPRESSEDSENSING or the handle to % the existing singleton*. % % COMPRESSEDSENSING('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in COMPRESSEDSENSING.M with the given input arguments. % % COMPRESSEDSENSING('Property','Value',...) creates a new COMPRESSEDSENSING or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before CompressedSensing_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to CompressedSensing_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 CompressedSensing % Last Modified by GUIDE v2.5 22-Jan-2019 13:41:52 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @CompressedSensing_OpeningFcn, ... 'gui_OutputFcn', @CompressedSensing_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 CompressedSensing is made visible. function CompressedSensing_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 CompressedSensing (see VARARGIN) handles.position=1; handles.axis='z'; set(handles.positionSlider,'Min', 1); set(handles.positionSlider,'Max', 100); set(handles.positionSlider,'value', 1); handles.rate=3; % Choose default command line output for CompressedSensing handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes CompressedSensing wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = CompressedSensing_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 slider movement. function positionSlider_Callback(hObject, eventdata, handles) % hObject handle to positionSlider (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 handles.position = get(hObject,'Value'); showImAndParam(handles); guidata(hObject,handles); % --- Executes during object creation, after setting all properties. function positionSlider_CreateFcn(hObject, eventdata, handles) % hObject handle to positionSlider (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. if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]); end function directoryText_Callback(hObject, eventdata, handles) % hObject handle to directoryText (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,'String') returns contents of directoryText as text % str2double(get(hObject,'String')) returns contents of directoryText as a double %zaladowanie plikow path=get(hObject,'String'); collection=dicomCollection(path); volume=dicomreadVolume(collection); handles.volume=squeeze(volume); handles.rangeV=size(handles.volume); range=handles.rangeV(3); % ustawienie odpowiedniego zakresu suwaka set(handles.positionSlider,'Max',range); set(handles.positionSlider,'SliderStep',[1/(range-1), 10/(range-1)]); % wyznaczenie maski probkowania dla kazdej osi im=squeeze(handles.volume(:,:,round(handles.rangeV(3)/2))); handles.maskZ=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(round(handles.rangeV(1))/2,:,:)); handles.maskX=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(:,round(handles.rangeV(2))/2,:)); handles.maskY=createSamplingMask(im, handles.rate); % wyswietlanie podgladu w panelu wyboru osi Vd=double(handles.volume); sn = round(size(Vd)/2); Vd = permute(Vd, [2 1 3]); ax1 = handles.view3DAxes; axes(ax1) hslc=slice(Vd, sn(1) ,sn(2),sn(3)); axis equal; axis vis3d; set(hslc(1:3),'LineStyle','none'); ax2 = handles.orientationAxes; axes(ax2); plot3([0 1],[0 0],[0 0],'r',[0 0],[0 1],[0 0],'g',[0 0],[0 0],[0 1],'b','linewidth',2); axis([-0.2 1 -0.2 1 -0.2 1]) xlabel(ax2,'X'); ylabel(ax2,'Y'); zlabel(ax2,'Z'); hlink = linkprop([ax1,ax2],{'CameraPosition','CameraUpVector'}); setappdata(CompressedSensing, 'theLink', hlink); rotate3d on showImAndParam(handles); guidata(hObject,handles); % --- Executes during object creation, after setting all properties. function directoryText_CreateFcn(hObject, eventdata, handles) % hObject handle to directoryText (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in directoryButton. function directoryButton_Callback(hObject, eventdata, handles) % hObject handle to directoryButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % zaladowanie plikow path=uigetdir; set(handles.directoryText,'string',path); collection=dicomCollection(path); volume=dicomreadVolume(collection); handles.volume=squeeze(volume); handles.rangeV=size(handles.volume); range=handles.rangeV(3); % wyznaczenie maski probkowania dla kazdej osi im=squeeze(handles.volume(:,:,round(handles.rangeV(3)/2))); handles.maskZ=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(round(handles.rangeV(1))/2,:,:)); handles.maskX=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(:,round(handles.rangeV(2))/2,:)); handles.maskY=createSamplingMask(im, handles.rate); % ustawienie odpowiedniego zakresu suwaka set(handles.positionSlider,'Max',range); set(handles.positionSlider,'SliderStep',[1/(range-1), 10/(range-1)]); % wyswietlanie podgladu w panelu wyboru osi Vd=double(handles.volume); sn = round(size(Vd)/2); Vd = permute(Vd, [2 1 3]); ax1 = handles.view3DAxes; axes(ax1) hslc=slice(Vd, sn(1) ,sn(2),sn(3)); axis equal; axis vis3d; set(hslc(1:3),'LineStyle','none'); ax2 = handles.orientationAxes; axes(ax2); plot3([0 1],[0 0],[0 0],'r',[0 0],[0 1],[0 0],'g',[0 0],[0 0],[0 1],'b','linewidth',2); axis([-0.2 1 -0.2 1 -0.2 1]) xlabel(ax2,'X'); ylabel(ax2,'Y'); zlabel(ax2,'Z'); hlink = linkprop([ax1,ax2],{'CameraPosition','CameraUpVector'}); setappdata(CompressedSensing, 'theLink', hlink); rotate3d on % aktualizacja okna i zmiennych showImAndParam(handles); guidata(hObject,handles); % --- Executes on button press in ZaxisRadioButton. function ZaxisRadioButton_Callback(hObject, eventdata, handles) % hObject handle to ZaxisRadioButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of ZaxisRadioButton set(handles.positionSlider, 'Value', 1); handles.position=1; handles.axis = 'z'; range=handles.rangeV(3); set(handles.positionSlider,'Max',range); set(handles.positionSlider,'SliderStep',[1/(range-1), 10/(range-1)]); showImAndParam(handles); guidata(hObject, handles); % --- Executes on button press in yaxisRadioButton. function yaxisRadioButton_Callback(hObject, eventdata, handles) % hObject handle to yaxisRadioButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of yaxisRadioButton set(handles.positionSlider, 'Value', 1); handles.position=1; handles.axis = 'y'; range=handles.rangeV(2); set(handles.positionSlider,'Max',range); set(handles.positionSlider,'SliderStep',[1/(range-1), 10/(range-1)]); showImAndParam(handles); guidata(hObject, handles); % --- Executes on button press in xaxisRadioButton. function xaxisRadioButton_Callback(hObject, eventdata, handles) % hObject handle to xaxisRadioButton (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of xaxisRadioButton % handles=guidata(hObject); set(handles.positionSlider, 'Value', 1); handles.position=1; handles.axis = 'x'; range=handles.rangeV(1); set(handles.positionSlider,'Max',range); set(handles.positionSlider,'SliderStep',[1/(range-1), 10/(range-1)]); showImAndParam(handles); guidata(hObject, handles); function rate_Callback(hObject, eventdata, handles) % hObject handle to rate (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,'String') returns contents of rate as text % str2double(get(hObject,'String')) returns contents of rate as a double handles.rate=str2double(get(hObject,'String')); % wyznaczenie masek dla nowego wskaznika probkowania im=squeeze(handles.volume(:,:,round(handles.rangeV(3)/2))); handles.maskZ=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(round(handles.rangeV(1))/2,:,:)); handles.maskX=createSamplingMask(im, handles.rate); im=squeeze(handles.volume(:,round(handles.rangeV(2))/2,:)); handles.maskY=createSamplingMask(im, handles.rate); showImAndParam(handles); guidata(hObject, handles); % --- Executes during object creation, after setting all properties. function rate_CreateFcn(hObject, eventdata, handles) % hObject handle to rate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function showImAndParam(handles) %SHOWIMANDPARAM Funkcja aktualizujaca widok okna % % Aktualizuje wyswietlanie aktualnie wybranego obrazu, dokonuje jego % rekonstrukcji oraz wyswietla wskazniki jakosci tej rekonstrukcji %wybranie obrazu z wolumenu danych dla zadanej osi i pozycji suwaka currentAxis=handles.axis; p=floor(handles.position); switch currentAxis case 'x' im=handles.volume(p,:,:); mask=handles.maskX; case 'y' im=handles.volume(:,p,:); mask=handles.maskY; case 'z' im=handles.volume(:,:,p); mask=handles.maskZ; end im=squeeze(im); im=imadjust(im); im=im2double(im); axes(handles.normalAxes); imshow(im); % rekonstrukcja obrazu % mask=createSamplingMask(im,2); imSparse=abs(imageCS(im,mask)); axes(handles.sparseAxes); imshow(imSparse); % wyliczenie wskaznikow jakosci: bled sredniokwadratowy, SNR, mapa % wskaznika podobienstwa strukturalnego mse=immse(imSparse, im); set(handles.mseText,'String',num2str(mse)); [~, snr] = psnr(imSparse, im); set(handles.snrText,'String',num2str(snr)); [~, ssimmap] = ssim(imSparse, im); axes(handles.ssimAxes); imshow(ssimmap,[]);