diff options
author | Eugeniy Mikhailov <evgmik@gmail.com> | 2012-09-18 14:54:23 -0400 |
---|---|---|
committer | Eugeniy Mikhailov <evgmik@gmail.com> | 2012-09-18 14:54:23 -0400 |
commit | 01fb2632d02c7bc03cb852cd2c632806a9f02c2e (patch) | |
tree | c5eba524bf555220b53ad0077fad8d0933a7bec6 /gui_win.m | |
parent | 47d51ea4ce15c26cd1cd81a5c0a2748235f309a5 (diff) | |
download | beam_profiler-01fb2632d02c7bc03cb852cd2c632806a9f02c2e.tar.gz beam_profiler-01fb2632d02c7bc03cb852cd2c632806a9f02c2e.zip |
reading and saving imaging logic is reworked
Diffstat (limited to 'gui_win.m')
-rw-r--r-- | gui_win.m | 103 |
1 files changed, 44 insertions, 59 deletions
@@ -22,7 +22,7 @@ function varargout = gui_win(varargin) % Edit the above text to modify the response to help gui_win -% Last Modified by GUIDE v2.5 17-Sep-2012 11:55:33 +% Last Modified by GUIDE v2.5 18-Sep-2012 14:31:11 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; @@ -71,6 +71,9 @@ global image_cleaned; global image_fitted; global image_cross; +global default_data_path; +default_data_path='Z:\beam_profiler_images'; + % Initial values background_m = 0; image_display = 0; @@ -282,20 +285,12 @@ if get(handles.button2loadimage,'Value') set(handles.button2start,'String','STOP'); drawnow; - if ~isstr(pathname) % undefined variables are 0 - pathname = 'Z:\beam_profiler images'; - end; - [filename, pathname, filterindex] = uigetfile( ... - { '*.png','PNG-files (*.png)';},'DefaultName',pathname); - - if isequal(filename,0) - else - img=imread(fullfile(pathname,filename)); + img=chose_and_read_image_from_file(); + if ~any(isnan(img)) image_display=double(img); image_original=image_display; display_stuff(handles); - - end; + end set(handles.button2loadimage,'Value',0); set(handles.button2start,'BackgroundColor','Green'); @@ -516,7 +511,8 @@ function button2save_Callback(hObject, eventdata, handles) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global image_display; -fname_to_save = horzcat('Z:\beam_profiler images',filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); +global default_data_path; +fname_to_save = horzcat(default_data_path,filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); set(handles.picsavepath,'String',horzcat('Image saved to: ',fname_to_save)); image_to_save=uint16(image_display); imwrite(image_to_save,fname_to_save,'png','bitdepth',16); @@ -526,74 +522,63 @@ imwrite(image_to_save,fname_to_save,'png','bitdepth',16); +function draw_backround_image(handles) +global background_m; +[Ny, Nx] = size(background_m); +axes(handles.backgrounddisplay); +imagesc(background_m); +set(handles.backgrounddisplay,'PlotBoxAspectRatio',[Nx Ny 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +display_stuff(handles); + % This executes when we want to grab the background from the camera -% --- Executes on button press in Grabfromcamera. -function Grabfromcamera_Callback(hObject, eventdata, handles) -% hObject handle to Grabfromcamera (see GCBO) +% --- Executes on button press in use_currently_displayed_as_background. +function use_currently_displayed_as_background_Callback(hObject, eventdata, handles) +% hObject handle to use_currently_displayed_as_background (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global background_m; global image_display; -global isworking; -isworking =1; -grabimage(handles); background_m = image_display; - -axes(handles.backgrounddisplay); -imagesc(background_m); -set(handles.backgrounddisplay,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); -drawnow; -isworking =0; +draw_backround_image(handles); % This executes when we want to choose the background from a file -% --- Executes on button press in readfromfile. -function readfromfile_Callback(hObject, eventdata, handles) -% hObject handle to readfromfile (see GCBO) +% --- Executes on button press in read_background_from_file. +function read_background_from_file_Callback(hObject, eventdata, handles) +% hObject handle to read_background_from_file (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) - global background_m; - -[filename, pathname, filterindex] = uigetfile( ... - { '*.png','PNG-files (*.png)';}); - -if isequal(filename,0) - - -else - img=imread(fullfile(pathname,filename)); +img=chose_and_read_image_from_file(); +if ~any(isnan(img)) background_m = double(img); - - axes(handles.backgrounddisplay); - imagesc(background_m); - set(handles.backgrounddisplay,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); - drawnow; -end; - - - - - - - - - - - - - - - + draw_backround_image(handles); +end +function img=chose_and_read_image_from_file() +global pathname; +global default_data_path; +% check if we have defined a pathname to look +if ~isstr(pathname) % undefined variables are 0 + pathname = default_data_path; +end; +% choose file to read +[filename, pathname, filterindex] = uigetfile( ... +{ '*.png','PNG-files (*.png)';},'DefaultName',pathname); +% read and update +if ~isequal(filename,0) + img=imread(fullfile(pathname,filename)); +else + img=NaN; +end; function readshutterspeed_Callback(hObject, eventdata, handles) |