function varargout = FBPdemo(varargin)
% FBPDEMO M-file for FBPdemo.fig
%      FBPDEMO, by itself, creates a new FBPDEMO or raises the existing
%      singleton*.
%
%      H = FBPDEMO returns the handle to a new FBPDEMO or the handle to
%      the existing singleton*.
%
%      FBPDEMO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in FBPDEMO.M with the given input arguments.
%
%      FBPDEMO('Property','Value',...) creates a new FBPDEMO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before FBPdemo_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to FBPdemo_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 FBPdemo

% Last Modified by GUIDE v2.5 28-Feb-2006 10:56:18

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @FBPdemo_OpeningFcn, ...
                   'gui_OutputFcn',  @FBPdemo_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
global obj;
global pix;
global angles;
global RecOut;
global RecIm;
global butterworth_percent;
global butterworth_order;
global temp_display;
global line;
global plot_state;
global counts;
global colormaps;
global nseed;
global begin_pix;
global end_pix;

% --- Executes just before FBPdemo is made visible.
function FBPdemo_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 FBPdemo (see VARARGIN)

% Choose default command line output for FBPdemo
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

global obj;
global pix;
global angles;
global RecIm;
global RecOut;
global counts;
global colormaps;
global temp_display;
global plot_state;
global begin_pix;
global end_pix;


%load and display default image in original_image_axes window
set(hObject, 'Units', 'pixels'); 
load default_obj.mat; 
position = get(hObject, 'Position'); 
axes(handles.original_image_axes); 
imagesc(obj) 
colormap gray;
set(handles.original_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');

%initialize the global variables
counts=100000;
pix=64;
angles=pix;
RecIm = zeros(pix,pix);
RecOut = zeros(pix,pix);
butterworth_percent = 1;
butterworth_order = 1;
colormaps = 1;
temp = obj;
obj=temp;
temp_display = zeros(pix,pix);
plot_state = 1;
begin_pix = 1;
end_pix = pix;

%display empty axes window for projected_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
colormap gray;
imagesc(RecIm);
set(handles.projected_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');

%initialize num_proj_angles edit box
set(handles.num_proj_angles_edit,'String','64');
set(handles.butterworth_order_box,'String','1');
set(handles.butterworth_slide_edit_box,'String','1');

%display empty axes window for reconstructed_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes); 
colormap gray;
imagesc(RecIm);
set(handles.reconstructed_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');



% UIWAIT makes FBPdemo wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = FBPdemo_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;


function num_proj_angles_edit_Callback(hObject, eventdata, handles)
% hObject    handle to num_proj_angles_edit (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 num_proj_angles_edit as text
%        str2double(get(hObject,'String')) returns contents of num_proj_angles_edit as a double

global obj;
global pix;
global angles;

%check to make sure entry is a good numeric value
user_entry = str2num(get(hObject,'string')); 
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if (user_entry<0) 
    errordlg('You must enter a numeric value greater than 0' ,'Bad Input','modal') 
    return
end

%proceed with callback...
angels = user_entry;



% --- Executes on button press in project_image_button.
function project_image_button_Callback(hObject, eventdata, handles)
% hObject    handle to project_image_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global obj;
global angles;
global pix;
global RecOut;
global colormaps;
global plot_state;
global line;
global begin_pix;
global end_pix;

%get the number of projection angles from the num_proj_angles edit box
angles = str2num(get(handles.num_proj_angles_edit,'String'));

%do the projection and rebin to fit in axes window
RecIm = project2D(obj,angles);
RecOut = rebin(RecIm',pix);
RecOut = RecOut';

%display the projection in the projected_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end
switch plot_state
    case 1
        imagesc(RecOut);
        set(handles.projected_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix));
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end
        
    case 3
        x=begin_pix:1:end_pix;
        plot(x,RecOut(begin_pix:end_pix,line));
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end
    case 4
        surfc(RecOut);
        set(handles.projected_image_axes, ...
            'Visible', 'on', ... 
            'Units', 'pixels');   
end
% --- Executes during object creation, after setting all properties.
function num_proj_angles_edit_CreateFcn(hObject, eventdata, handles)
% hObject    handle to num_proj_angles_edit (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 backproject_button.
function backproject_button_Callback(hObject, eventdata, handles)
% hObject    handle to backproject_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


global RecOut;
global RecIm;
global temp_display;
global colormaps;
global plot_state;
global line;
global begin_pix;
global end_pix;

%create the backprojection
RecIm = backproject2D(RecOut);

%display the backprojection
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end

switch plot_state
    case 1
        imagesc(RecIm);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,RecIm(line,begin_pix:end_pix));
        if max(RecIm(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecIm(line,begin_pix:end_pix)) 1.1 .* max(RecIm(line,begin_pix:end_pix))]);
        end
    case 3
        x=begin_pix:1:end_pix;
        plot(RecIm(begin_pix:end_pix,line));
        if max(RecIm(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecIm(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end       
    case 4
        surfc(RecIm);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'on', ... 
            'Units', 'pixels');
end

%set the temp display variable for the reconstructed axis to RecIm
temp_display = RecIm;


% --- Executes on button press in load_image_button.
function load_image_button_Callback(hObject, eventdata, handles)
% hObject    handle to load_image_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global obj;
global pix;
global colormaps;
global plot_state;
global line;
global RecIm;
global RecOut;
global temp_display;
global begin_pix;
global end_pix;

RecIm = zeros(pix,pix);
RecOut = zeros(pix,pix);
temp_display = zeros(pix,pix);

%setup the load menu
[filename, pathname] = uigetfile( ...
{'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)';
   '*.m',  'M-files (*.m)'; ...
   '*.fig','Figures (*.fig)'; ...
   '*.mat','MAT-files (*.mat)'; ...
   '*.mdl','Models (*.mdl)'; ...
   '*.*',  'All Files (*.*)'}, ...
   'Pick a file');
%load the file
set(hObject, 'Units', 'pixels'); 
eval(['load ', filename]); 

%find size and display in original_image_axis
[pix N] = size(obj);
position = get(hObject, 'Position'); 
axes(handles.original_image_axes); 
line = pix/2;
begin_pix = 1;
end_pix = pix;

%display image in original image axes based on display setting
set(hObject, 'Units', 'pixels'); 
axes(handles.original_image_axes);
position = get(hObject, 'Position');
switch colormaps
            case 1
                colormap gray;
            case 2
                colormap jet;
            case 3 
                colormap HSV;
            case 4 
                colormap Summer;
            case 5 
                colormap bone;
end
        
switch plot_state
    case 1
        imagesc(obj) 
        set(handles.original_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        plot(obj(line,begin_pix:end_pix)); 
    case 3
        plot(obj(begin_pix:end_pix,line));
    case 4
        surfc(obj);
        set(handles.original_image_axes, ...
            'Visible', 'on', ... 
            'Units', 'pixels');
end
        
%setup the projected_image_axis with a blank screen
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5 
        colormap bone;
end
imagesc(zeros(pix,pix));
set(handles.projected_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');

%fill in the num_proj_angles text edit box
set(handles.num_proj_angles_edit,'String',pix);

%setup line
line = pix/2;
set(handles.line_num_box,'String',line);
set(handles.begin_pix_box,'String',begin_pix);
set(handles.end_pix_box,'String',end_pix);

%setup the reconstructed_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes); 
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end
imagesc(RecIm);
set(handles.reconstructed_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');


% --- Executes on button press in filter_button.
function filter_button_Callback(hObject, eventdata, handles)
% hObject    handle to filter_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global RecOut;
global butterworth_percent;
global butterworth_order;
global colormaps;
global plot_state;
global line;
global begin_pix;
global end_pix;

%filter the projection
RecOut = rampfilter(RecOut,butterworth_percent,butterworth_order);

%redisplay the image in the projected_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end

switch plot_state
    case 1
        imagesc(RecOut);
        set(handles.projected_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix));
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end
    case 3
        x=begin_pix:1:end_pix;
        plot(x,RecOut(begin_pix:end_pix,line));
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end
    case 4
        surfc(RecOut);
        set(handles.projected_image_axes, ... 
            'Visible', 'on', ... 
            'Units', 'pixels');
end

% --- Executes on button press in chop_neg_button.
function chop_neg_button_Callback(hObject, eventdata, handles)
% hObject    handle to chop_neg_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global RecIm;
global temp_display;
global colormaps;
global plot_state;
global line;
global begin_pix;
global end_pix;

[M N] = size(RecIm);
temp_display = RecIm;

%eliminate all negative entries from the reconstructed image
for i = 1:1:M
    for j = 1:1:N
        if temp_display(i,j)<0
            temp_display(i,j) = 0;
        end
    end
end

%redisplay the image
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes); 
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end

switch plot_state
    case 1
        imagesc(temp_display);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,temp_display(line,begin_pix:end_pix));
        if max(temp_display(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(temp_display(line,begin_pix:end_pix)) 1.1 .* max(temp_display(line,begin_pix:end_pix))]);
        end
    case 3
        x=begin_pix:1:end_pix;
        plot(x,temp_display(begin_pix:end_pix,line));
        if max(temp_display(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(temp_display(begin_pix:end_pix,line)) 1.1 .* max(temp_display(begin_pix:end_pix,line))]);
        end
    case 4
        surfc(temp_display);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'on', ... 
            'Units', 'pixels');
end


function butterworth_order_box_Callback(hObject, eventdata, handles)
% hObject    handle to butterworth_order_box (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 butterworth_order_box as text
%        str2double(get(hObject,'String')) returns contents of butterworth_order_box as a double

global butterworth_order;

%check to see if the entry is a valid number
user_entry = str2num(get(hObject,'string')); 
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if (user_entry<1) 
    errordlg('You must enter a numeric value greater than or equal to 1' ,'Bad Input','modal') 
    return
end

%round input to 0 decimal places 
butterworth_order = roundoff(str2num(get(hObject,'String')),0);

%set slider to new corresponding value
set(handles.butterworth_order_box,'String',num2str(butterworth_order));



% --- Executes during object creation, after setting all properties.
function butterworth_order_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to butterworth_order_box (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.
global butterworth_order;

%initialize butterworth_order
butterworth_order = 1;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%fill in display box with value
set(hObject,'String',num2str(butterworth_order));

% --- Executes on slider movement.
function butterworth_percent_slide_Callback(hObject, eventdata, handles)
% hObject    handle to butterworth_percent_slide (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 butterworth_percent;

%get new value and round to 2 decimal places
butterworth_percent = get(hObject,'Value');
butterworth_percent = roundoff(butterworth_percent,2);

%set slider to corresponding value
set(handles.butterworth_slide_edit_box,'String',butterworth_percent);



% --- Executes during object creation, after setting all properties.
function butterworth_percent_slide_CreateFcn(hObject, eventdata, handles)
% hObject    handle to butterworth_percent_slide (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.
global butterworth_percent;

if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end
set(hObject,'Value',1);


function butterworth_slide_edit_box_Callback(hObject, eventdata, handles)
% hObject    handle to butterworth_slide_edit_box (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 butterworth_slide_edit_box as text
%        str2double(get(hObject,'String')) returns contents of butterworth_slide_edit_box as a double

global butterworth_percent;

%get user entry and check to see if valid
user_entry = str2num(get(hObject,'string')); 
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if ((user_entry > 1)|(user_entry<0)) 
    errordlg('You must enter a numeric value between 0 and 1' ,'Bad Input','modal') 
    return
end

%set butterworth_percent to entry and set slide to corresponding value
butterworth_percent = user_entry;
set(handles.butterworth_percent_slide,'Value',butterworth_percent);

% --- Executes during object creation, after setting all properties.
function butterworth_slide_edit_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to butterworth_slide_edit_box (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.
global butterworth_percent;

%initialize butterworth_percent
butterworth_percent = 1;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in redisplay_img_button.
function redisplay_img_button_Callback(hObject, eventdata, handles)
% hObject    handle to redisplay_img_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global RecIm;
global temp_display;
global colormaps;
global plot_state;
global line;
global begin_pix;
global end_pix;

%redisplay the original image
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end

switch plot_state
    case 1
        imagesc(RecIm);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,RecIm(line,begin_pix:end_pix));
        if max(RecIm(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecIm(line,begin_pix:end_pix)) 1.1 .* max(RecIm(line,begin_pix:end_pix))]);
        end
    case 3
        x=begin_pix:1:end_pix;
        plot(x,RecIm(begin_pix:end_pix,line));
        if max(RecIm(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecIm(begin_pix:end_pix,line)) 1.1 .* max(RecIm(begin_pix:end_pix,line))]);
        end
    case 4
        surfc(RecIm);
        set(handles.reconstructed_image_axes, ... 
            'Visible', 'on', ... 
            'Units', 'pixels');
end

%set the temp display variable for the reconstructed axis to RecIm
temp_display = RecIm;


% --- Executes on selection change in plot_box.
function plot_box_Callback(hObject, eventdata, handles)
% hObject    handle to plot_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns plot_box contents as cell array
%        contents{get(hObject,'Value')} returns selected item from plot_box


% --- Executes during object creation, after setting all properties.
function plot_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to plot_box (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: listbox 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 line_num_box_Callback(hObject, eventdata, handles)
% hObject    handle to line_num_box (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 line_num_box as text
%        str2double(get(hObject,'String')) returns contents of line_num_box as a double
global line;
global pix;
global plot_state;
global begin_pix;
global end_pix;
global obj;
global RecOut;
global temp_display;

user_entry = str2num(get(hObject,'String'));

%check to see if the number entered is valid
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end
if ((user_entry < 0)|(user_entry > pix))
    errordlg(['You must enter a numeric value between 0 and ',num2str(pix)] ,'Bad Input','modal') 
    return
end

%set line to new valid entry
line = user_entry;

switch plot_state 
    case 2
        %display x profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(line,begin_pix:end_pix));   
        if max(temp_display(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(temp_display(line,begin_pix:end_pix)) 1.1 .* max(temp_display(line,begin_pix:end_pix))]);
        end

        %display x profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix)); 
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end

        %display x profile plot in original_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(line,begin_pix:end_pix)); 
        if max(obj(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(obj(line,begin_pix:end_pix)) 1.1 .* max(obj(line,begin_pix:end_pix))]);
        end

    case 3
        %display y profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(begin_pix:end_pix,line));   
        if max(temp_display(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(temp_display(begin_pix:end_pix,line)) 1.1 .* max(temp_display(begin_pix:end_pix,line))]);
        end
        
        %display y profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(begin_pix:end_pix,line)); 
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end
        
        %display y profile plot in original_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(begin_pix:end_pix,line)); 
        if max(obj(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(obj(begin_pix:end_pix,line)) 1.1 .* max(obj(begin_pix:end_pix,line))]);
        end
end

% --- Executes during object creation, after setting all properties.
function line_num_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to line_num_box (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.

global pix;
global line;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%initialize line and fill in display box
set(hObject,'String',num2str(32));
line = 32;

% --- Executes on button press in adjust_counts_button.
function adjust_counts_button_Callback(hObject, eventdata, handles)
% hObject    handle to adjust_counts_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global counts;
global RecOut;

%adjust the counts
RecOut = adjust_counts(RecOut,counts);


function num_counts_edit_box_Callback(hObject, eventdata, handles)
% hObject    handle to num_counts_edit_box (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 num_counts_edit_box as text
%        str2double(get(hObject,'String')) returns contents of num_counts_edit_box as a double
global counts;
user_entry = str2num(get(hObject,'String'));
%check to see if the number entered is valid
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end
if (user_entry < 0)
    errordlg('You must enter a numeric value greater than 0','Bad Input','modal') 
    return
end

%set global variable counts to the number user input
counts = user_entry;

% --- Executes during object creation, after setting all properties.
function num_counts_edit_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to num_counts_edit_box (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.
global counts;

%initialize counts
counts = 100000;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%fill in display box
set(hObject,'String',num2str(counts));


% --- Executes on button press in add_noise_button.
function add_noise_button_Callback(hObject, eventdata, handles)
% hObject    handle to add_noise_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

global RecOut;
global colormaps;
global nseed;
global plot_state;
global line;
global begin_pix;
global end_pix;

%add noise
RecOut = poisson(RecOut,nseed);

%redisplay the image in the projected_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end

switch plot_state
    case 1
        imagesc(RecOut);
        set(handles.projected_image_axes, ... 
            'Visible', 'off', ... 
            'Units', 'pixels');
    case 2
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix));
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end
    case 3
        x=begin_pix:1:end_pix;
        plot(RecOut(begin_pix:end_pix,line));
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end
    case 4
        surfc(RecOut);
        set(handles.projected_image_axes, ... 
            'Visible', 'on', ... 
            'Units', 'pixels');
end


% --- Executes on selection change in colormap_popup.
function colormap_popup_Callback(hObject, eventdata, handles)
% hObject    handle to colormap_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns colormap_popup contents as cell array
%        contents{get(hObject,'Value')} returns selected item from colormap_popup
global colormaps;

colormaps = get(hObject,'Value');

%adjust 3 axes to new colormap
switch colormaps
    case 1
        axes(handles.reconstructed_image_axes);
        colormap gray;
        axes(handles.projected_image_axes);
        colormap gray;
        axes(handles.original_image_axes);
        colormap gray;
    case 2
        axes(handles.reconstructed_image_axes);
        colormap jet;
        axes(handles.projected_image_axes);
        colormap jet;
        axes(handles.original_image_axes);
        colormap jet;
    case 3
        axes(handles.reconstructed_image_axes);
        colormap HSV;
        axes(handles.projected_image_axes);
        colormap HSV;
        axes(handles.original_image_axes);
        colormap HSV;
    case 4
        axes(handles.reconstructed_image_axes);
        colormap Summer;
        axes(handles.projected_image_axes);
        colormap Summer;
        axes(handles.original_image_axes);
        colormap Summer;
    case 5
        axes(handles.reconstructed_image_axes);
        colormap bone;
        axes(handles.projected_image_axes);
        colormap bone;
        axes(handles.original_image_axes);
        colormap bone; 
end

% --- Executes during object creation, after setting all properties.
function colormap_popup_CreateFcn(hObject, eventdata, handles)
% hObject    handle to colormap_popup (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
global colormaps;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%initialize colormaps to gray
colormaps = 1;



function nseed_box_Callback(hObject, eventdata, handles)
% hObject    handle to nseed_box (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 nseed_box as text
%        str2double(get(hObject,'String')) returns contents of nseed_box as a double
global nseed;

%get user entry and check to see if it is valid
user_entry = str2num(get(hObject,'String'));
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if (user_entry<0) 
    errordlg('You must enter a numeric value greater than 0' ,'Bad Input','modal') 
    return
end

%set nseed to new valid entry
nseed = user_entry;

% --- Executes during object creation, after setting all properties.
function nseed_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to nseed_box (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.
global nseed;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

%initalize nseed and set into display box
nseed = 1;
set(hObject,'String',num2str(nseed));



function begin_pix_box_Callback(hObject, eventdata, handles)
% hObject    handle to begin_pix_box (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 begin_pix_box as text
%        str2double(get(hObject,'String')) returns contents of begin_pix_box as a double
global begin_pix;
global end_pix;
global line;
global obj;
global temp_display;
global RecOut;
global plot_state;

user_entry = str2num(get(hObject,'String'));

%check to see if the number entered is valid
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if ((user_entry < 0)|(user_entry > end_pix))
    errordlg(['You must enter a numeric value between 0 and ',num2str(end_pix)] ,'Bad Input','modal') 
    return
end

begin_pix = user_entry;

switch plot_state 
    case 2
        %display x profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(line,begin_pix:end_pix));   
        if max(temp_display(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(temp_display(line,begin_pix:end_pix)) 1.1 .* max(temp_display(line,begin_pix:end_pix))]);
        end

        %display x profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix)); 
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end

        %display x profile plot in original_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(line,begin_pix:end_pix)); 
        if max(obj(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(obj(line,begin_pix:end_pix)) 1.1 .* max(obj(line,begin_pix:end_pix))]);
        end

    case 3
        %display y profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(begin_pix:end_pix,line));  
        if max(temp_display(begin_pix:end_pix,line)) > 0        
            axis([begin_pix end_pix min(temp_display(begin_pix:end_pix,line)) 1.1 .* max(temp_display(begin_pix:end_pix,line))]);
        end
        
        %display y profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(begin_pix:end_pix,line)); 
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end

        %display y profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(begin_pix:end_pix,line)); 
        if max(obj(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(obj(begin_pix:end_pix,line)) 1.1 .* max(obj(begin_pix:end_pix,line))]);
        end
end



% --- Executes during object creation, after setting all properties.
function begin_pix_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to begin_pix_box (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.
global begin_pix;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

begin_pix = 1;

set(hObject,'String',begin_pix);


function end_pix_box_Callback(hObject, eventdata, handles)
% hObject    handle to end_pix_box (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 end_pix_box as text
%        str2double(get(hObject,'String')) returns contents of end_pix_box as a double
% --- Executes during object creation, after setting all properties.

global begin_pix;
global end_pix;
global pix;
global line;
global obj;
global temp_display;
global RecOut;
global plot_state;

user_entry = str2num(get(hObject,'String'));

%check to see if the number entered is valid
if isnan(user_entry) 
    errordlg('You must enter a numeric value','Bad Input','modal') 
    return
end

if ((user_entry < begin_pix)|(user_entry > pix))
    errordlg(['You must enter a numeric value between the beginning pixel value and ',num2str(pix)] ,'Bad Input','modal') 
    return
end

end_pix = user_entry;

switch plot_state 
    case 2
        %display x profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(line,begin_pix:end_pix)); 
        if max(temp_display(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(temp_display(line,begin_pix:end_pix)) 1.1 .* max(temp_display(line,begin_pix:end_pix))]);
        end

        %display x profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(line,begin_pix:end_pix)); 
        if max(RecOut(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
        end

        %display x profile plot in original_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(line,begin_pix:end_pix)); 
        if max(obj(line,begin_pix:end_pix)) > 0
            axis([begin_pix end_pix min(obj(line,begin_pix:end_pix)) 1.1 .* max(obj(line,begin_pix:end_pix))]);
        end

    case 3
        %display y profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.reconstructed_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,temp_display(begin_pix:end_pix,line));  
        if max(temp_display(begin_pix:end_pix,line)) > 0        
            axis([begin_pix end_pix min(temp_display(begin_pix:end_pix,line)) 1.1 .* max(temp_display(begin_pix:end_pix,line))]);
        end
        
        %display y profile plot in projected_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.projected_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,RecOut(begin_pix:end_pix,line)); 
        if max(RecOut(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
        end

        %display y profile plot in reconstructed_image_axis
        set(hObject, 'Units', 'pixels'); 
        axes(handles.original_image_axes);
        position = get(hObject, 'Position');
        x=begin_pix:1:end_pix;
        plot(x,obj(begin_pix:end_pix,line)); 
        if max(obj(begin_pix:end_pix,line)) > 0
            axis([begin_pix end_pix min(obj(begin_pix:end_pix,line)) 1.1 .* max(obj(begin_pix:end_pix,line))]);
        end
end


function end_pix_box_CreateFcn(hObject, eventdata, handles)
% hObject    handle to end_pix_box (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.
global end_pix;

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

end_pix = 64;
set(hObject,'String',end_pix);

% --- Executes on button press in images_button.
function images_button_Callback(hObject, eventdata, handles)
% hObject    handle to images_button (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 images_button
global RecIm;
global temp_display;
global colormaps;
global RecOut;
global obj;
global plot_state;

plot_state=1;

%display the original image
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end
imagesc(RecIm);
set(handles.reconstructed_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');

%set the temp display variable for the reconstructed axis to RecIm
temp_display = RecIm;

%display the projection in the projected_image_axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end
imagesc(RecOut);
set(handles.projected_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');

%display original image in original_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.original_image_axes); 
position = get(hObject, 'Position');
imagesc(obj) 
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5 
        colormap bone;
end
set(handles.original_image_axes, ... 
    'Visible', 'off', ... 
    'Units', 'pixels');


% --- Executes on button press in x_prof_button.
function x_prof_button_Callback(hObject, eventdata, handles)
% hObject    handle to x_prof_button (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 x_prof_button
global temp_display
global RecOut;
global obj;
global line;
global plot_state;
global begin_pix;
global end_pix;

plot_state = 2;

%display x profile plot in reconstructed_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
x = begin_pix:1:end_pix;
plot(x,temp_display(line,begin_pix:end_pix));
if max(temp_display(line,begin_pix:end_pix)) > 0
    axis([begin_pix end_pix min(temp_display(line,begin_pix:end_pix)) 1.1 .* max(temp_display(line,begin_pix:end_pix))]);
end

%display x profile plot in projected_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
x = begin_pix:1:end_pix;
plot(x, RecOut(line,begin_pix:end_pix)); 
if max(RecOut(line,begin_pix:end_pix)) > 0
    axis([begin_pix end_pix min(RecOut(line,begin_pix:end_pix)) 1.1 .* max(RecOut(line,begin_pix:end_pix))]);
end

%display x profile plot in original_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.original_image_axes);
position = get(hObject, 'Position');
x=begin_pix:1:end_pix;
plot(x,obj(line,begin_pix:end_pix));
if max(obj(line,begin_pix:end_pix)) > 0
    axis([begin_pix end_pix min(obj(line,begin_pix:end_pix)) 1.1 .* max(obj(line,begin_pix:end_pix))]);
end


% --- Executes on button press in y_prof_button.
function y_prof_button_Callback(hObject, eventdata, handles)
% hObject    handle to y_prof_button (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 y_prof_button
global temp_display
global RecOut;
global obj;
global line;
global plot_state;
global begin_pix;
global end_pix;

plot_state=3;

%display y profile plot in reconstructed_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
x = begin_pix:1:end_pix;
plot(x,temp_display(begin_pix:end_pix,line));   
if max(temp_display(begin_pix:end_pix,line)) > 0
    axis([begin_pix end_pix min(temp_display(begin_pix:end_pix,line)) 1.1 .* max(temp_display(begin_pix:end_pix,line))]);
end

%display y profile plot in projected_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
x=begin_pix:1:end_pix;
plot(x,RecOut(begin_pix:end_pix,line)); 
if max(RecOut(begin_pix:end_pix,line)) > 0
    axis([begin_pix end_pix min(RecOut(begin_pix:end_pix,line)) 1.1 .* max(RecOut(begin_pix:end_pix,line))]);
end

%display y profile plot in original_image_axis
set(hObject, 'Units', 'pixels'); 
axes(handles.original_image_axes);
position = get(hObject, 'Position');
x=begin_pix:1:end_pix;
plot(x,obj(begin_pix:end_pix,line)); 
if max(RecOut(begin_pix:end_pix,line)) > 0
    axis([begin_pix end_pix min(obj(begin_pix:end_pix,line)) 1.1 .* max(obj(begin_pix:end_pix,line))]);
end



% --- Executes on button press in surf_button.
function surf_button_Callback(hObject, eventdata, handles)
% hObject    handle to surf_button (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 surf_button
global temp_display
global RecOut;
global obj;
global line;
global colormaps;
global plot_state;

plot_state = 4;

%display surface plot in reconstructed image axes
set(hObject, 'Units', 'pixels'); 
axes(handles.reconstructed_image_axes);
position = get(hObject, 'Position');
surfc(temp_display);
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end   
set(handles.reconstructed_image_axes, ...
    'Visible', 'on', ... 
    'Units', 'pixels');

%display surface plot in projected image axes
set(hObject, 'Units', 'pixels'); 
axes(handles.projected_image_axes);
position = get(hObject, 'Position');
surfc(RecOut);
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end   
set(handles.projected_image_axes, ...
    'Visible', 'on', ... 
    'Units', 'pixels');

%display surface plot in reconstructed image axes
set(hObject, 'Units', 'pixels'); 
axes(handles.original_image_axes);
position = get(hObject, 'Position');
surfc(obj);
switch colormaps
    case 1
        colormap gray;
    case 2
        colormap jet;
    case 3 
        colormap HSV;
    case 4 
        colormap Summer;
    case 5
        colormap bone;
end   
set(handles.original_image_axes, ...
    'Visible', 'on', ... 
    'Units', 'pixels');
