Skip to content

Commit

Permalink
refactor: Refactor some functions in preprocess image
Browse files Browse the repository at this point in the history
  • Loading branch information
hh-space-invader committed Dec 4, 2024
1 parent 33de341 commit b32ad5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion fastembed/image/transform/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def pad2square(
image = image.crop((left, top, right, bottom))
return image

new_image = Image.new(mode="RGB", size=(size, size), color=fill_color)
new_image = Image.new(mode="RGB", size=(size, size), color=fill_color or 0)
left = (size - width) // 2
top = (size - height) // 2
new_image.paste(image, (left, top))
Expand Down
15 changes: 7 additions & 8 deletions fastembed/image/transform/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ def __init__(self, mean: Union[float, list[float]], std: Union[float, list[float
self.std = std

def __call__(self, images: list[np.ndarray]) -> list[np.ndarray]:
return [
normalize(image, mean=np.array(self.mean), std=np.array(self.std)) for image in images
]
return [normalize(image, mean=self.mean, std=self.std) for image in images]


class Resize(Transform):
Expand Down Expand Up @@ -183,11 +181,12 @@ def _get_resize(transforms: list[Transform], config: dict[str, Any]):
)
)
elif mode == "JinaCLIPImageProcessor":
resample = (
Compose._interpolation_resolver(config.get("interpolation"))
if isinstance(config.get("interpolation"), str)
else config.get("interpolation", Image.Resampling.BICUBIC)
)
interpolation = config.get("interpolation")
if isinstance(interpolation, str):
resample = Compose._interpolation_resolver(interpolation)
else:
resample = interpolation or Image.Resampling.BICUBIC

if "size" in config:
resize_mode = config.get("resize_mode", "shortest")
if resize_mode == "shortest":
Expand Down

0 comments on commit b32ad5e

Please sign in to comment.