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: vl_imseg.m
    path of file: ./repos/Image-Harmonization-Dataset-iHarmony4/Lalonde and Efros/utilsPrivate/3rd_party/vlfeat-0.9.14/toolbox/quickshift
    
    the code of the file until where you have to start completion: function Q = vl_imseg(I,labels)
% VL_IMSEG Color an image based on the segmentation
%   ISEG = VL_IMSEG(I,LABELS) labels ISEG with the average color from I of

    
function Q = vl_imseg(I,labels)
% VL_IMSEG Color an image based on the segmentation
%   ISEG = VL_IMSEG(I,LABELS) labels ISEG with the average color from I of
%   each cluster indicated by LABELS.
%
%   See also: VL_HELP().

% Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
% All rights reserved.
%
% This file is part of the VLFeat library and is made available under
% the terms of the BSD license (see the COPYING file).

[M,N,K] = size(I) ;
Q = 0*I ;
for k=1:size(I,3)
  acc = zeros(M,N) ;
  nrm = zeros(M,N) ;
  acc = vl_binsum(acc,  I(:,:,k), labels) ;
  nrm = vl_binsum(nrm, ones(M,N), labels) ;
  acc = acc ./ (nrm+eps) ;
  Q(:,:,k) = acc(labels) ;
end