function handles = FWidth(hObject, eventdata, handles);

if ~handles.open_flag 

    errordlg('Image must be open','Error');
else
    CommandCall(hObject, eventdata, handles,'click on background');
    figure(handles.figure_handle);
    [x,y] = ginput(1);
    r_back = [x,y];

    int_back = get_avg_int(hObject, eventdata, handles,r_back)
    
    CommandCall(hObject, eventdata, handles,'click on vesicle');
    figure(handles.figure_handle);
    [x,y] = ginput(1);
    r_vesicle = [x,y];
    
    int_vesicle = get_avg_int(hObject, eventdata, handles,r_vesicle)
    int_vesicle = int_vesicle - int_back
    
    CommandCall(hObject, eventdata, handles,'click on measurement location(s) hit enter when done');
    figure(handles.figure_handle);
    [x,y] = ginput();
    r_measure_n = [x,y];
    
    rsize = size(r_measure_n);
    rsize = rsize(1);
    
    CommandCall(hObject, eventdata, handles,'click on range from m.l.');
    figure(handles.figure_handle);
    [x,y] = ginput(1);
    r_range = [x,y]; 
    
    for i= 1:rsize
        r_measure = r_measure_n(i,:);
        
        y_range = abs(r_measure(2)-r_range(2));
    
        r_measure_pix    = round(r_measure/handles.pixelsize);
        y_range_pix      = round(y_range/handles.pixelsize);
    
    %(r_measure_pix(2)-y_range_pix):(r_measure_pix(2)-y_range_pix)
    
        y = (r_measure_pix(2)-y_range_pix):(r_measure_pix(2)+y_range_pix);
    
    integrate_int_width = sum(handles.im(y,r_measure_pix(1))-int_back)/int_vesicle*handles.pixelsize;
    
    COM = sum(y'.*(handles.im(y,r_measure_pix(1))-int_back))/int_vesicle*handles.pixelsize^2/integrate_int_width;
    
    rad = integrate_int_width/pi;
    if ~isfield(handles, 'width')
        handles.width.r1 = [r_measure(1),COM+rad];
        handles.width.r2 = [r_measure(1),COM-rad];
        guidata(hObject, handles);
    else
        handles.width.r1 = [handles.width.r1; [r_measure(1),COM+rad]];
        handles.width.r2 = [handles.width.r2; [r_measure(1),COM-rad]];
        guidata(hObject, handles);

    end
    
    end;



    
end

function inten = get_avg_int(hObject, eventdata, handles,r)

r_pix = round(r/handles.pixelsize);

rad  = 2;
diam = rad*2+1;

inten = sum(sum(handles.im((r_pix(2)-rad):(r_pix(2)+rad),(r_pix(1)-rad):(r_pix(1)+rad))))/diam^2;

function CommandCall(hObject, eventdata, handles,command_name)

set(handles.command_text, 'String', command_name);
guidata(hObject, handles);