function result = applyfilter(img, filter)

    img = double(img); % násobení filtrem s desetinným číslem
    result = zeros(size(img));

    % sizes
    [i_height, i_width] = size(img);
    [f_height, f_width] = size(filter);

    % calc a, b
    a = (f_width - 1) / 2;
    b = (f_height - 1) / 2;

    % padded img
    padded_img = zeros(i_height + 2*b, i_width + 2*a);
    padded_img(b+1:end-b, a+1:end-a) = img;

   % sliding window
   for i = 1:i_height
       for j = 1:i_width

           window = padded_img(i : i+2*b, j : j+2*a);

           result(i,j) = sum(window .* filter, 'all');
       end
   end

   result = uint8(result); % návrat do původního typu

end

