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: hatch.m
    path of file: ./repos/gptoolbox/imageprocessing
    
    the code of the file until where you have to start completion: function H = hatch(im,levels,thickness)
  % HATCH computes dithering hatched image with a number of levels of specified
  % thickness
  %
  % H = hatch(im,levels)
  %
  % Inputs:
  %  im  original image
  %  levels  number of hatching levels {3}
  %  thickness  thickness of individual hatch lines
  % Outputs:
  %  H  hatched image
  %
  % See also: dith
  %

  assert(levels>1);
  
  % make sure image is grayscale
  switch size(im,3)
  case 1
  % do nothing, already "grayscale"
  case 3
    warning('Converting input image to grayscale using rgb2gray');

    
function H = hatch(im,levels,thickness)
  % HATCH computes dithering hatched image with a number of levels of specified
  % thickness
  %
  % H = hatch(im,levels)
  %
  % Inputs:
  %  im  original image
  %  levels  number of hatching levels {3}
  %  thickness  thickness of individual hatch lines
  % Outputs:
  %  H  hatched image
  %
  % See also: dith
  %

  assert(levels>1);
  
  % make sure image is grayscale
  switch size(im,3)
  case 1
  % do nothing, already "grayscale"
  case 3
    warning('Converting input image to grayscale using rgb2gray');
    im = rgb2gray(im);
  otherwise
    error('Input image should be grayscale');
  end