Image Super Resolution
Upscale the resolution and enhance details in the images.
Applicable scenarios
Applicable to converting original image assets into high resolution images.
Requirements for AWS service quotas
- This API needs to create a GPU instance based on Amazon SageMaker. If the corresponding instance limit in your AWS account is insufficient, the API feature will be deployed abnormally. You can click Support Center on the toolbar at the top of the AWS Management Console to create a support ticket to request an increase in the instance limit of the Amazon SageMaker service. For more information, see AWS service quotas.
- The default AWS Lambda memory is about 4GB (4096 MB). If the AWS Lambda function limit in your AWS account is lower than 4096 MB, the API feature will be deployed abnormally. You can click Support Center on the toolbar at the top of the AWS Management Console to create a support ticket and request to increase the memory limit of the AWS Lambda service. For more information, see AWS service quotas.
API reference
-
HTTP request method:
POST
-
Request body parameters
Name | Type | Required | Description |
---|---|---|---|
url | String | Choose url or img. | Image URL address, which supports HTTP/HTTPS and S3 protocols. Supported image formats are jpg/jpeg/png/bmp. Image size should not exceed 1920 * 1080. With portrait enhancement enabled, it is recommended that the image size should not exceed 1280 * 720. Due to performance limitations, the recommended image size does not exceed 400 * 400 for architecture based on AWS Lambda. |
img | String | Choose url or img. | Base64-encoded image data |
scale | Integer | no | Upscale size. 2 (default) or 4 is supported |
face | Bool | no | By default, it is False. When set to True, face enhancement is enabled. Only GPU deployment is supported. |
- Example JSON request
{
"url": "Image URL address",
"scale" : 2
}
{
"img": "Base64-encoded image data",
"scale" : 4
}
- Response parameters
Name | Type | Description |
---|---|---|
result | String | Base64-encoded image data after scaling |
- Example JSON response
{
"result": "Base64-encoded image data after scaling"
}
API test
You can use the following tools (API explorer, Postman, cURL, Python, Java) to test calling APIs.
API Explorer
Prerequisites
When deploying the solution, you need to:
- set the parameter API Explorer to
yes
. - set the parameter API Gateway Authorization to
NONE
.
Otherwise, you can only view the API definitions in the API explorer, but cannot test calling API online.
Steps
- Sign in to the AWS CloudFormation console.
-
On the Stacks page, select the solution’s root stack. Do not select the NESTED stack.
-
Choose the Outputs tab, and find the URL for APIExplorer.
-
Click the URL to access the API explorer. The APIs that you have selected during deployment will be displayed.
-
For the API you want to test, click the down arrow to display the request method.
- Choose the Try it out button, and enter the correct Body data to test API and check the test result.
- Make sure the format is correct, and choose Execute.
- Check the returned result in JSON format in the Responses body. If needed, copy or download the result.
- Check the Response headers.
- (Optional) Choose Clear next to the Execute button to clear the request body and responses.
Postman (AWS_IAM Authentication)
- Sign in to the AWS CloudFormation console.
- On the Stacks page, select the solution’s root stack.
- Choose the Outputs tab, and find the URL with the prefix
GeneralOCR
. -
Create a new tab in Postman. Paste the URL into the address bar, and select POST as the HTTP call method.
-
Open the Authorization configuration, select Amazon Web Service Signature from the drop-down list, and enter the AccessKey, SecretKey and Amazon Web Service Region of the corresponding account (such as cn-north-1 or cn-northwest-1 ).
-
Open the Body configuration item and select the raw and JSON data types.
- Enter the test data in the Body, and click the Send button to see the corresponding return results.
{
"url": "Image URL address"
}
cURL
- Windows
curl --location --request POST "https://[API_ID].execute-api.[AWS_REGION].amazonaws.com/[STAGE]/image_super_resolution" ^
--header "Content-Type: application/json" ^
--data-raw "{\"url\": \"Image URL address\"}"
- Linux/MacOS
curl --location --request POST 'https://[API_ID].execute-api.[AWS_REGION].amazonaws.com/[STAGE]/image_super_resolution' \
--header 'Content-Type: application/json' \
--data-raw '{
"url":"Image URL address"
}'
Python (AWS_IAM Authentication)
import requests
import json
from aws_requests_auth.boto_utils import BotoAWSRequestsAuth
auth = BotoAWSRequestsAuth(aws_host='[API_ID].execute-api.[AWS_REGION].amazonaws.com',
aws_region='[AWS_REGION]',
aws_service='execute-api')
url = 'https://[API_ID].execute-api.[AWS_REGION].amazonaws.com/[STAGE]/image_super_resolution'
payload = {
'url': 'Image URL address'
}
response = requests.request("POST", url, data=json.dumps(payload), auth=auth)
print(json.loads(response.text))
Python (NONE Authentication)
import requests
import json
url = "https://[API_ID].execute-api.[AWS_REGION].amazonaws.com/[STAGE]/image_super_resolution"
payload = json.dumps({
"url": "Image URL address"
})
headers = {
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
Java
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"url\":\"Image URL address\"\n}");
Request request = new Request.Builder()
.url("https://xxxxxxxxxxx.execute-api.xxxxxxxxx.amazonaws.com/[STAGE]/image_super_resolution")
.method("POST", body)
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
Cost Estimation
You are responsible for the cost of using each Amazon Web Services service when running the solution. As of this revision, the main cost factors affecting the solution include.
- Amazon API Gateway calls
- Amazon API Gateway data output
- Amazon CloudWatch Logs storage
- Amazon Elastic Container Registry storage
- Amazon SageMaker endpoint instance type
- Amazon SageMaker endpoint data input
- Amazon SageMaker endpoint data output
Example
In US East (Ohio) Region (us-east-2), process one million images, with an average processing time of 1 second for one image. Amazon SageMaker endpoint instance will be charged as long as it is started.
The cost of using this solution is shown below:
Service | Dimensions | Cost |
---|---|---|
Amazon API Gateway | 1 million invocations | $3.5 |
Amazon API Gateway | 4MB data output each time, $0.09/GB | $360 |
Amazon CloudWatch Logs | 10KB each time, $0.50/GB | $0.05 |
Amazon Elastic Container Registry | 0.5GB storage, $0.1/GB per month | $0.05 |
Amazon SageMaker | Endpoint instance runs for 278 hours, ml.g4dn.xlarge $0.736/hour | $204.61 |
Amazon SageMaker | Endpoint instance data input is 1MB each time, $0.016/GB | $16 |
Amazon SageMaker | Endpoint instance data output is 4MB each time, $0.016/GB | $64 |
Total | $648.21 |
Uninstall the deployment
You can uninstall the Image Super Resolution feature via Amazon CloudFormation as described in Add or remove AI features and make sure the ImageSuperResolution parameter is set to no in the parameters section.
Note
Time to uninstall the deployment is approximately: 20 Minutes