function result = applyfilter3(img, filter)

    img = double(img);
    
    % flatten the filter
    filter_flat = filter(:);
   
    % operation
    op = @(x) filter_flat' * x; 

    % sliding window
    result = colfilt(img, size(filter), 'sliding', op);
    result = uint8(result);

end

