{"id":7670,"library":"resize-right","title":"Resize Right","description":"Resize Right is a Python library providing a single, highly flexible `resize` function for image resizing. It supports both NumPy arrays and PyTorch tensors, offering various scaling options, padding modes, and output shape controls. The current version is 0.0.2. Releases appear to be infrequent, indicating a stable, focused utility rather than a rapidly evolving project.","status":"active","version":"0.0.2","language":"en","source_language":"en","source_url":"https://github.com/assafshocher/ResizeRight","tags":["image processing","resize","computer vision","numpy","pytorch"],"install":[{"cmd":"pip install resize-right","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"Core functionality relies on NumPy arrays for image manipulation.","package":"numpy","optional":false},{"reason":"Required only if you intend to resize PyTorch tensors.","package":"torch","optional":true}],"imports":[{"symbol":"resize","correct":"from resize_right import resize"}],"quickstart":{"code":"import numpy as np\nfrom resize_right import resize\n\n# Create a dummy 4D NumPy array (batch, H, W, channels)\n# representing a batch of 2 images, 100x100 pixels, 3 channels\nimage_batch = np.random.rand(2, 100, 100, 3).astype(np.float32)\n\nprint(f\"Original shape: {image_batch.shape}\")\n\n# Resize to half the size using scale_factors\nresized_batch_scale = resize(image_batch, scale_factors=0.5)\nprint(f\"Resized by scale_factors (0.5) shape: {resized_batch_scale.shape}\")\n\n# Resize to a specific output shape [50, 50] (for H, W)\nresized_batch_shape = resize(image_batch, out_shape=[50, 50])\nprint(f\"Resized by out_shape ([50, 50]) shape: {resized_batch_shape.shape}\")","lang":"python","description":"Demonstrates resizing a batch of NumPy images using both `scale_factors` and `out_shape` parameters. The library handles `(B, H, W, C)` for NumPy and `(B, C, H, W)` for PyTorch tensors."},"warnings":[{"fix":"Ensure NumPy arrays are consistently `(B, H, W, C)`. If converting from a `(B, C, H, W)` source, use `array.transpose(0, 2, 3, 1)` before passing to `resize_right.resize`.","message":"Input array layout for NumPy: `resize_right` expects NumPy arrays in `(batch, height, width, channels)` format. Providing `(batch, channels, height, width)` (common in PyTorch) will lead to incorrect resizing or errors due to misinterpretation of dimensions.","severity":"gotcha","affected_versions":"0.0.x"},{"fix":"Provide only one of `out_shape` or `scale_factors` to explicitly control the resizing behavior. If dynamic scaling is needed, calculate `out_shape` based on `scale_factors` manually and then pass only `out_shape`.","message":"Conflicting `out_shape` and `scale_factors` parameters: If both `out_shape` and `scale_factors` are provided, `out_shape` will take precedence, and `scale_factors` will be ignored. This might lead to unexpected output dimensions if the user intends `scale_factors` to be the primary control.","severity":"gotcha","affected_versions":"0.0.x"},{"fix":"Convert input arrays to `float32` or `float64` using `array.astype(np.float32)` before resizing for optimal results and to avoid potential issues with interpolation algorithms.","message":"Handling of non-float data types: While `resize_right` generally works with various numeric types, it's primarily designed for floating-point image data (e.g., `float32`, `float64`) common in deep learning pipelines. Using integer types might lead to precision loss or unexpected results during interpolation, especially for downsampling.","severity":"gotcha","affected_versions":"0.0.x"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the import statement is `from resize_right import resize`. Then call it directly as `resize(...)` instead of `resize_right.resize(...)`.","cause":"The `resize` function is directly imported from the `resize_right` module, not accessed as an attribute of the module object.","error":"AttributeError: module 'resize_right' has no attribute 'resize'"},{"fix":"Convert PIL Image objects to NumPy arrays first using `np.array(pil_image)` or PyTorch tensors using `torch.from_numpy(np.array(pil_image))` before passing them to the `resize` function.","cause":"The `resize` function only accepts NumPy arrays or PyTorch tensors as input, not native image objects from libraries like Pillow (PIL).","error":"ValueError: input_array should be a torch tensor or numpy array, but got <class 'PIL.Image.Image'>"},{"fix":"Ensure `out_shape` is a list or tuple of two integers (e.g., `[50, 50]`) or `scale_factors` is a single float or an iterable of two floats (e.g., `0.5` or `[0.5, 0.5]`) for specifying the resizing dimensions.","cause":"This often occurs when `out_shape` or `scale_factors` parameters are not provided in the expected format (e.g., an array where a scalar or list of integers is expected).","error":"TypeError: 'numpy.ndarray' object cannot be interpreted as an integer"}]}