diff options
-rw-r--r-- | gui_win.m | 152 |
1 files changed, 85 insertions, 67 deletions
@@ -44,11 +44,6 @@ end % End initialization code - DO NOT EDIT - - - - - % --- Executes just before gui_win is made visible. function gui_win_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. @@ -121,20 +116,74 @@ global background_m; % If we need to substract the background, we do it % background_m is a global variable if get(handles.button2substract,'Value') > 0 - m = image_display - background_m; +% m = image_display - background_m; else - m = image_display; +% m = image_display; end; -% Read the tolerance value from the GUI -tol = str2num(get(handles.readtolerance,'String')); +[Ny, Nx] = size(image_display); % Display what we have before doing fit axes(handles.image2display); -imagesc(m); -set(handles.image2display,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1]); +imagesc(image_display); +% we need specific aspect ratio for images for them not to be stretched +set(handles.image2display,'PlotBoxAspectRatio',[Nx Ny 1],'DataAspectRatio',[1 1 1]); drawnow; +% display cross lines if needed +if get(handles.showcross,'Value') + display_cross_marks_and_cross_sections(handles) +end + + + + + +function display_cross_marks_and_cross_sections(handles) +global cross_coordinates; +global image_display; +[Ny, Nx] = size(image_display); +if any( isnan(cross_coordinates) ) + % cross coordinates are undefined no need to draw cross +else + x0=cross_coordinates(1); + y0=cross_coordinates(2); + hline_x=[1,Nx]; + hline_y=[y0,y0]; + vline_x=[x0,x0]; + vline_y=[1,Ny]; + cross_color = 'white'; + cross_line_width =2; + % show cross marks + axes(handles.image2display); + hold on; + plot(hline_x, hline_y, 'LineWidth', cross_line_width, 'Color', cross_color); + plot(vline_x, vline_y, 'LineWidth', cross_line_width, 'Color', cross_color); +end + +% define actual image cross sections +if any( isnan(cross_coordinates) ) + % we just assign bunch of zeros for dummy cross sections + vsection = image_display(:,1)*NaN; + hsection = image_display(1,:)*NaN; +else + x0=cross_coordinates(1); + y0=cross_coordinates(2); + % define displayed image cross section + vsection = image_display(:,x0); + hsection = image_display(y0,:); +end +% draw above cross sections +% vertical +axes(handles.ysectiondisplay); +hold off; +h = plot(vsection); +set(h,'Color','red','LineWidth',2); +% horizontal +axes(handles.xsectiondisplay); +hold off; +h = plot(hsection); +set(h,'Color','red','LineWidth',2); function grab_image_and_update_display(handles) @@ -165,7 +214,6 @@ global image_cleaned; global image_fitted; image_cleaned = 0; image_fitted = 0; -set(handles.showcross,'Value',0); set(handles.chooseoriginal,'Value',1); isworking =1; % Paint the button and change text @@ -221,7 +269,6 @@ image_cleaned = 0; image_fitted = 0; isworking =1; set(handles.chooseoriginal,'Value',1); -set(handles.showcross,'Value',0); if image_display > 0 image_display = image_original; display_stuff(handles); @@ -230,7 +277,6 @@ end; % This calls a file-open dialog and runs the beam profiler on the choosen % file if get(handles.button2loadimage,'Value') - set(handles.showcross,'Value',0); set(handles.button2start,'Value',1); set(handles.button2start,'BackgroundColor','Red'); set(handles.button2start,'String','STOP'); @@ -283,11 +329,6 @@ if (isworking == 1) else isworking = 1; set(handles.button2clean,'String','Working'); - if get(handles.showcross,'Value') - set(handles.showcross,'Value',0); - image_display=image_display+image_negative; - end; - %read the attenuation from the GUI filter = str2num(get(handles.readstrength,'String')); radius = str2num(get(handles.readrange,'String')); @@ -716,7 +757,6 @@ global image_display; global image_original; global image_cleaned; global image_fitted; -set(handles.showcross,'Value',0); if get(handles.chooseoriginal,'Value') image_display=image_original; display_stuff(handles); @@ -746,64 +786,42 @@ else end; -%To show the cross on the screen +function x=check_bound(x,xleft,xright) +% check if number out of bound and then assign it to the mid of the region +if xleft > xright + % sanity check for bounds + tmp=xright; + xright=xleft; + xleft=tmp; +end +if x<xleft || x>xright + x=(xleft+xright)/2; +end + +%To show the cross on the screen we need to get its coordinates % --- Executes on button press in showcross. function showcross_Callback(hObject, eventdata, handles) % hObject handle to showcross (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) +global cross_coordinates; global image_display; -global image_cross; -global image_negative; -global background_m; -if get(handles.button2substract,'Value') > 0 - image_display = image_display - background_m; -end; -[sizey sizex] = size(image_display); -image_cross=image_display; - +[Ny, Nx] = size(image_display); if get(handles.showcross,'Value') - if image_display == 0 - set(handles.showcross,'Value',0) - else - [x0,y0]=ginput(1); - x0=round(x0); - y0=round(y0); - max2 = max(image_display(:)); - - % Here we draw crossections - hold off; - axes(handles.ysectiondisplay); - h = plot(image_display(:,x0)); - hold on; - set(h,'Color','red','LineWidth',2); - - - hold off; - axes(handles.xsectiondisplay); - h = plot(image_display(y0,:)); - set(h,'Color','red','LineWidth',2); - - - - %draw cross on the image - for y=1:sizey - image_cross(y,x0) = max(max2,image_display(y,x0)); - end; - for x=1:sizex - image_cross(y0,x) = max(max2,image_display(y0,x)); - end; - - image_negative = image_display-image_cross; - image_display = image_cross; - display_stuff(handles); - end; + [x0,y0]=ginput(1); + x0=check_bound(x0, 1, Nx); + y0=check_bound(y0, 1, Ny); + x0=round(x0); + y0=round(y0); + cross_coordinates = [x0,y0]; else - image_display=image_display+image_negative; - display_stuff(handles); + cross_coordinates = [NaN,NaN]; end; +display_stuff(handles); + + |