Rescales `image` by `scale`. Args: image (`np.ndarray`): The image to rescale. scale (`float`): The scale to use for rescaling the image. data_format (`ChannelDimension`, *optional*): The channel dimension format of the image. If
(
image: np.ndarray,
scale: float,
data_format: Optional[ChannelDimension] = None,
dtype: np.dtype = np.float32,
input_data_format: Optional[Union[str, ChannelDimension]] = None,
)
| 95 | |
| 96 | |
| 97 | def rescale( |
| 98 | image: np.ndarray, |
| 99 | scale: float, |
| 100 | data_format: Optional[ChannelDimension] = None, |
| 101 | dtype: np.dtype = np.float32, |
| 102 | input_data_format: Optional[Union[str, ChannelDimension]] = None, |
| 103 | ) -> np.ndarray: |
| 104 | """ |
| 105 | Rescales `image` by `scale`. |
| 106 | |
| 107 | Args: |
| 108 | image (`np.ndarray`): |
| 109 | The image to rescale. |
| 110 | scale (`float`): |
| 111 | The scale to use for rescaling the image. |
| 112 | data_format (`ChannelDimension`, *optional*): |
| 113 | The channel dimension format of the image. If not provided, it will be the same as the input image. |
| 114 | dtype (`np.dtype`, *optional*, defaults to `np.float32`): |
| 115 | The dtype of the output image. Defaults to `np.float32`. Used for backwards compatibility with feature |
| 116 | extractors. |
| 117 | input_data_format (`ChannelDimension`, *optional*): |
| 118 | The channel dimension format of the input image. If not provided, it will be inferred from the input image. |
| 119 | |
| 120 | Returns: |
| 121 | `np.ndarray`: The rescaled image. |
| 122 | """ |
| 123 | if not isinstance(image, np.ndarray): |
| 124 | raise TypeError(f"Input image must be of type np.ndarray, got {type(image)}") |
| 125 | |
| 126 | rescaled_image = image * scale |
| 127 | if data_format is not None: |
| 128 | rescaled_image = to_channel_dimension_format(rescaled_image, data_format, input_data_format) |
| 129 | |
| 130 | rescaled_image = rescaled_image.astype(dtype) |
| 131 | |
| 132 | return rescaled_image |
| 133 | |
| 134 | |
| 135 | def _rescale_for_pil_conversion(image): |
no test coverage detected