class_docstr: Constructs a SAM image processor.
  
  Args:
      do_resize (`bool`, *optional*, defaults to `True`):
          Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by the
          `do_resize` parameter in the `preprocess` method.
      size (`dict`, *optional*, defaults to `{"longest_edge": 1024}`):
          Size of the output image after resizing. Resizes the longest edge of the image to match
          `size["longest_edge"]` while maintaining the aspect ratio. Can be overridden by the `size` parameter in the
          `preprocess` method.
      mask_size (`dict`, *optional*, defaults to `{"longest_edge": 256}`):
          Size of the output segmentation map after resizing. Resizes the longest edge of the image to match
          `size["longest_edge"]` while maintaining the aspect ratio. Can be overridden by the `mask_size` parameter
          in the `preprocess` method.
      resample (`PILImageResampling`, *optional*, defaults to `Resampling.BILINEAR`):
          Resampling filter to use if resizing the image. Can be overridden by the `resample` parameter in the
          `preprocess` method.
      do_rescale (`bool`, *optional*, defaults to `True`):
          Wwhether 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. Only has an effect if `do_rescale` is set to `True`. 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 the `do_normalize` parameter in the `preprocess`
          method. Can be overridden by the `do_normalize` parameter 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. Can be
          overridden by the `image_mean` parameter in the `preprocess` method.
      image_std (`float` or `List[float]`, *optional*, defaults to `IMAGENET_DEFAULT_STD`):
          Standard deviation 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_std` parameter in the `preprocess` method.
          Can be overridden by the `image_std` parameter in the `preprocess` method.
      do_pad (`bool`, *optional*, defaults to `True`):
          Whether to pad the image to the specified `pad_size`. Can be overridden by the `do_pad` parameter in the
          `preprocess` method.
      pad_size (`dict`, *optional*, defaults to `{"height": 1024, "width": 1024}`):
          Size of the output image after padding. Can be overridden by the `pad_size` parameter in the `preprocess`
          method.
      mask_pad_size (`dict`, *optional*, defaults to `{"height": 256, "width": 256}`):
          Size of the output segmentation map after padding. Can be overridden by the `mask_pad_size` parameter in
          the `preprocess` method.
      do_convert_rgb (`bool`, *optional*, defaults to `True`):
          Whether to convert the image to RGB.
class_docstr_tok: ["Constructs","a","SAM","image","processor",".","Args",":","do_resize","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","resize","the","image","'s","(","height",",","width",")","dimensions","to","the","specified","`","size","`",".","Can","be","overridden","by","the","`","do_resize","`","parameter","in","the","`","preprocess","`","method",".","size","(","`","dict","`",",","*","optional","*",",","defaults","to","`","{","``","longest_edge","''",":","1024","}","`",")",":","Size","of","the","output","image","after","resizing",".","Resizes","the","longest","edge","of","the","image","to","match","`","size","[","``","longest_edge","''","]","`","while","maintaining","the","aspect","ratio",".","Can","be","overridden","by","the","`","size","`","parameter","in","the","`","preprocess","`","method",".","mask_size","(","`","dict","`",",","*","optional","*",",","defaults","to","`","{","``","longest_edge","''",":","256","}","`",")",":","Size","of","the","output","segmentation","map","after","resizing",".","Resizes","the","longest","edge","of","the","image","to","match","`","size","[","``","longest_edge","''","]","`","while","maintaining","the","aspect","ratio",".","Can","be","overridden","by","the","`","mask_size","`","parameter","in","the","`","preprocess","`","method",".","resample","(","`","PILImageResampling","`",",","*","optional","*",",","defaults","to","`","Resampling.BILINEAR","`",")",":","Resampling","filter","to","use","if","resizing","the","image",".","Can","be","overridden","by","the","`","resample","`","parameter","in","the","`","preprocess","`","method",".","do_rescale","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Wwhether","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",".","Only","has","an","effect","if","`","do_rescale","`","is","set","to","`","True","`",".","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","the","`","do_normalize","`","parameter","in","the","`","preprocess","`","method",".","Can","be","overridden","by","the","`","do_normalize","`","parameter","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",".","Can","be","overridden","by","the","`","image_mean","`","parameter","in","the","`","preprocess","`","method",".","image_std","(","`","float","`","or","`","List","[","float","]","`",",","*","optional","*",",","defaults","to","`","IMAGENET_DEFAULT_STD","`",")",":","Standard","deviation","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_std","`","parameter","in","the","`","preprocess","`","method",".","Can","be","overridden","by","the","`","image_std","`","parameter","in","the","`","preprocess","`","method",".","do_pad","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","pad","the","image","to","the","specified","`","pad_size","`",".","Can","be","overridden","by","the","`","do_pad","`","parameter","in","the","`","preprocess","`","method",".","pad_size","(","`","dict","`",",","*","optional","*",",","defaults","to","`","{","``","height","''",":","1024",",","``","width","''",":","1024","}","`",")",":","Size","of","the","output","image","after","padding",".","Can","be","overridden","by","the","`","pad_size","`","parameter","in","the","`","preprocess","`","method",".","mask_pad_size","(","`","dict","`",",","*","optional","*",",","defaults","to","`","{","``","height","''",":","256",",","``","width","''",":","256","}","`",")",":","Size","of","the","output","segmentation","map","after","padding",".","Can","be","overridden","by","the","`","mask_pad_size","`","parameter","in","the","`","preprocess","`","method",".","do_convert_rgb","(","`","bool","`",",","*","optional","*",",","defaults","to","`","True","`",")",":","Whether","to","convert","the","image","to","RGB","."]
code: def _preprocess_image(
      self,
      image: ImageInput,
      do_resize: Optional[bool] = None,
      size: Dict[str, int] = None,
      resample: PILImageResampling = None,
      do_rescale: bool = None,
      rescale_factor: Optional[float] = None,
      do_normalize: Optional[bool] = None,
      image_mean: Optional[Union[float, List[float]]] = None,
      image_std: Optional[Union[float, List[float]]] = None,
      do_pad: Optional[bool] = None,
      pad_size: Optional[Dict[str, int]] = None,
      do_convert_rgb: Optional[bool] = None,
      data_format: Optional[Union[str, ChannelDimension]] = None,
      input_data_format: Optional[Union[str, ChannelDimension]] = None,
  ) -> Tuple[np.ndarray, Tuple[int, int], Tuple[int, int]]:
      image = to_numpy_array(image)
  
      # PIL RGBA images are converted to RGB
      if do_convert_rgb:
          image = convert_to_rgb(image)
  
      # All transformations expect numpy arrays.
      image = to_numpy_array(image)
  
      if is_scaled_image(image) and do_rescale:
          logger.warning_once(
              "It looks like you are trying to rescale already rescaled images. If the input"
              " images have pixel values between 0 and 1, set `do_rescale=False` to avoid rescaling them again."
          )
  
      if input_data_format is None:
          input_data_format = infer_channel_dimension_format(image)
  
      original_size = get_image_size(
          image, channel_dim=input_data_format
      )
  
      image, reshaped_input_size = self._preprocess(
          image=image,
          do_resize=do_resize,
          size=size,
          resample=resample,
          do_rescale=do_rescale,
          rescale_factor=rescale_factor,
          do_normalize=do_normalize,
          image_mean=image_mean,
          image_std=image_std,
          do_pad=do_pad,
          pad_size=pad_size,
          input_data_format=input_data_format,
      )
  
      if data_format is not None:
          image = to_channel_dimension_format(
              image, data_format, input_channel_dim=input_data_format
          )
  
      return image, original_size, reshaped_input_size
  
imports: import math
  from copy import deepcopy
  from itertools import product
  from typing import Any, Dict, List, Optional, Tuple, Union
  import numpy
  from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
  from ...image_transforms import convert_to_rgb, pad, resize, to_channel_dimension_format
  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, is_tf_available, is_torch_available, is_torchvision_available, logging, requires_backends
label_desc: Use image node_id 6 for calling the SamImageProcessor obj's underlying member method code with example usage: obj._preprocess_image(image, do_resize, size, resample, do_rescale, rescale_factor, do_normalize, image_mean, image_std, do_pad, pad_size, do_convert_rgb, data_format, input_data_format) and returns: image,  original_size,  reshaped_input_size