from typing import Dict, List, Optional, Union

import numpy as np

from ...image_processing_utils import BaseImageProcessor, BatchFeature, get_size_dict
from ...image_transforms import (
    get_resize_output_image_size,
    normalize,
    pad,
    rescale,
    resize,
    to_channel_dimension_format,
)
from ...image_utils import (
    IMAGENET_STANDARD_MEAN,
    IMAGENET_STANDARD_STD,
    ChannelDimension,
    ImageInput,
    PILImageResampling,
    get_image_size,
    make_list_of_images,
    to_numpy_array,
    valid_images,
)
from ...utils import TensorType, logging
from ...utils.import_utils import is_vision_available


_SCREAMING_SNAKE_CASE:    Optional[Any]     						=							logging.get_logger(__name__)


if is_vision_available():
			import PIL

class 						_SCREAMING_SNAKE_CASE				(  _lowercase				):






		"""simple docstring"""







		A_    			=   ['''pixel_values''']



		def __init__(      self     :					Optional[Any]	,       __SCREAMING_SNAKE_CASE     :					bool = True	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int] = None	,       __SCREAMING_SNAKE_CASE     :					PILImageResampling = PILImageResampling.BILINEAR	,       __SCREAMING_SNAKE_CASE     :					bool = True	,       __SCREAMING_SNAKE_CASE     :					bool = False	,       __SCREAMING_SNAKE_CASE     :					bool = True	,       __SCREAMING_SNAKE_CASE     :					bool = True	,       __SCREAMING_SNAKE_CASE     :					Union[int, float] = 1 / 255	,       __SCREAMING_SNAKE_CASE     :					bool = True	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[float, List[float]]] = None	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[float, List[float]]] = None	,       **__SCREAMING_SNAKE_CASE     :					Any	,       ):






					"""simple docstring"""
					super().__init__(**__SCREAMING_SNAKE_CASE )

					_snake_case														=   size if size is not None else {"height": 2_560, "width": 1_920}
					if isinstance(__SCREAMING_SNAKE_CASE	,       (tuple, list) ):
								# The previous feature extractor size parameter was in (width, height) format
								_snake_case														=   size[::-1]
					_snake_case														=   get_size_dict(__SCREAMING_SNAKE_CASE )

					_snake_case														=   do_resize
					_snake_case														=   size
					_snake_case														=   resample
					_snake_case														=   do_thumbnail
					_snake_case														=   do_align_long_axis
					_snake_case														=   do_pad
					_snake_case														=   do_rescale
					_snake_case														=   rescale_factor
					_snake_case														=   do_normalize
					_snake_case														=   image_mean if image_mean is not None else IMAGENET_STANDARD_MEAN
					_snake_case														=   image_std if image_std is not None else IMAGENET_STANDARD_STD



		def 					_a					(      self     :					Tuple	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int]	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None ):






					"""simple docstring"""
					_snake_case							,			_snake_case														=   get_image_size(__SCREAMING_SNAKE_CASE )
					_snake_case							,			_snake_case														=   size["height"], size["width"]

					if (output_width < output_height and input_width > input_height) or (
					    output_width > output_height and input_width < input_height
					):
								_snake_case														=   np.rotaa(__SCREAMING_SNAKE_CASE	,       3 )

					if data_format is not None:
								_snake_case														=   to_channel_dimension_format(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE )

					return image



		def 					_a					(      self     :					Union[str, Any]	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int]	,       __SCREAMING_SNAKE_CASE     :					bool = False	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None	,       ):






					"""simple docstring"""
					_snake_case							,			_snake_case														=   size["height"], size["width"]
					_snake_case							,			_snake_case														=   get_image_size(__SCREAMING_SNAKE_CASE )

					_snake_case														=   output_width - input_width
					_snake_case														=   output_height - input_height

					if random_padding:
								_snake_case														=   np.random.randint(low=0	,       high=delta_height + 1 )
								_snake_case														=   np.random.randint(low=0	,       high=delta_width + 1 )
					else:
								_snake_case														=   delta_height // 2
								_snake_case														=   delta_width // 2

					_snake_case														=   delta_height - pad_top
					_snake_case														=   delta_width - pad_left

					_snake_case														=   ((pad_top, pad_bottom), (pad_left, pad_right))
					return pad(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       data_format=__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					List[str]	,       *__SCREAMING_SNAKE_CASE     :					Dict	,       **__SCREAMING_SNAKE_CASE     :					int ):






					"""simple docstring"""
					logger.info("pad is deprecated and will be removed in version 4.27. Please use pad_image instead." )
					return self.pad_image(*__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Any	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int]	,       __SCREAMING_SNAKE_CASE     :					PILImageResampling = PILImageResampling.BICUBIC	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None	,       **__SCREAMING_SNAKE_CASE     :					Optional[int]	,       ):






					"""simple docstring"""
					_snake_case							,			_snake_case														=   get_image_size(__SCREAMING_SNAKE_CASE )
					_snake_case							,			_snake_case														=   size["height"], size["width"]

					# We always resize to the smallest of either the input or output size.
					_snake_case														=   min(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE )
					_snake_case														=   min(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE )

					if height == input_height and width == input_width:
								return image

					if input_height > input_width:
								_snake_case														=   int(input_width * height / input_height )
					elif input_width > input_height:
								_snake_case														=   int(input_height * width / input_width )

					return resize(
					    __SCREAMING_SNAKE_CASE	,       size=(height, width)	,       resample=__SCREAMING_SNAKE_CASE	,       reducing_gap=2.0	,       data_format=__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Tuple	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int]	,       __SCREAMING_SNAKE_CASE     :					PILImageResampling = PILImageResampling.BICUBIC	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None	,       **__SCREAMING_SNAKE_CASE     :					int	,       ):






					"""simple docstring"""
					_snake_case														=   get_size_dict(__SCREAMING_SNAKE_CASE )
					_snake_case														=   min(size["height"]	,       size["width"] )
					_snake_case														=   get_resize_output_image_size(__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE	,       default_to_square=__SCREAMING_SNAKE_CASE )
					_snake_case														=   resize(__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE	,       resample=__SCREAMING_SNAKE_CASE	,       data_format=__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )
					return resized_image



		def 					_a					(      self     :					Dict	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Union[int, float]	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None	,       **__SCREAMING_SNAKE_CASE     :					Union[str, Any]	,       ):






					"""simple docstring"""
					return rescale(__SCREAMING_SNAKE_CASE	,       scale=__SCREAMING_SNAKE_CASE	,       data_format=__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Tuple	,       __SCREAMING_SNAKE_CASE     :					np.ndarray	,       __SCREAMING_SNAKE_CASE     :					Union[float, List[float]]	,       __SCREAMING_SNAKE_CASE     :					Union[float, List[float]]	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, ChannelDimension]] = None	,       **__SCREAMING_SNAKE_CASE     :					Optional[int]	,       ):






					"""simple docstring"""
					return normalize(__SCREAMING_SNAKE_CASE	,       mean=__SCREAMING_SNAKE_CASE	,       std=__SCREAMING_SNAKE_CASE	,       data_format=__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )







		def 					_a					(      self     :					Any	,       __SCREAMING_SNAKE_CASE     :					ImageInput	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					Dict[str, int] = None	,       __SCREAMING_SNAKE_CASE     :					PILImageResampling = None	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					bool = False	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					float = None	,       __SCREAMING_SNAKE_CASE     :					bool = None	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[float, List[float]]] = None	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[float, List[float]]] = None	,       __SCREAMING_SNAKE_CASE     :					Optional[Union[str, TensorType]] = None	,       __SCREAMING_SNAKE_CASE     :					Optional[ChannelDimension] = ChannelDimension.FIRST	,       **__SCREAMING_SNAKE_CASE     :					Any	,       ):






					"""simple docstring"""
					_snake_case														=   do_resize if do_resize is not None else self.do_resize
					_snake_case														=   size if size is not None else self.size
					if isinstance(__SCREAMING_SNAKE_CASE	,       (tuple, list) ):
								# Previous feature extractor had size in (width, height) format
								_snake_case														=   size[::-1]
					_snake_case														=   get_size_dict(__SCREAMING_SNAKE_CASE )
					_snake_case														=   resample if resample is not None else self.resample
					_snake_case														=   do_thumbnail if do_thumbnail is not None else self.do_thumbnail
					_snake_case														=   do_align_long_axis if do_align_long_axis is not None else self.do_align_long_axis
					_snake_case														=   do_pad if do_pad is not None else self.do_pad
					_snake_case														=   do_rescale if do_rescale is not None else self.do_rescale
					_snake_case														=   rescale_factor if rescale_factor is not None else self.rescale_factor
					_snake_case														=   do_normalize if do_normalize is not None else self.do_normalize
					_snake_case														=   image_mean if image_mean is not None else self.image_mean
					_snake_case														=   image_std if image_std is not None else self.image_std

					_snake_case														=   make_list_of_images(__SCREAMING_SNAKE_CASE )

					if not valid_images(__SCREAMING_SNAKE_CASE ):
								raise ValueError(
								    "Invalid image type. Must be of type PIL.Image.Image, numpy.ndarray, "
								    "torch.Tensor, tf.Tensor or jax.ndarray." )

					if do_resize and size is None:
								raise ValueError("Size must be specified if do_resize is True." )

					if do_rescale and rescale_factor is None:
								raise ValueError("Rescale factor must be specified if do_rescale is True." )

					if do_pad and size is None:
								raise ValueError("Size must be specified if do_pad is True." )

					if do_normalize and (image_mean is None or image_std is None):
								raise ValueError("Image mean and std must be specified if do_normalize is True." )

					# All transformations expect numpy arrays.
					_snake_case														=   [to_numpy_array(__SCREAMING_SNAKE_CASE ) for image in images]

					if do_align_long_axis:
								_snake_case														=   [self.align_long_axis(__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE ) for image in images]

					if do_resize:
								_snake_case														=   [self.resize(image=__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE	,       resample=__SCREAMING_SNAKE_CASE ) for image in images]

					if do_thumbnail:
								_snake_case														=   [self.thumbnail(image=__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE ) for image in images]

					if do_pad:
								_snake_case														=   [self.pad_image(image=__SCREAMING_SNAKE_CASE	,       size=__SCREAMING_SNAKE_CASE	,       random_padding=__SCREAMING_SNAKE_CASE ) for image in images]

					if do_rescale:
								_snake_case														=   [self.rescale(image=__SCREAMING_SNAKE_CASE	,       scale=__SCREAMING_SNAKE_CASE ) for image in images]

					if do_normalize:
								_snake_case														=   [self.normalize(image=__SCREAMING_SNAKE_CASE	,       mean=__SCREAMING_SNAKE_CASE	,       std=__SCREAMING_SNAKE_CASE ) for image in images]

					_snake_case														=   [to_channel_dimension_format(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE ) for image in images]

					_snake_case														=   {"pixel_values": images}
					return BatchFeature(data=__SCREAMING_SNAKE_CASE	,       tensor_type=__SCREAMING_SNAKE_CASE )


from typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


_SCREAMING_SNAKE_CASE:    Optional[Any]     						=							{
    '''configuration_sam''': [
        '''SAM_PRETRAINED_CONFIG_ARCHIVE_MAP''',
        '''SamConfig''',
        '''SamMaskDecoderConfig''',
        '''SamPromptEncoderConfig''',
        '''SamVisionConfig''',
    ],
    '''processing_sam''': ['''SamProcessor'''],
}


try:
			if not is_torch_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_SCREAMING_SNAKE_CASE:    Dict     						=							[
			    '''SAM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''SamModel''',
			    '''SamPreTrainedModel''',
			]
try:
			if not is_tf_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_SCREAMING_SNAKE_CASE:    Optional[Any]     						=							[
			    '''TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST''',
			    '''TFSamModel''',
			    '''TFSamPreTrainedModel''',
			]
try:
			if not is_vision_available():
						raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
			pass
else:
			_SCREAMING_SNAKE_CASE:    List[Any]     						=							['''SamImageProcessor''']


if TYPE_CHECKING:
			from .configuration_sam import (
			    SAM_PRETRAINED_CONFIG_ARCHIVE_MAP,
			    SamConfig,
			    SamMaskDecoderConfig,
			    SamPromptEncoderConfig,
			    SamVisionConfig,
			)
			from .processing_sam import SamProcessor

			try:
						if not is_torch_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_sam import SAM_PRETRAINED_MODEL_ARCHIVE_LIST, SamModel, SamPreTrainedModel

			try:
						if not is_tf_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .modeling_tf_sam import TF_SAM_PRETRAINED_MODEL_ARCHIVE_LIST, TFSamModel, TFSamPreTrainedModel

			try:
						if not is_vision_available():
									raise OptionalDependencyNotAvailable()
			except OptionalDependencyNotAvailable:
						pass
			else:
						from .image_processing_sam import SamImageProcessor

else:
			import sys

			_SCREAMING_SNAKE_CASE:    Union[str, Any]     						=							_LazyModule(__name__, globals()['''__file__'''], _import_structure, module_spec=__spec__)

