class_docstr: Constructs a Nougat image processor.
  
  Args:
      do_crop_margin (`bool`, *optional*, defaults to `True`):
          Whether to crop the image margins.
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by
          `do_resize` in the `preprocess` method.
      size (`Dict[str, int]` *optional*, defaults to `{"height": 896, "width": 672}`):
          Size of the image after resizing. Can be overridden by `size` in the `preprocess` method.
      resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`):
          Resampling filter to use if resizing the image. Can be overridden by `resample` in the `preprocess` method.
      do_thumbnail (`bool`, *optional*, defaults to `True`):
          Whether to resize the image using thumbnail method.
      do_align_long_axis (`bool`, *optional*, defaults to `False`):
          Whether to align the long axis of the image with the long axis of `size` by rotating by 90 degrees.
      do_pad (`bool`, *optional*, defaults to `True`):
          Whether to pad the images to the largest image size in the batch.
      do_rescale (`bool`, *optional*, defaults to `True`):
          Whether to rescale the image by the specified scale `rescale_factor`. Can be overridden by the `do_rescale`
          parameter in the `preprocess` method.
      rescale_factor (`int` or `float`, *optional*, defaults to `1/255`):
          Scale factor to use if rescaling the image. Can be overridden by the `rescale_factor` parameter in the
          `preprocess` method.
      do_normalize (`bool`, *optional*, defaults to `True`):
          Whether to normalize the image. Can be overridden by `do_normalize` in the `preprocess` method.
      image_mean (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_MEAN`):
          Mean to use if normalizing the image. This is a float or list of floats the length of the number of
          channels in the image. Can be overridden by the `image_mean` parameter in the `preprocess` method.
      image_std (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_STD`):
          Image standard deviation.
class_docstr_tok: ["Constructs","a","Nougat","image","processor",".","Args",":","do_crop_margin","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","crop","the","image","margins",".","do_resize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","resize","the","image","'s","(","height",",","width",")","dimensions","to","the","specified","`","size","`",".","Can","be","overridden","by","`","do_resize","`","in","the","`","preprocess","`","method",".","size","(","`","Dict","[","str",",","int","]","`","*","optional","*",",","defaults","to","`","{","``","height","''",":","896",",","``","width","''",":","672","}","`",")",":","Size","of","the","image","after","resizing",".","Can","be","overridden","by","`","size","`","in","the","`","preprocess","`","method",".","resample","(","`","PILImageResampling","`",",","*","optional","*",",","defaults","to","`","Resampling.BILINEAR","`",")",":","Resampling","filter","to","use","if","resizing","the","image",".","Can","be","overridden","by","`","resample","`","in","the","`","preprocess","`","method",".","do_thumbnail","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","resize","the","image","using","thumbnail","method",".","do_align_long_axis","(","`","bool","`",",","*","optional","*",",","defaults","to","`","False","`",")",":","Whether","to","align","the","long","axis","of","the","image","with","the","long","axis","of","`","size","`","by","rotating","by","90","degrees",".","do_pad","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","pad","the","images","to","the","largest","image","size","in","the","batch",".","do_rescale","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","rescale","the","image","by","the","specified","scale","`","rescale_factor","`",".","Can","be","overridden","by","the","`","do_rescale","`","parameter","in","the","`","preprocess","`","method",".","rescale_factor","(","`","int","`","or","`","float","`",",","*","optional","*",",","defaults","to","`","1\/255","`",")",":","Scale","factor","to","use","if","rescaling","the","image",".","Can","be","overridden","by","the","`","rescale_factor","`","parameter","in","the","`","preprocess","`","method",".","do_normalize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","normalize","the","image",".","Can","be","overridden","by","`","do_normalize","`","in","the","`","preprocess","`","method",".","image_mean","(","`","float","`","or","`","List","[","float","]","`",",","*","optional","*",",","defaults","to","`","IMAGENET_DEFAULT_MEAN","`",")",":","Mean","to","use","if","normalizing","the","image",".","This","is","a","float","or","list","of","floats","the","length","of","the","number","of","channels","in","the","image",".","Can","be","overridden","by","the","`","image_mean","`","parameter","in","the","`","preprocess","`","method",".","image_std","(","`","float","`","or","`","List","[","float","]","`",",","*","optional","*",",","defaults","to","`","IMAGENET_DEFAULT_STD","`",")",":","Image","standard","deviation","."]
docstr: Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the
  threshold).
  
  Args:
      image (`np.array`):
          The image to be cropped.
      gray_threshold (`int`, *optional*, defaults to `200`)
          Value below which pixels are considered to be gray.
      data_format (`ChannelDimension`, *optional*):
          The channel dimension format of the output image. If unset, will use the inferred format from the
          input.
      input_data_format (`ChannelDimension`, *optional*):
          The channel dimension format of the input image. If unset, will use the inferred format from the input.
docstr_tok: ["Crops","the","margin","of","the","image",".","Gray","pixels","are","considered","margin","(","i.e.",",","pixels","with","a","value","below","the","threshold",")",".","Args",":","image","(","`","np.array","`",")",":","The","image","to","be","cropped",".","gray_threshold","(","`","int","`",",","*","optional","*",",","defaults","to","`","200","`",")","Value","below","which","pixels","are","considered","to","be","gray",".","data_format","(","`","ChannelDimension","`",",","*","optional","*",")",":","The","channel","dimension","format","of","the","output","image",".","If","unset",",","will","use","the","inferred","format","from","the","input",".","input_data_format","(","`","ChannelDimension","`",",","*","optional","*",")",":","The","channel","dimension","format","of","the","input","image",".","If","unset",",","will","use","the","inferred","format","from","the","input","."]
code: def crop_margin(
      self,
      image: np.array,
      gray_threshold: int = 200,
      data_format: Optional[ChannelDimension] = None,
      input_data_format: Optional[Union[str, ChannelDimension]] = None,
  ) -> np.array:
      """
      Crops the margin of the image. Gray pixels are considered margin (i.e., pixels with a value below the
      threshold).
  
      Args:
          image (`np.array`):
              The image to be cropped.
          gray_threshold (`int`, *optional*, defaults to `200`)
              Value below which pixels are considered to be gray.
          data_format (`ChannelDimension`, *optional*):
              The channel dimension format of the output image. If unset, will use the inferred format from the
              input.
          input_data_format (`ChannelDimension`, *optional*):
              The channel dimension format of the input image. If unset, will use the inferred format from the input.
      """
      if input_data_format is None:
          input_data_format = infer_channel_dimension_format(image)
  
      image = to_pil_image(image, input_data_format=input_data_format)
      data = np.array(image.convert("L")).astype(np.uint8)
      max_val = data.max()
      min_val = data.min()
      if max_val == min_val:
          image = np.array(image)
          image = (
              to_channel_dimension_format(
                  image, data_format, input_data_format
              )
              if data_format is not None
              else image
          )
          return image
      data = (data - min_val) / (max_val - min_val) * 255
      gray = data < gray_threshold
      coords = self.python_find_non_zero(gray)
      x_min, y_min, width, height = self.python_bounding_rect(coords)
      image = image.crop((x_min, y_min, x_min + width, y_min + height))
      image = np.array(image).astype(np.uint8)
      image = to_channel_dimension_format(
          image, input_data_format, ChannelDimension.LAST
      )
  
      image = (
          to_channel_dimension_format(
              image, data_format, input_data_format
          )
          if data_format is not None
          else image
      )
  
      return image
  
file_path: transformers/src/transformers/models/nougat/image_processing_nougat.py
imports: from typing import Dict, List, Optional, Union
  import numpy
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import get_resize_output_image_size, pad, resize, to_channel_dimension_format, to_pil_image
  from ...image_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, ChannelDimension, ImageInput, PILImageResampling, get_image_size, infer_channel_dimension_format, is_scaled_image, make_list_of_images, to_numpy_array, valid_images
  from ...utils import TensorType, logging
  from ...utils.import_utils import is_cv2_available, is_vision_available
label_desc: Use image node_id 4 for calling the NougatImageProcessor obj's underlying member method code with example usage: obj.crop_margin(image, gray_threshold, data_format, input_data_format) and returns: image, image