Object Storage Service (OSS) の画像処理 (IMG) を使用して、OSS に保存されているイメージにガウスぼかしを適用します。イメージ全体をぼかすことも、検出された顔を自動的にターゲットにすることもできます。これは、プライバシー保護、視覚的な合成、表示品質の向上に役立ちます。
利用シーン
プライバシー保護:イメージを公開する前に、ナンバープレート番号や顔などの機密情報を隠します。
レイヤー化された画像の合成:複数レイヤーの合成でレイヤー間のエッジを滑らかにし、より洗練された結果にします。
低解像度ディスプレイ:低解像度のイメージを高解像度のスクリーンに表示する際のピクセレーションアーティファクトを和らげます。
パラメーター
アクション: blur
| パラメーター | 必須 | 説明 | 有効な値 |
|---|
r | はい | ぼかし半径。値が大きいほど、ぼかしが強くなります。 | 1–50 |
s | はい | ガウス分布の標準偏差。値が大きいほど、ぼかしが強くなります。 | 1–50 |
g | いいえ | ぼかし範囲。ぼかしをイメージ全体ではなく、検出された顔に限定します。 | face (最大の顔のみ)、faces (検出されたすべての顔) |
p | いいえ | 検出された顔のサイズに対するパーセンテージとして、ぼかし領域をリサイズします。g が設定されている場合にのみ適用されます。 | 1–200 (%) |
g パラメーターを使用するには、バケットを Intelligent Media Management (IMM) プロジェクトにバインドする必要があります。g を使用する場合、匿名アクセスはサポートされません。また、OSS で必要な IMM 権限も必要です。設定手順については、「クイックスタート」および「権限」をご参照ください。
画像のぼかし
URL を使用したパブリックイメージのぼかし
公開読み取りまたは公開読み書きのアクセス制御リスト (ACL) を持つイメージの場合、IMG パラメーターをオブジェクト URL に直接追加します。OSS はイメージをリアルタイムで処理し、結果を返します。SDK や API 呼び出しは不要です。
オブジェクト URL に ?x-oss-process=image/blur,r_10,s_10 を追加します:
https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/blur,r_10,s_10
| 元画像 | 処理後の画像 |
|---|
 |  |
https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg | https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image/blur,r_10,s_10 |
OSS SDK を使用した非公開イメージのぼかし
以下の例では、image/blur,r_10,s_10 を使用してイメージ全体をぼかし、結果をローカルファイルに保存します。コードを実行する前に、OSS_ACCESS_KEY_ID と OSS_ACCESS_KEY_SECRET を環境変数として設定してください。
他の言語については、「概要」をご参照ください。
Java
Java SDK 3.17.4 以降が必要です。
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GetObjectRequest;
import java.io.File;
public class Demo {
public static void main(String[] args) throws Throwable {
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
String objectName = "src.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// ぼかし半径:10、標準偏差:10
String image = "image/blur,r_10,s_10";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
ossClient.getObject(request, new File("D:\\dest.jpg"));
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
PHP SDK 2.7.0 以降が必要です。
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
$provider = new EnvironmentVariableCredentialsProvider();
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
$bucket= "examplebucket";
$object = "src.jpg";
$download_file = "D:\\dest.jpg";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// ぼかし半径:10、標準偏差:10
$image = "image/blur,r_10,s_10";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image);
$ossClient->getObject($bucket, $object, $options);
Python
Python SDK 2.18.4 以降が必要です。
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
key = 'source-example.jpg'
local_file_name = 'D:\\target-example.jpg'
# 最大の顔をぼかし処理: 半径 25、標準偏差 50
process = 'image/blur,g_face,r_25,s_50'
result = bucket.get_object_to_file(key, local_file_name, process=process)
Go
Go SDK 3.0.2 以降が必要です。
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func HandleError(err error) {
fmt.Println("Error:", err)
os.Exit(-1)
}
func main() {
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
HandleError(err)
}
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "",
oss.SetCredentialsProvider(&provider),
oss.AuthVersion(oss.AuthV4),
oss.Region("cn-hangzhou"))
if err != nil {
HandleError(err)
}
bucket, err := client.Bucket("examplebucket")
if err != nil {
HandleError(err)
}
// ぼかし半径:10、標準偏差:10
image := "image/blur,r_10,s_10"
err = bucket.GetObjectToFile("src.jpg", "D://dest.jpg", oss.Process(image))
if err != nil {
HandleError(err)
}
}
OSS API を使用した非公開イメージのぼかし
REST API を直接呼び出すカスタム統合の場合、GetObject リクエストにぼかしパラメーターを含め、V4 署名を使用してリクエストに署名します。詳細については、「(推奨) Authorization ヘッダーに V4 署名を含める」をご参照ください。
GET /oss.jpg?x-oss-process=image/blur,r_10,s_10 HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: SignatureValue
GetObject の完全な仕様については、「GetObject」をご参照ください。
その他の実装オプションについては、「IMG 実装モード」をご参照ください。
画像内の顔のぼかし
顔のぼかしでは、OSS と IMM の統合を利用して顔を自動的に検出します。g パラメーターを使用する前に、バケットを IMM プロジェクトにバインドしてください。詳細については、「クイックスタート」または「AttachOSSBucket」をご参照ください。
以下の例では、OSS SDKを使用しています。API アプローチの場合、GetObject リクエストで同じ x-oss-process 値を使用します (前のセクションのパターンを参照してください)。
最大の顔のぼかし
g_face を使用して、イメージ内の最大の顔を検出してぼかします。
パラメーター文字列: image/blur,g_face,r_25,s_50
| 元画像 | 処理後の画像 |
|---|
 |  |
サンプルコード
Java
Java SDK 3.17.4 以降が必要です。
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GetObjectRequest;
import java.io.File;
public class Demo {
public static void main(String[] args) throws Throwable {
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
String objectName = "example.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// すべての顔をぼかす: 半径 25、標準偏差 50
String image = "image/blur,g_faces,r_25,s_50";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
ossClient.getObject(request, new File("D:\\dest.jpg"));
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
PHP SDK 2.7.0 以降が必要です。
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
$provider = new EnvironmentVariableCredentialsProvider();
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
$bucket= "examplebucket";
$object = "src.jpg";
$download_file = "D:\\dest.jpg";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// すべての顔をぼかす: 半径 25、標準偏差 50
$image = "image/blur,g_faces,r_25,s_50";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image);
$ossClient->getObject($bucket, $object, $options);
Python
Python SDK 2.18.4 以降が必要です。
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
key = 'source-example.jpg'
local_file_name = 'D:\\target-example.jpg'
# 最大の顔をぼかす:半径 25、標準偏差 50
process = 'image/blur,g_face,r_25,s_50'
result = bucket.get_object_to_file(key, local_file_name, process=process)
Go
Go SDK 3.0.2 以降が必要です。
1. Analysis of the English text structure and meaning:
This is a Go code block with comments and function calls for Alibaba Cloud OSS SDK. The code demonstrates how to use environment variable credentials, create an OSS client, get a bucket, and process an image with face blurring.
2. Identification of technical terms and their proper translations:
- "package main" → "package main" (Go language keyword, keep as-is)
- "import" → "import" (Go keyword, keep as-is)
- "fmt", "os", "github.com/aliyun/aliyun-oss-go-sdk/oss" → package names, keep as-is
- "HandleError" → function name, keep as-is
- "Error:" → error message prefix, translate to "エラー:"
- "os.Exit(-1)" → system call, keep as-is
- "oss.NewEnvironmentVariableCredentialsProvider()" → SDK method, keep as-is
- "oss.New()" → SDK constructor, keep as-is
- "oss.SetCredentialsProvider(&provider)" → SDK option, keep as-is
- "oss.AuthVersion(oss.AuthV4)" → SDK constant, keep as-is
- "oss.Region("cn-hangzhou")" → SDK option, keep as-is
- "client.Bucket("examplebucket")" → SDK method, keep as-is
- "// Blur all faces: radius 25, standard deviation 50" → comment, translate to Japanese while preserving technical terms
- "image/blur,g_faces,r_25,s_50" → OSS image processing parameters, keep as-is
- "bucket.GetObjectToFile()" → SDK method, keep as-is
- "oss.Process(image)" → SDK option, keep as-is
3. Consideration of context and tone:
This is a code example for developers, so technical accuracy is critical. Comments should be translated clearly while preserving all technical parameters and syntax. The HTML structure must be preserved exactly.
4. Draft translation with reasoning:
- Keep all Go keywords, package names, and SDK method names in English
- Translate comments to Japanese, ensuring technical terms like "radius" and "standard deviation" are properly translated as "半径" and "標準偏差"
- Preserve all HTML attributes and structure
- Ensure proper spacing between Japanese and English elements (e.g., "半径 25")
5. Optimization and final review:
- Verify all technical terms follow standard translations (e.g., "standard deviation" → "標準偏差")
- Confirm code syntax remains intact
- Check that comments are natural Japanese while maintaining technical precision
- Ensure HTML structure preservation
- Validate spacing rules (half-width spaces between Japanese and English)
すべての顔のぼかし
g_faces を使用して、イメージ内のすべての顔を検出してぼかします。
パラメーター文字列: image/blur,g_faces,r_25,s_50
| 元画像 | 処理後の画像 |
|---|
 |  |
サンプルコード
Java
Java SDK 3.17.4 以降が必要です。
import com.aliyun.oss.*;
import com.aliyun.oss.common.auth.*;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.GetObjectRequest;
import java.io.File;
public class Demo {
public static void main(String[] args) throws Throwable {
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
String region = "cn-hangzhou";
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
String bucketName = "examplebucket";
String objectName = "example.jpg";
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// すべての顔をぼかす:半径 25、標準偏差 50
String image = "image/blur,g_faces,r_25,s_50";
GetObjectRequest request = new GetObjectRequest(bucketName, objectName);
request.setProcess(image);
ossClient.getObject(request, new File("D:\\dest.jpg"));
} catch (OSSException oe) {
System.out.println("Error Message:" + oe.getErrorMessage());
System.out.println("Error Code:" + oe.getErrorCode());
System.out.println("Request ID:" + oe.getRequestId());
System.out.println("Host ID:" + oe.getHostId());
} catch (ClientException ce) {
System.out.println("Error Message:" + ce.getMessage());
} finally {
if (ossClient != null) {
ossClient.shutdown();
}
}
}
}
PHP
PHP SDK 2.7.0 以降が必要です。
<?php
if (is_file(__DIR__ . '/../autoload.php')) {
require_once __DIR__ . '/../autoload.php';
}
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
}
use OSS\Credentials\EnvironmentVariableCredentialsProvider;
use OSS\OssClient;
$provider = new EnvironmentVariableCredentialsProvider();
$endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
$bucket= "examplebucket";
$object = "src.jpg";
$download_file = "D:\\dest.jpg";
$config = array(
"provider" => $provider,
"endpoint" => $endpoint,
"signatureVersion" => OssClient::OSS_SIGNATURE_VERSION_V4,
"region" => "cn-hangzhou"
);
$ossClient = new OssClient($config);
// すべての顔をぼかす:半径 25、標準偏差 50
$image = "image/blur,g_faces,r_25,s_50";
$options = array(
OssClient::OSS_FILE_DOWNLOAD => $download_file,
OssClient::OSS_PROCESS => $image);
$ossClient->getObject($bucket, $object, $options);
Python
Python SDK 2.18.4 以降が必要です。
# -*- coding: utf-8 -*-
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
region = 'cn-hangzhou'
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
key = 'source-example.jpg'
local_file_name = 'D:\\target-example.jpg'
# すべての顔をぼかす:半径 25、標準偏差 50
process = 'image/blur,g_faces,r_25,s_50'
result = bucket.get_object_to_file(key, local_file_name, process=process)
Go
Go SDK 3.0.2 以降が必要です。
package main
import (
"fmt"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func HandleError(err error) {
fmt.Println("Error:", err)
os.Exit(-1)
}
func main() {
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
HandleError(err)
}
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "",
oss.SetCredentialsProvider(&provider),
oss.AuthVersion(oss.AuthV4),
oss.Region("cn-hangzhou"))
if err != nil {
HandleError(err)
}
bucket, err := client.Bucket("examplebucket")
if err != nil {
HandleError(err)
}
// すべての顔をぼかす:半径 25、標準偏差 50
image := "image/blur,g_faces,r_25,s_50"
err = bucket.GetObjectToFile("example.jpg", "D://dest.jpg", oss.Process(image))
if err != nil {
HandleError(err)
}
}
顔の境界を越えたぼかし領域の拡大
p パラメーターを使用して、ぼかし領域を検出された顔の境界を越えて拡大します。これは、髪や周囲のコンテキストも隠す必要がある場合に便利です。値は検出された顔のサイズに対するパーセンテージです。p_200 は、ぼかし領域を顔サイズの 2 倍に拡大します。
ぼかし領域を拡大した最大の顔
パラメーター文字列: image/blur,g_face,p_200,r_25,s_50
| 元画像 | 処理後の画像 |
|---|
 |  |
ぼかし領域を拡大したすべての顔
パラメーター文字列: image/blur,g_faces,p_200,r_25,s_50
| 元画像 | 処理後の画像 |
|---|
 |  |
SDK コードは上記の例と同じパターンに従います。image パラメーター文字列を適切な値に置き換えてください。例えば、Java の場合:
// 最大の顔をぼかし、ぼかし領域を顔サイズの 2 倍に拡大
String image = "image/blur,g_face,p_200,r_25,s_50";
// すべての顔をぼかし、ぼかし領域を顔サイズの 2 倍に拡大
// (別のスコープで宣言するか、別の変数名を使用)
String image2 = "image/blur,g_faces,p_200,r_25,s_50";
リファレンス
OSS IMG のぼかしと CSS の filter: blur() を組み合わせて、Web ページでレイヤー化された視覚効果を作成します。次の例では、サーバー側で IMG のぼかしを適用し、その上に CSS のぼかしを追加して相加効果を生み出しています:
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ぼかし効果の例</title>
<style>
.blurred {
filter: blur(5px);
}
.container {
position: relative;
width: 300px;
}
.text {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
color: white;
font-size: 24px;
}
</style>
</head>
<body>
<div class="container">
<img src="https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg" alt="サンプルイメージ" class="blurred">
<div class="text">Hello World</div>
</div>
<div>
<img src="https://oss-console-img-demo-cn-hangzhou-3az.oss-cn-hangzhou.aliyuncs.com/example1.jpg?x-oss-process=image%2Fblur%2Cr_10%2Cs_10&spm=a2c4g.11186623.0.i12">
</div>
</body>
</html>