You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: perception_correction.m
    path of file: ./repos/cmap/+tools
    
    the code of the file until where you have to start completion: 
% PERCEPTION_CORRECTION  Roughly corrects produces colormap from set of colors.
%  Uses simple interpolation in LAB space, which may not always
    
function cm = perception_correction(cm, nnew)

% Use LAB space for perception.
lab = rgb2lab(cm);
l = lab(:,1)';
a = lab(:,2)';
b = lab(:,3)';

% Original L positions for colors.
idx = round((l - min(l)) ./ (max(l) - min(l)) .* nnew);

% New position.
vecnew = 1:nnew;

% Perception based on new position.
pu = linspace(min(l), max(l), nnew);

% Interpolate for new colormap.
anew = interp1(idx, a, vecnew);
bnew = interp1(idx, b, vecnew);
cm = lab2rgb([pu', anew', bnew']);
cm = max(min(cm, 1), 0);

end