跳到主要内容

🥷 [S2] Challenge 12

· 阅读需 1 分钟

Just KNIME It, Season 2 / Challenge 12 reference

Challenge 12: Blur the Image​

Level : Easy

Description: You are contacted by the police department and asked for some help. They need to provide the press with an image of a witness, but they must preserve their face a secret. They want you to blur the image, such that it is clear that it corresponds to an actual person but their identity still remains undisclosed. Hint: Consider using the Gaussian Convolution node.

Author: Daria Liakh Dataset: Witness Image in the KNIME Hub

Solution​

Pillow is an integrated library within KNIME's Python environment. Therefore, accomplishing this challenge is quite straightforward. A simple Python View node is all that's needed.

import knime.scripting.io as knio
import requests
from PIL import Image, ImageFilter
from io import BytesIO

# Download an JPEG image
url = "https://api.hub.knime.com/repository/Users/alinebessa/Just%20KNIME%20It!%20Season%202%20-%20Datasets/Challenge%2012%20-%20Dataset/Image/personwhodeosnotexist.jpg:data?spaceVersion=-1"
headers = {'User-Agent': 'KNIME_AP_view_example/0.0 (https://knime.com)'}
response = requests.get(url, headers=headers)
if response.ok:
image_data = response.content
# Open the image
image = Image.open(BytesIO(image_data))
blurred_image = image.filter(ImageFilter.GaussianBlur(30))
else:
raise RuntimeError(f"Downloading the image failed: '{response.reason}'")


# Set the image as the output view
# knio.view will detect that the bytes object is a JPEG image automatically
knio.output_view = knio.view(blurred_image) # alternative: knio.view_jpeg(image)

Any thoughts?​

  • I am uncertain whether the latest technology has the capability to restructure it or not.
  • Incorporating a widget for image upload/download could enhance the user experience.