Skip to content

Commit

Permalink
Add blur background to editing
Browse files Browse the repository at this point in the history
  • Loading branch information
jrrodri committed Dec 17, 2024
1 parent b023378 commit b06fad1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 6 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ abraia editing removebg "*.jpg"

![removebg output](https://github.com/abraia/abraia-multiple/raw/master/images/removebg-output.png)

### Blur background

Automatically blur the images background to focus attentioin on the main objects.

```sh
abraia editing blur "*.jpg"
```

![blur background output](https://github.com/abraia/abraia-multiple/raw/master/images/blur-background.jpg)

### Upscale images

Scale up and enhance images in bulk, doubling the size and preserving quality.
Expand Down Expand Up @@ -179,8 +189,6 @@ Compress images in bulk specifying the input glob pattern or folder:
abraia editing convert "images/bird*.jpg"
```

![image optimized](https://github.com/abraia/abraia-multiple/raw/master/images/birds_optimized.jpg)

Automatically change the aspect ratio specifying both `width` and `height` parameters and setting the resize `mode` (pad, crop, thumb). Or simply resize images maintaining the aspect ratio just specifying the `width` or the `height` of the new image:

```sh
Expand Down
2 changes: 1 addition & 1 deletion abraia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dotenv import load_dotenv
load_dotenv()

__version__ = '0.21.0'
__version__ = '0.21.1'

from . import config
from .client import Abraia, APIError
Expand Down
8 changes: 8 additions & 0 deletions abraia/editing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ def remove_background(img):
return out


def blur_background(img):
mask = (np.ones(img.shape[:2]) * 255).astype(np.uint8)
back = draw.draw_blurred_mask(img.copy(), mask)
fore = remove_background(img)
out = draw.draw_overlay(back, fore)
return out


def upscale_image(img):
if max(img.shape) > 1920:
h, w = img.shape[:2]
Expand Down
Binary file added images/blur-background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/blur.jpg
Binary file not shown.
Binary file added images/motorcycle.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 15 additions & 3 deletions scripts/abraia
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ from tqdm import tqdm
from urllib.parse import urlparse
from concurrent.futures import ProcessPoolExecutor

from abraia.utils import load_image
from abraia.editing import clean_image
from abraia.utils import load_image, save_image
from abraia.editing import clean_image, blur_background

from abraia import config
from abraia import Abraia
Expand Down Expand Up @@ -80,6 +80,11 @@ def convert_file(src, dest, args):


def editing_file(src, dest, mode):
if mode == 'blur':
img = load_image(src)
out = blur_background(img)
save_image(out, dest)
return dest
output = f"export/{os.path.basename(dest)}"
path = abraia.upload_file(src, 'batch/')
if mode == 'anonymize':
Expand Down Expand Up @@ -154,10 +159,17 @@ def anonymize(src):
editing_files(src, 'anonymize', desc="Anonymizing")


@cli_editing.command()
@click.argument('src')
def blur(src):
"""Blur the image background to focus attention on the main object."""
editing_files(src, 'blur', desc="Blur background")


@cli_editing.command()
@click.argument('src')
def clean(src):
"""Clean images removing unwanted objects with inpating."""
"""Clean images removing unwanted objects with inpainting."""
img = load_image(src)
clean_image(img)

Expand Down

0 comments on commit b06fad1

Please sign in to comment.