%  Demonstration for showing a film of the backpropagation
%  process in CT scanning
%
%  Version 1.4, 11/11-2002, Joergen Arendt Jensen
%  Version 1.5, 31/10-2005, Joergen Arendt Jensen
%        Axis adde on sinogram
%        Sliders change as base level and window size
%  Version 2.0, 27/10-2005, Joergen Arendt Jensen
%        New version with image display instead of movie
%   Version 2.1, October 29, 2018, JAJ
%      Adapted for newer versions of Matlab

%  Set default text font and line size

set(0,'defaultaxesfontsize',18);
set(0,'defaulttextfontsize',18);

clf
hp1=axes('position',[0.25 0.17 0.7 0.8]);  %  Window for display
axes(hp1)
colormap(gray)
axis off
zoom on

%  Place push buttons on the display

t1=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.9 0.15 0.08],...
             'Callback','load thorax_demo_data; load no_filter_thorax; cla; axis off; show_movie(ct_demo_image, frame_no, dx, 2, 1); img=thorax;',...
             'String','Thorax film', 'fontsize',18);

t2=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.8 0.15 0.08],...
             'Callback','load head_demo_data; load no_filter_head; cla; axis off; show_movie(ct_demo_image, frame_no, dx, 2, 1); img=head;',...
             'String','Head film', 'fontsize',18);

t3=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.7 0.15 0.08],...
             'Callback','load torso_demo_data; load no_filter_torso; cla; axis off; show_movie(ct_demo_image, frame_no, dx, 2, 1); img=torso;',...
             'String','Torso film', 'fontsize',18);


t4=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.6 0.15 0.08],...
             'Callback','cla; axis off;  show_movie(ct_demo_image, frame_no, dx, 5, 3);',...
             'String','Play film', 'fontsize',18);

t5=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.5 0.15 0.08],...
             'Callback','cla; axis off; show_movie(ct_demo_image, frame_no, dx, 5, 6);',...
             'String','Play film slow', 'fontsize',18);


t6=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.4 0.15 0.08],...
             'Callback','th=show_image(img, dx, s1, s2);',...
             'String','Show full image', 'fontsize',18);

t7=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.3 0.15 0.08],...
             'Callback','th=show_image(ct_image_no_filter, dx,s1,s2); caxis(''auto'');',...
             'String','Image no filter', 'fontsize',18);

t8=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.2 0.15 0.08],...
             'Callback','imagesc((1:200)/200*180,((1:512)-256)*dx*1000,ct_data); colormap(gray); xlabel(''Vinkel [deg.]''); ylabel(''Afstand [mm]'');',...
             'String','Sinogram', 'fontsize',18);

t9=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.1 0.15 0.08],... 
             'Callback','set(s1,''Value'',0); set(s2,''Value'',1); caxis([get(s1,''Value'')*3000 get(s2,''Value'')*3000]);',... 
             'String','Reset color', 'fontsize',18); 
 
%  Sliders for determining contrast

s1=uicontrol('Style','slider','Units','normalized','Position',[0.25 0.08 0.7 0.02],... 
             'Callback','caxis([get(s1,''Value'') get(s1,''Value'')+get(s2,''Value'')]*3000); show_values(th,[get(s1,''Value'') get(s2,''Value'')]*3000);',... 
             'String','Min.', 'fontsize',18); 

s2=uicontrol('Style','slider','Units','normalized','Position',[0.25 0.04 0.7 0.02],... 
             'Callback','caxis([get(s1,''Value'') get(s1,''Value'')+get(s2,''Value'')]*3000); show_values(th,[get(s1,''Value'') get(s2,''Value'')]*3000);',... 
             'String','Max.', 'fontsize',18); 
set(s2,'Value',1);

%  Load the initial film

disp('Loading inital data. Please wait ...')
load thorax_demo_data;
load no_filter_thorax; 
img=thorax;
th=show_image(img, dx,s1,s2);
% th=text(0.6,0.95,['Base level: ',num2str(round(get(s1,'Value')*3000-1000)),' Hu, Window: ',num2str(round(get(s2,'Value')*3000)),' Hu'],...
%    'Units','normalized','color',[1 1 1]);
% drawnow
