Number of repeats for each different intensity 
    n = length(I);
    
    % The fraction of those points we need either side of the chosen pt
    frac = n_req/n/2;
    
    % The histogram positions to use
    pos = linspace(0.2,0.8,N);
    
    h = waitbar(0,'Computing...');
    for i=1:N
       
        % select data around the histogram position
        centre = pos(i);
        Q = quantile(I,[centre-frac,centre+frac]); 
        sel = I >= (Q(1)) & I <= (Q(2));       
        sel_data =