diff options
author | Mi Zhang <mzhang@email.wm.edu> | 2012-09-11 16:03:41 -0400 |
---|---|---|
committer | Mi Zhang <mzhang@email.wm.edu> | 2012-09-11 16:03:41 -0400 |
commit | d1d7a486cc70665dafe64aaddd44c58e228815b0 (patch) | |
tree | acbf530230d6860c9a85f5f1d67d0e445dde5192 | |
download | beam_profiler-d1d7a486cc70665dafe64aaddd44c58e228815b0.tar.gz beam_profiler-d1d7a486cc70665dafe64aaddd44c58e228815b0.zip |
initial commit
-rw-r--r-- | Gaussian2D.m | 15 | ||||
-rw-r--r-- | centerofmass.m | 18 | ||||
-rw-r--r-- | fitGaussian1D.m | 11 | ||||
-rw-r--r-- | fitgaussian2D.m | 101 | ||||
-rw-r--r-- | grabNimages_1394cam.exe | bin | 0 -> 180224 bytes | |||
-rw-r--r-- | gui_win.asv | 778 | ||||
-rw-r--r-- | gui_win.fig | bin | 0 -> 19224 bytes | |||
-rw-r--r-- | gui_win.m | 739 | ||||
-rw-r--r-- | stripeeraser.m | 15 |
9 files changed, 1677 insertions, 0 deletions
diff --git a/Gaussian2D.m b/Gaussian2D.m new file mode 100644 index 0000000..586ea36 --- /dev/null +++ b/Gaussian2D.m @@ -0,0 +1,15 @@ +function [z] = Gaussian2D(p,X,Y); + +cx = p(1); +cy = p(2); +wx = p(3); +wy = p(4); +amp = p(5); +theta = p(6); +background=p(7); +Xn = (X-cx)*cos(theta) - (Y-cy)*sin(theta); +Yn = (X-cx)*sin(theta) + (Y-cy)*cos(theta); + +%z = amp*(exp(-2*(Xn).^2./(wx^2)-2*(Yn).^2./(wy^2))) + background; + +z = amp*(exp(-2*((Xn).^2./(wx^2)+(Yn).^2./(wy^2)))) + background; diff --git a/centerofmass.m b/centerofmass.m new file mode 100644 index 0000000..7050145 --- /dev/null +++ b/centerofmass.m @@ -0,0 +1,18 @@ +% PURPOSE: find c of m of distribution +function [cx,cy,sx,sy] = centerofmass(m); + +[sizey sizex] = size(m); +vx = sum(m); +vy = sum(m'); + +vx = vx.*(vx>0); +vy = vy.*(vy>0); + +x = [1:sizex]; +y = [1:sizey]; + +cx = sum(vx.*x)/sum(vx); +cy = sum(vy.*y)/sum(vy); + +sx = sqrt(sum(vx.*(abs(x-cx).^2))/sum(vx)); +sy = sqrt(sum(vy.*(abs(y-cy).^2))/sum(vy)); diff --git a/fitGaussian1D.m b/fitGaussian1D.m new file mode 100644 index 0000000..b3fbb56 --- /dev/null +++ b/fitGaussian1D.m @@ -0,0 +1,11 @@ +function [z] = fitGaussian1D(p,v,x) + +cx = p(1); +wx = p(2); +amp = p(3); +background = p(4); + +zx = amp*exp(-2*(x-cx).^2./(wx^2)) - v - background; + + +z = sum(zx.^2); diff --git a/fitgaussian2D.m b/fitgaussian2D.m new file mode 100644 index 0000000..a6f3d10 --- /dev/null +++ b/fitgaussian2D.m @@ -0,0 +1,101 @@ +%% a function to fit a thermal cloud 2-D +function fp = fitgaussian2D(m,cx,cy,tol); +%% m = image +%% tol = fitting tolerance + +%Here we prepare a set of options to do our fits +options = optimset('Display','off','TolFun',tol,'LargeScale','off'); +theta = 0; +background=0; + +%We determine the size of an image +[sizey sizex] = size(m); +% guessing the widths +[tx,ty,sx,sy] = centerofmass(m); +sx = 2.*sx; +sy = 2.*sy; +%peak value +pOD = max(max(m)); + +%This is to avoid any possible access to some sells outside of the matrix +tmx = round(cy); +if isnan(tmx) > 0 + tmx = sizey/2; +end; +if round(cy) > sizey + tmx = sizey; +end; +if round(cy) < 1 + tmx = 1; +end; +mx = m(tmx,:); + + +%Here we do the 1D horizontal fit +%This is to give better initial parameters to our 2D fit +x1D = 1:sizex; +%Initiall parameters +ip1D = [cx,sx,pOD,background]; +fp1D = fminunc(@fitGaussian1D,ip1D,options,mx,x1D); + +cx = fp1D(1); +sx = fp1D(2); +PeakOD = fp1D(3); +background = fp1D(4); + +tmy = round(cx); +if isnan(tmy) > 0 + tmy = sizex/2; +end; +if round(cx) > sizex + tmy = sizex; +end; +if round(cx) < 1 + tmy = 1; +end; +my = m(:,tmy)'; + +y1D = 1:sizey; +ip1D = [cy,sy,PeakOD,background]; +%1D vertical fit +fp1D = fminunc(@fitGaussian1D,ip1D,options,my,y1D); + +cy = fp1D(1); +sy = fp1D(2); +PeakOD = fp1D(3); +background = fp1D(4); +[X,Y] = meshgrid(1:sizex,1:sizey); + +%Lower and upper limits for the 2D fit +LB = [1,1,1,1,0,-1.58,0]; +UB = [sizex,sizey,sizex*10,sizey*10,inf,1.58,inf]; + +% Here we do the 2D fit +options = optimset('lsqnonlin'); +options.Display = 'iter'; +options.TolFun = tol; +initpar = [cx,cy,sx,sy,PeakOD,theta,background]; +%this is to avoid errors when doing fits on the image full of zeros +if isnan(sum(sum(Gaussian2Dff(initpar,X,Y,m)))) < 1 + % Here is the actual fit + fp = lsqnonlin( @(pt) Gaussian2Dff(pt,X,Y,m),initpar,LB,UB,options); +else + fp = [0,0,0,0,0,0,0]; +end; + + + +% 2D Gauss function +function [z] = Gaussian2Dff(p,X,Y,m); + +cx = p(1); +cy = p(2); +wx = p(3); +wy = p(4); +amp = p(5); +theta = p(6); +background=p(7); +Xn = (X-cx)*cos(theta) - (Y-cy)*sin(theta); +Yn = (X-cx)*sin(theta) + (Y-cy)*cos(theta); + +z = amp*(exp(-2*((Xn).^2./(wx^2)+(Yn).^2./(wy^2)))) + background - m;
\ No newline at end of file diff --git a/grabNimages_1394cam.exe b/grabNimages_1394cam.exe Binary files differnew file mode 100644 index 0000000..1dff238 --- /dev/null +++ b/grabNimages_1394cam.exe diff --git a/gui_win.asv b/gui_win.asv new file mode 100644 index 0000000..6768549 --- /dev/null +++ b/gui_win.asv @@ -0,0 +1,778 @@ +function varargout = gui_win(varargin) +% gui_win MATLAB code for gui_win.fig +% gui_win, by itself, creates a new gui_win or raises the existing +% singleton*. +% +% H = gui_win returns the handle to a new gui_win or the handle to +% the existing singleton*. +% +% gui_win('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in gui_win.M with the given input arguments. +% +% gui_win('Property','Value',...) creates a new gui_win or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the gui_win before gui_win_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to gui_win_OpeningFcn via varargin. +% +% *See gui_win Options on GUIDE's Tools menu. Choose "gui_win allows only one +% instance to run (singleton)". +% +% See also: GUIDE, GUIDATA, GUIHANDLES + +% Edit the above text to modify the response to help gui_win + +% Last Modified by GUIDE v2.5 10-Sep-2012 11:34:46 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @gui_win_OpeningFcn, ... + 'gui_OutputFcn', @gui_win_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 gui_win is made visible. +function gui_win_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 gui_win (see VARARGIN) + +% Choose default command line output for gui_win +handles.output = hObject; + +% Update handles structure +guidata(hObject, handles); + +% Set color of the strart button to green +set(handles.togglebutton1,'BackgroundColor','Green'); + +% Declare global variables +global background_m; +global image_name; +global isworking; +global image_m; +global image_original; +global image_cleaned; +global image_fitted; + +% Initial values +background_m = 0; +image_m = 0; +image_original = 0; +image_cleaned = 0; +image_fitted = 0; +image_name = 'test.png'; +isworking = 0; + +% Don`t show ticks for the minor windows +set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +set(handles.xsection,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +set(handles.ysection,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); + + + +% --- Outputs from this function are returned to the command line. +function varargout = gui_win_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; + + + + + + + +% This funcion just calls the external program which takes an image from camera +% We call it with parameters read from the GUI fields +function grabimage(handles) +global image_name; +global image_m; +global image_original; +run_string = horzcat('grabNimages_1394cam.exe -s ',num2str(get(handles.edit2,'String')),' -n ',num2str(get(handles.edit3,'String'))); +system(run_string); +img=imread(image_name); +image_m=double(img); +image_original=image_m; + + + + + +function display_stuff(handles) +global image_m; +global background_m; + + +% If we need to substract the background, we do it +% background_m is a global variable +if get(handles.togglebutton2,'Value') > 0 + m = image_m - background_m; +else + m = image_m; +end; + +% Read the tolerance value from the GUI +tol = str2num(get(handles.edit1,'String')); + +% Display what we have before doing fit +axes(handles.original_image); +imagesc(m); +set(handles.original_image,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1]); +drawnow; + + + + + +% This function is executed when START button is pressed. +% We do different stuff depending on the radiobutton selection + +% --- Executes on button press in togglebutton1. +function togglebutton1_Callback(hObject, eventdata, handles) +% hObject handle to togglebutton1 (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 togglebutton1 + +global isworking; +global image_m; +isworking =1; +% Paint the button and change text +set(handles.togglebutton1,'BackgroundColor','Red'); +set(handles.togglebutton1,'String','STOP'); +drawnow; % needed to draw this before doing fit + + + + + +% This is for the single run +if get(handles.radiobutton2,'Value') + + % Grab an image from camera + grabimage(handles); + display_stuff(handles); + +end; + + + + + +% This executes when we do the continious run +% Same as the single fit exept that we have a while cycle +if get(handles.radiobutton3,'Value') + + while get(handles.togglebutton1,'Value') > 0 + + grabimage(handles); + display_stuff(handles); + + + + end; + +end; + + + +% Paint it back +set(handles.togglebutton1,'Value',0); +set(handles.togglebutton1,'BackgroundColor','Green'); +set(handles.togglebutton1,'String','START'); +drawnow; +isworking =0; + + + + +% If we change the radiobutton setting we unpress the start button which will stop any activity.. eventually +% Also here we check if we want to choose a file from a the file-open +% dialog + +% --- Executes when selected object is changed in uipanel1. +function uipanel1_SelectionChangeFcn(hObject, eventdata, handles) +% hObject handle to the selected object in uipanel1 +% eventdata structure with the following fields (see UIBUTTONGROUP) +% EventName: string 'SelectionChanged' (read only) +% OldValue: handle of the previously selected object or empty if none was selected +% NewValue: handle of the currently selected object +% handles structure with handles and user data (see GUIDATA) + +set(handles.togglebutton1,'Value',0); +global isworking; +global image_m; +global image_original; +global pathname; +isworking =1; + +% This calls a file-open dialog and runs the beam profiler on the choosen +% file +if get(handles.radiobutton4,'Value') + + set(handles.togglebutton1,'Value',1); + set(handles.togglebutton1,'BackgroundColor','Red'); + set(handles.togglebutton1,'String','STOP'); + drawnow; + + if ~isstr(pathname) % undefined variables are 0 + pathname = 'Z:\beam_profier images'; + end; + [filename, pathname, filterindex] = uigetfile( ... + { '*.png','PNG-files (*.png)';},'DefaultName',pathname); + + if isequal(filename,0) + else + img=imread(fullfile(pathname,filename)); + image_m=double(img); + image_original=image_m; + display_stuff(handles); + + end; + + set(handles.radiobutton4,'Value',0); + set(handles.togglebutton1,'BackgroundColor','Green'); + set(handles.togglebutton1,'Value',0); + set(handles.togglebutton1,'String','START'); +end; +isworking =0; + + + +% Executes when we press Clean button + +% --- Executes on button press in pushbutton10. +function pushbutton10_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton10 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global isworking; +global image_m; +global image_cleaned; + +if (isworking == 1) +else + isworking = 1; + set(handles.pushbutton10,'String','Working'); + + %read the attenuation from the GUI + filter = str2num(get(handles.edit4,'String')); + radius = str2num(get(handles.edit5,'String')); + + %clean the image with the stripe eraser + [image_cleaned,~]=stripeeraser(image_m,radius,filter); + image_cleaned=abs(image_cleaned); + image_m=image_cleaned; + display_stuff(handles); + + set(handles.pushbutton10,'String','Clean'); + set(handles.popupmenu4,'Value',2); +end; +isworking = 0; + + + +% Executes when we press Fit button + +% --- Executes on button press in pushbutton8. +function pushbutton8_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton8 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +global isworking; +global image_m; +global background_m; +global image_fitted; + +if (isworking == 1) +else +isworking = 1; +set(handles.pushbutton8,'String','Working'); + +axes(handles.original_image); +[x,y] = ginput(1); +cx = x(1); +cy = y(1); + + +% If we need to substract the background, we do it +% background_m is a global variable +if get(handles.togglebutton2,'Value') > 0 + m = image_m - background_m; +else + m = image_m; +end; + + +% Read the tolerance value from the GUI +tol = str2num(get(handles.edit1,'String')); + + +% Here we do our fit. Output is a vector with gauss parameters +p = fitgaussian2D(m,cx,cy,tol); + + +% Parameters we got +cx = p(1); +cy = p(2); +wx = p(3); +wy = p(4); +amp = p(5); +theta = p(6); +background=p(7); + +% Display them into the table in GUI +set(handles.uitable1,'Data',p') + +% This is for drawing fitted gaussian +[sizey sizex] = size(m); +[x,y] = meshgrid(1:sizex,1:sizey); + + +% This takes parameters 'p' and produces fit array (same size as initial 'm' array) +fit = Gaussian2D(p,x,y); + + +% Now we want to draw sections of our gaussians +% If we have some wierd image and the center is outside of arrays, we do crossections on the closest border +% Need it because there will be an error if we try to acces some data that is not in our arrays +tcx = round(cx); +if isnan(tcx) > 0 + tcx = sizex/2; +end; +if round(cx) > sizex + tcx = sizex; +end; +if round(cx) < 1 + tcx = 1; +end; + + + +tcy = round(cy); +if isnan(tcy) > 0 + tcy = sizey/2; +end; +if round(cy) > sizey + tcy = sizey; +end; +if round(cy) < 1 + tcy = 1; +end; + + + +% Here we draw crossections +hold off; +axes(handles.ysection); +h = plot(m(:,tcx)); +hold on; +set(h,'Color','red','LineWidth',2); +h = plot(fit(:,tcx)); +set(h,'Color','blue','LineWidth',2); + +hold off; +axes(handles.xsection); +h = plot(m(tcy,:)); +set(h,'Color','red','LineWidth',2); +hold on; +h = plot(fit(tcy,:)); +set(h,'Color','blue','LineWidth',2); +hold off; + + +%Here we plot the ideal fitted image + + +for x=1:sizex + for y=1:sizey + Xn = (x-cx)*cos(theta) - (y-cy)*sin(theta); + Yn = (x-cx)*sin(theta) + (y-cy)*cos(theta); + image_fitted(y,x) = amp*(exp(-2*((Xn).^2./(wx^2)+(Yn).^2./(wy^2)))) + background; + end; +end; + + + +set(handles.pushbutton8,'String','Fit'); +end; +isworking = 0; + + + + + + +%background substraction +%here we only toggle on/off +% --- Executes on button press in togglebutton2. +function togglebutton2_Callback(hObject, eventdata, handles) +% hObject handle to togglebutton2 (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 togglebutton2 + +if get(handles.togglebutton2,'Value') > 0 + + set(handles.togglebutton2,'String','ON'); + +else + set(handles.togglebutton2,'String','OFF'); +end; + + + + + + + +%image saving +% --- Executes on button press in pushbutton3. +function pushbutton3_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global image_name; +global image_m; +%fname_to_save = horzcat(pwd,filesep,'saved_images',filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); +fname_to_save = horzcat('Z:\beam_profier images',filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); + +set(handles.text12,'String',horzcat('Image saved to: ',fname_to_save)); +image_to_save=uint16(image_m); +imwrite(image_to_save,fname_to_save,'png','bitdepth',16); + + + + + + + +% This executes when we want to grab the background from the camera +% --- Executes on button press in pushbutton4. +function pushbutton4_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton4 (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_m; +global isworking; +isworking =1; +grabimage(handles); +background_m = image_m; + +axes(handles.axes6); +imagesc(background_m); +set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +drawnow; +isworking =0; + + + +% This executes when we want to choose the background from a file +% --- Executes on button press in pushbutton5. +function pushbutton5_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton5 (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)); + background_m = double(img); + + axes(handles.axes6); + imagesc(background_m); + set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); + drawnow; +end; + + + + + + + + + + + + + + + + + + + + + +% --- Executes during object creation, after setting all properties. +function figure1_CreateFcn(hObject, eventdata, handles) +% hObject handle to figure1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Add the current directory to the path, as the pwd might change thru' the +% gui. Remove the directory from the path when gui is closed +% (See figure1_DeleteFcn) +setappdata(hObject, 'StartPath', pwd); +addpath(pwd); + + +% --- Executes during object deletion, before destroying properties. +function figure1_DeleteFcn(hObject, eventdata, handles) +% hObject handle to figure1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Remove the directory added to the path in the figure1_CreateFcn. +if isappdata(hObject, 'StartPath') + rmpath(getappdata(hObject, 'StartPath')); +end + + + +function edit2_Callback(hObject, eventdata, handles) +% hObject handle to edit2 (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 edit2 as text +% str2double(get(hObject,'String')) returns contents of edit2 as a double + + +% --- Executes during object creation, after setting all properties. +function edit2_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles) +% hObject handle to edit3 (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 edit3 as text +% str2double(get(hObject,'String')) returns contents of edit3 as a double + + +% --- Executes during object creation, after setting all properties. +function edit3_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit3 (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 edit1_Callback(hObject, eventdata, handles) +% hObject handle to edit1 (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 edit1 as text +% str2double(get(hObject,'String')) returns contents of edit1 as a double + + +% --- Executes during object creation, after setting all properties. +function edit1_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit1 (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 during object creation, after setting all properties. +function original_image_CreateFcn(hObject, eventdata, handles) +% hObject handle to original_image (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: place code in OpeningFcn to populate original_image + + +% --- Executes on button press in checkbox1. +function checkbox1_Callback(hObject, eventdata, handles) +% hObject handle to checkbox1 (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 checkbox1 + + +% --- Executes on button press in pushbutton7. +function pushbutton7_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton7 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + + +function edit4_Callback(hObject, eventdata, handles) +% hObject handle to edit4 (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 edit4 as text +% str2double(get(hObject,'String')) returns contents of edit4 as a double + + +% --- Executes during object creation, after setting all properties. +function edit4_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit4 (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 selection change in popupmenu4. +function popupmenu4_Callback(hObject, eventdata, handles) +% hObject handle to popupmenu4 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu4 contents as cell array +% contents{get(hObject,'Value')} returns selected item from +% popupmenu4 +global image_m; +global image_original; +global image_cleaned; +global image_fitted; +val=get(hObject,'Value'); +switch val + case 1 + image_m=image_original; + display_stuff(handles); + case 2 + image_m=image_cleaned; + display_stuff(handles); + case 3 + image_m=image_fitted; + display_stuff(handles); +end; + + +% --- Executes during object creation, after setting all properties. +function popupmenu4_CreateFcn(hObject, eventdata, handles) +% hObject handle to popupmenu4 (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. +if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) + set(hObject,'BackgroundColor','white'); +end + + + +function edit5_Callback(hObject, eventdata, handles) +% hObject handle to edit5 (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 edit5 as text +% str2double(get(hObject,'String')) returns contents of edit5 as a double + + +% --- Executes during object creation, after setting all properties. +function edit5_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit5 (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 + + +% --- If Enable == 'on', executes on mouse press in 5 pixel border. +% --- Otherwise, executes on mouse press in 5 pixel border or over radiobutton4. +function radiobutton4_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to radiobutton4 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global image_m; +global image_original; +global image_cleaned; +global image_fitted; +if get(handles,radiobutton4,'Value') + image_m=image_original; + display_stuff(handles); +end; +if get(handles,radiobutton8,'Value') + image_m=image_cleaned; + display_stuff(handles); +end; +if get(handles,radiobutton8,'Value') + image_m=image_cleaned; + display_stuff(handles); +end; + + +% -------------------------------------------------------------------- +function uipanel1_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to uipanel1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) diff --git a/gui_win.fig b/gui_win.fig Binary files differnew file mode 100644 index 0000000..2f8f633 --- /dev/null +++ b/gui_win.fig diff --git a/gui_win.m b/gui_win.m new file mode 100644 index 0000000..e35a26a --- /dev/null +++ b/gui_win.m @@ -0,0 +1,739 @@ +function varargout = gui_win(varargin) +% gui_win MATLAB code for gui_win.fig +% gui_win, by itself, creates a new gui_win or raises the existing +% singleton*. +% +% H = gui_win returns the handle to a new gui_win or the handle to +% the existing singleton*. +% +% gui_win('CALLBACK',hObject,eventData,handles,...) calls the local +% function named CALLBACK in gui_win.M with the given input arguments. +% +% gui_win('Property','Value',...) creates a new gui_win or raises the +% existing singleton*. Starting from the left, property value pairs are +% applied to the gui_win before gui_win_OpeningFcn gets called. An +% unrecognized property name or invalid value makes property application +% stop. All inputs are passed to gui_win_OpeningFcn via varargin. +% +% *See gui_win Options on GUIDE's Tools menu. Choose "gui_win allows only one +% instance to run (singleton)". +% +% See also: GUIDE, GUIDATA, GUIHANDLES + +% Edit the above text to modify the response to help gui_win + +% Last Modified by GUIDE v2.5 10-Sep-2012 11:34:46 + +% Begin initialization code - DO NOT EDIT +gui_Singleton = 1; +gui_State = struct('gui_Name', mfilename, ... + 'gui_Singleton', gui_Singleton, ... + 'gui_OpeningFcn', @gui_win_OpeningFcn, ... + 'gui_OutputFcn', @gui_win_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 gui_win is made visible. +function gui_win_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 gui_win (see VARARGIN) + +% Choose default command line output for gui_win +handles.output = hObject; + +% Update handles structure +guidata(hObject, handles); + +% Set color of the strart button to green +set(handles.togglebutton1,'BackgroundColor','Green'); + +% Declare global variables +global background_m; +global image_name; +global isworking; +global image_m; +global image_original; +global image_cleaned; +global image_fitted; + +% Initial values +background_m = 0; +image_m = 0; +image_original = 0; +image_cleaned = 0; +image_fitted = 0; +image_name = 'test.png'; +isworking = 0; + +% Don`t show ticks for the minor windows +set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +set(handles.xsection,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +set(handles.ysection,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); + + + +% --- Outputs from this function are returned to the command line. +function varargout = gui_win_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; + + + + + + + +% This funcion just calls the external program which takes an image from camera +% We call it with parameters read from the GUI fields +function grabimage(handles) +global image_name; +global image_m; +global image_original; +run_string = horzcat('grabNimages_1394cam.exe -s ',num2str(get(handles.edit2,'String')),' -n ',num2str(get(handles.edit3,'String'))); +system(run_string); +img=imread(image_name); +image_m=double(img); +image_original=image_m; + + + + + +function display_stuff(handles) +global image_m; +global background_m; + + +% If we need to substract the background, we do it +% background_m is a global variable +if get(handles.togglebutton2,'Value') > 0 + m = image_m - background_m; +else + m = image_m; +end; + +% Read the tolerance value from the GUI +tol = str2num(get(handles.edit1,'String')); + +% Display what we have before doing fit +axes(handles.original_image); +imagesc(m); +set(handles.original_image,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1]); +drawnow; + + + + + +% This function is executed when START button is pressed. +% We do different stuff depending on the radiobutton selection + +% --- Executes on button press in togglebutton1. +function togglebutton1_Callback(hObject, eventdata, handles) +% hObject handle to togglebutton1 (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 togglebutton1 + +global isworking; +global image_m; +isworking =1; +% Paint the button and change text +set(handles.togglebutton1,'BackgroundColor','Red'); +set(handles.togglebutton1,'String','STOP'); +drawnow; % needed to draw this before doing fit + + + + + +% This is for the single run +if get(handles.radiobutton2,'Value') + + % Grab an image from camera + grabimage(handles); + display_stuff(handles); + +end; + + + + + +% This executes when we do the continious run +% Same as the single fit exept that we have a while cycle +if get(handles.radiobutton3,'Value') + + while get(handles.togglebutton1,'Value') > 0 + + grabimage(handles); + display_stuff(handles); + + + + end; + +end; + + + +% Paint it back +set(handles.togglebutton1,'Value',0); +set(handles.togglebutton1,'BackgroundColor','Green'); +set(handles.togglebutton1,'String','START'); +drawnow; +isworking =0; + + + + +% If we change the radiobutton setting we unpress the start button which will stop any activity.. eventually +% Also here we check if we want to choose a file from a the file-open +% dialog + +% --- Executes when selected object is changed in uipanel1. +function uipanel1_SelectionChangeFcn(hObject, eventdata, handles) +% hObject handle to the selected object in uipanel1 +% eventdata structure with the following fields (see UIBUTTONGROUP) +% EventName: string 'SelectionChanged' (read only) +% OldValue: handle of the previously selected object or empty if none was selected +% NewValue: handle of the currently selected object +% handles structure with handles and user data (see GUIDATA) + +set(handles.togglebutton1,'Value',0); +global isworking; +global image_m; +global image_original; +global pathname; +isworking =1; + +% This calls a file-open dialog and runs the beam profiler on the choosen +% file +if get(handles.radiobutton4,'Value') + + set(handles.togglebutton1,'Value',1); + set(handles.togglebutton1,'BackgroundColor','Red'); + set(handles.togglebutton1,'String','STOP'); + drawnow; + + if ~isstr(pathname) % undefined variables are 0 + pathname = 'Z:\beam_profier images'; + end; + [filename, pathname, filterindex] = uigetfile( ... + { '*.png','PNG-files (*.png)';},'DefaultName',pathname); + + if isequal(filename,0) + else + img=imread(fullfile(pathname,filename)); + image_m=double(img); + image_original=image_m; + display_stuff(handles); + + end; + + set(handles.radiobutton4,'Value',0); + set(handles.togglebutton1,'BackgroundColor','Green'); + set(handles.togglebutton1,'Value',0); + set(handles.togglebutton1,'String','START'); +end; +isworking =0; + + + +% Executes when we press Clean button + +% --- Executes on button press in pushbutton10. +function pushbutton10_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton10 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global isworking; +global image_m; +global image_cleaned; + +if (isworking == 1) +else + isworking = 1; + set(handles.pushbutton10,'String','Working'); + + %read the attenuation from the GUI + filter = str2num(get(handles.edit4,'String')); + radius = str2num(get(handles.edit5,'String')); + + %clean the image with the stripe eraser + [image_cleaned,~]=stripeeraser(image_m,radius,filter); + image_cleaned=abs(image_cleaned); + image_m=image_cleaned; + display_stuff(handles); + + set(handles.pushbutton10,'String','Clean'); + set(handles.radiobutton8,'Value',1); +end; +isworking = 0; + + + +% Executes when we press Fit button + +% --- Executes on button press in pushbutton8. +function pushbutton8_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton8 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +global isworking; +global image_m; +global background_m; +global image_fitted; + +if (isworking == 1) +else +isworking = 1; +set(handles.pushbutton8,'String','Working'); + +axes(handles.original_image); +[x,y] = ginput(1); +cx = x(1); +cy = y(1); + + +% If we need to substract the background, we do it +% background_m is a global variable +if get(handles.togglebutton2,'Value') > 0 + m = image_m - background_m; +else + m = image_m; +end; + + +% Read the tolerance value from the GUI +tol = str2num(get(handles.edit1,'String')); + + +% Here we do our fit. Output is a vector with gauss parameters +p = fitgaussian2D(m,cx,cy,tol); + + +% Parameters we got +cx = p(1); +cy = p(2); +wx = p(3); +wy = p(4); +amp = p(5); +theta = p(6); +background=p(7); + +% Display them into the table in GUI +set(handles.uitable1,'Data',p') + +% This is for drawing fitted gaussian +[sizey sizex] = size(m); +[x,y] = meshgrid(1:sizex,1:sizey); + + +% This takes parameters 'p' and produces fit array (same size as initial 'm' array) +fit = Gaussian2D(p,x,y); + + +% Now we want to draw sections of our gaussians +% If we have some wierd image and the center is outside of arrays, we do crossections on the closest border +% Need it because there will be an error if we try to acces some data that is not in our arrays +tcx = round(cx); +if isnan(tcx) > 0 + tcx = sizex/2; +end; +if round(cx) > sizex + tcx = sizex; +end; +if round(cx) < 1 + tcx = 1; +end; + + + +tcy = round(cy); +if isnan(tcy) > 0 + tcy = sizey/2; +end; +if round(cy) > sizey + tcy = sizey; +end; +if round(cy) < 1 + tcy = 1; +end; + + + +% Here we draw crossections +hold off; +axes(handles.ysection); +h = plot(m(:,tcx)); +hold on; +set(h,'Color','red','LineWidth',2); +h = plot(fit(:,tcx)); +set(h,'Color','blue','LineWidth',2); + +hold off; +axes(handles.xsection); +h = plot(m(tcy,:)); +set(h,'Color','red','LineWidth',2); +hold on; +h = plot(fit(tcy,:)); +set(h,'Color','blue','LineWidth',2); +hold off; + + +%Here we plot the ideal fitted image + + +for x=1:sizex + for y=1:sizey + Xn = (x-cx)*cos(theta) - (y-cy)*sin(theta); + Yn = (x-cx)*sin(theta) + (y-cy)*cos(theta); + image_fitted(y,x) = amp*(exp(-2*((Xn).^2./(wx^2)+(Yn).^2./(wy^2)))) + background; + end; +end; + + + +set(handles.pushbutton8,'String','Fit'); +end; +isworking = 0; + + + + + + +%background substraction +%here we only toggle on/off +% --- Executes on button press in togglebutton2. +function togglebutton2_Callback(hObject, eventdata, handles) +% hObject handle to togglebutton2 (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 togglebutton2 + +if get(handles.togglebutton2,'Value') > 0 + + set(handles.togglebutton2,'String','ON'); + +else + set(handles.togglebutton2,'String','OFF'); +end; + + + + + + + +%image saving +% --- Executes on button press in pushbutton3. +function pushbutton3_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton3 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global image_name; +global image_m; +%fname_to_save = horzcat(pwd,filesep,'saved_images',filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); +fname_to_save = horzcat('Z:\beam_profier images',filesep,datestr(now, 'yyyy_mm_dd_HHMMSS'),'.png'); + +set(handles.text12,'String',horzcat('Image saved to: ',fname_to_save)); +image_to_save=uint16(image_m); +imwrite(image_to_save,fname_to_save,'png','bitdepth',16); + + + + + + + +% This executes when we want to grab the background from the camera +% --- Executes on button press in pushbutton4. +function pushbutton4_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton4 (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_m; +global isworking; +isworking =1; +grabimage(handles); +background_m = image_m; + +axes(handles.axes6); +imagesc(background_m); +set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); +drawnow; +isworking =0; + + + +% This executes when we want to choose the background from a file +% --- Executes on button press in pushbutton5. +function pushbutton5_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton5 (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)); + background_m = double(img); + + axes(handles.axes6); + imagesc(background_m); + set(handles.axes6,'PlotBoxAspectRatio',[4 3 1],'DataAspectRatio',[1 1 1],'YTick',[],'XTick',[]); + drawnow; +end; + + + + + + + + + + + + + + + + + + + + + +% --- Executes during object creation, after setting all properties. +function figure1_CreateFcn(hObject, eventdata, handles) +% hObject handle to figure1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Add the current directory to the path, as the pwd might change thru' the +% gui. Remove the directory from the path when gui is closed +% (See figure1_DeleteFcn) +setappdata(hObject, 'StartPath', pwd); +addpath(pwd); + + +% --- Executes during object deletion, before destroying properties. +function figure1_DeleteFcn(hObject, eventdata, handles) +% hObject handle to figure1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + +% Remove the directory added to the path in the figure1_CreateFcn. +if isappdata(hObject, 'StartPath') + rmpath(getappdata(hObject, 'StartPath')); +end + + + +function edit2_Callback(hObject, eventdata, handles) +% hObject handle to edit2 (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 edit2 as text +% str2double(get(hObject,'String')) returns contents of edit2 as a double + + +% --- Executes during object creation, after setting all properties. +function edit2_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit2 (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 edit3_Callback(hObject, eventdata, handles) +% hObject handle to edit3 (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 edit3 as text +% str2double(get(hObject,'String')) returns contents of edit3 as a double + + +% --- Executes during object creation, after setting all properties. +function edit3_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit3 (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 edit1_Callback(hObject, eventdata, handles) +% hObject handle to edit1 (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 edit1 as text +% str2double(get(hObject,'String')) returns contents of edit1 as a double + + +% --- Executes during object creation, after setting all properties. +function edit1_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit1 (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 during object creation, after setting all properties. +function original_image_CreateFcn(hObject, eventdata, handles) +% hObject handle to original_image (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles empty - handles not created until after all CreateFcns called + +% Hint: place code in OpeningFcn to populate original_image + + +% --- Executes on button press in checkbox1. +function checkbox1_Callback(hObject, eventdata, handles) +% hObject handle to checkbox1 (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 checkbox1 + + +% --- Executes on button press in pushbutton7. +function pushbutton7_Callback(hObject, eventdata, handles) +% hObject handle to pushbutton7 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + + +function edit4_Callback(hObject, eventdata, handles) +% hObject handle to edit4 (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 edit4 as text +% str2double(get(hObject,'String')) returns contents of edit4 as a double + + +% --- Executes during object creation, after setting all properties. +function edit4_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit4 (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 edit5_Callback(hObject, eventdata, handles) +% hObject handle to edit5 (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 edit5 as text +% str2double(get(hObject,'String')) returns contents of edit5 as a double + + +% --- Executes during object creation, after setting all properties. +function edit5_CreateFcn(hObject, eventdata, handles) +% hObject handle to edit5 (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 + + +% --- If Enable == 'on', executes on mouse press in 5 pixel border. +% --- Otherwise, executes on mouse press in 5 pixel border or over radiobutton4. +function radiobutton4_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to radiobutton4 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) + + + +% -------------------------------------------------------------------- +function uipanel1_ButtonDownFcn(hObject, eventdata, handles) +% hObject handle to uipanel1 (see GCBO) +% eventdata reserved - to be defined in a future version of MATLAB +% handles structure with handles and user data (see GUIDATA) +global image_m; +global image_original; +global image_cleaned; +global image_fitted; +if get(handles.radiobutton4,'Value') + image_m=image_original; + display_stuff(handles); +end; +if get(handles.radiobutton8,'Value') + image_m=image_cleaned; + display_stuff(handles); +end; +if get(handles.radiobutton9,'Value') + image_m=image_fitted; + display_stuff(handles); +end; diff --git a/stripeeraser.m b/stripeeraser.m new file mode 100644 index 0000000..2ff6107 --- /dev/null +++ b/stripeeraser.m @@ -0,0 +1,15 @@ +function [immask,imfourier]=stripeeraser(img,radius,filter) +immask=fftshift(fft2(img)); +max1=max(immask(:)); +for x=1:640 + for y=1:480 + d=sqrt((x-320)^2+(y-240)^2); + if d>radius %Outside the central frequency. + if abs(immask(y,x))>max1*(10^(-filter)); %The filter works like a neutral desity filter. + immask(y,x)=immask(y,x)*exp(-(d/radius)^2); %Erase the frequency of the stripes. + end; + end; + end; +end; +imfourier=immask; +immask=ifft2(ifftshift(immask));
\ No newline at end of file |