All Products
Search
Document Center

Intelligent Media Management:Image quality assessment

Last Updated:Dec 16, 2024

Intelligent Media Management (IMM) provides the image quality assessment feature that gives an overall quality score of an image based on metrics such as sharpness, noise, distortion, color saturation, and exposure. Image quality assessment can be used to select a high-quality cover image for articles and a thumbnail for videos, remove duplicate images, and filter out low-quality images.

Scenarios

  • Document cover image selection: Image quality assessment helps document creators select high-quality and visually striking cover images, which contributes to high click-through rates and visits.

  • Video thumbnail selection: Image quality assessment helps video content creators select high-quality and visually striking images as video thumbnails, which contributes to high click-through rates and enhanced viewer experience.

  • Low-quality image filtering: In image processing and storage systems, low-quality images may occupy a large amount of storage space and affect system performance and user experience. Image quality assessment can be used to automatically filter out blurry, distorted, or noisy images. This way, image libraries have increased quality and usability.

Prerequisites

  • An AccessKey pair is created and obtained. For more information, see Create an AccessKey pair.

  • OSS is activated, a bucket is created, and objects are uploaded to the bucket. For more information, see Upload objects.

  • IMM is activated. For more information, see Activate IMM.

  • A project is created in the IMM console. For more information, see Create a project.

    Note
    • You can call the CreateProject operation to create a project. For more information, see CreateProject.

    • You can call the ListProjects operation to query the existing projects in a specific region. For more information, see ListProjects.

Usage

Call the DetectImageScore operation to obtain the quality score of an image.

Example

  • IMM project name: test-project

  • Image location: oss://test-bucket/test-object.jpg

  • Image:test-object

Sample request

{
    "ProjectName": "test-project",
    "SourceURI": "oss://test-bucket/test-object.jpg",
}

Sample response

{
    "RequestId": "1AEABE83-5746-02E4-A97D-52EE4BB*****",
    "ImageScore": {
        "OverallQualityScore": 0.727
    }
}
Note

The highest quality score of an image is 1. A higher score indicates better image quality. The preceding response shows that the quality score of the image is 0.727.

Sample code

The following sample code provides an example on how to obtain the quality score of an image by using IMM SDK for Python:

# -*- coding: utf-8 -*-
# This file is auto-generated, don't edit it. Thanks.
import sys
import os
from typing import List

from alibabacloud_imm20200930.client import Client as imm20200930Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_imm20200930 import models as imm_20200930_models
from alibabacloud_tea_util import models as util_models
from alibabacloud_tea_util.client import Client as UtilClient


class Sample:
    def __init__(self):
        pass

    @staticmethod
    def create_client(
        access_key_id: str,
        access_key_secret: str,
    ) -> imm20200930Client:
        """
        Use your AccessKey ID and AccessKey secret to initialize the client. 
        @param access_key_id:
        @param access_key_secret:
        @return: Client
        @throws Exception
        """
        config = open_api_models.Config(
            access_key_id=access_key_id,
            access_key_secret=access_key_secret
        )
        # Specify the IMM endpoint. 
        config.endpoint = f'imm.cn-beijing.aliyuncs.com'
        return imm20200930Client(config)

    @staticmethod
    def main(
        args: List[str],
    ) -> None:
        # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a RAM user. 
        # We recommend that you do not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all the resources within your account may be compromised. 
        # In this example, the AccessKey pair is read from the environment variables to implement identity verification for API access. For information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html. 
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # Initialize the client. 
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        detect_image_score_request = imm_20200930_models.DetectImageScoreRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.jpg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Display the response of the API operation. 
            client.detect_image_score_with_options(detect_image_score_request, runtime)
        except Exception as error:
            # Print the error message if necessary. 
            UtilClient.assert_as_string(error.message)

    @staticmethod
    async def main_async(
        args: List[str],
    ) -> None:
        # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. To prevent security risks, we recommend that you call API operations or perform routine O&M as a RAM user. 
        # We recommend that you do not include your AccessKey pair (AccessKey ID and AccessKey secret) in your project code. Otherwise, the AccessKey pair may be leaked and the security of all the resources within your account may be compromised. 
        # In this example, the AccessKey pair is read from the environment variables to implement identity verification for API access. For information about how to configure environment variables, see https://www.alibabacloud.com/help/document_detail/2361894.html. 
        imm_access_key_id = os.getenv("AccessKeyId")
        imm_access_key_secret = os.getenv("AccessKeySecret")
        # Initialize the client. 
        client = Sample.create_client(imm_access_key_id, imm_access_key_secret)
        detect_image_score_request = imm_20200930_models.DetectImageScoreRequest(
            project_name='test-project',
            source_uri='oss://test-bucket/test-object.jpg'
        )
        runtime = util_models.RuntimeOptions()
        try:
            # Display the response of the API operation. 
            await client.detect_image_score_with_options_async(detect_image_score_request, runtime)
        except Exception as error:
            # Print the error message if necessary. 
            UtilClient.assert_as_string(error.message)


if __name__ == '__main__':
    Sample.main(sys.argv[1:])