Updated on 2024-12-10 GMT+08:00

Defog

Function

When a camera takes photos in smoggy weather, the image quality will be poor because the shooting scene is unclear. This API removes both uniform and non-uniform haze from images using the image defog algorithm. After you upload the image to be processed, Defog returns the processed image to you.

Prerequisites

Before using Defog, you need to apply for the service and complete authentication. For details, see Applying for a Service and Authentication.

URI

URI format

POST /v1.0/vision/defog

Request Message

Table 1 describes the request parameters.
Table 1 Parameter description

Parameter

Mandatory

Type

Description

image

Configure either this parameter or file.

String

Indicates the Base64 character string converted from the image. The size cannot exceed 10 MB. The supported image formats include JPEG, PNG, BMP, and WEBP.

file

Configure either this parameter or image.

File

Indicates the image file.

gamma

No

Float

Indicates the gamma correction value. The default value is 1.5. The value ranges from 0.1 to 10.

natural_look

No

Boolean

Indicates whether to keep the normal look. The default value is true. If the parameter is set to false, the image is defogged, but the visual effect may be unnatural.

Response Message

  • Table 2 describes the response parameters of Base64-encoded character strings.
    Table 2 Parameter description

    Parameter

    Type

    Description

    result

    String

    Indicates the Base64 character string converted from the image when the API is successfully called.

    This parameter is not included when the API fails to be called.

    error_code

    String

    Indicates the error code of a failed API call. For details, see Error Codes.

    This parameter is not included when the API is successfully called.

    error_msg

    String

    Indicates the error message of a failed API call.

    This parameter is not included when the API is successfully called.

  • Table 3 describes the response parameters of image files.
    Table 3 Parameter description

    Parameter

    Type

    Description

    error_code

    String

    Indicates the error code of a failed API call. For details, see Error Codes.

    This parameter is not included when the API is successfully called.

    error_msg

    String

    Indicates the error message of a failed API call.

    This parameter is not included when the API is successfully called.

Examples

  • Example request (Method 1: Use a Base64-encoded image.)
    POST https://image.ap-southeast-1.myhuaweicloud.com/v1.0/vision/defog
        
    Request Header:   
    Content-Type:application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG...    
    Request Body:
    {
      "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj...",
      "gamma":1.5,
      "natural_look":true
    }
  • Example request (Method 2: Use an image file.)
    POST https://image.ap-southeast-1.myhuaweicloud.com/v1.0/vision/defog
        
    Request Header:   
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDTALBglghkgBZQMEAgEwgguVBgkqhkiG... 
     
    Request Body(form-data):
    file: File (image file)
    gamma:1.5
    natural_look:true

Method 1: Use a Base64-encoded image.

  • Example successful response
    {
     "result":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAAgABwESAAMAAAABAAEAAAEaAAUAAAABAAAAYgEbAAUAAAABAAAAagEoAAMAAAABAAIAAAExAAIAAAAcAAAAcgEyAAIAAAAUAAAAjodpAAQAAAABAAAApAAAANAACvyAAAAnEAAK/IAAACcQQWRvYmUgUGhvdG9zaG9wIENTMyBXaW5kb3dzADIwMTc6MTA6MjAgMTA6NDU6MzYAAAAAA6ABAAMAAAAB//8AAKACAAQAAAABAAALIKADAAQAAAABAAAGQAAAAAAAAAAGAQMAAwAAAAEABgAAARoABQAAAAEAAAEeARsABQAAAAEAAAEmASgAAwAAAAEAAgAAAgEABAAAAAEAAAEuAgIABAAAAAEAABAj..."
    }
  • Example failed response
    {
        "error_code": "AIS.0105",
        "error_msg": "Recognize Failed"
    }

Method 2: Use an image file.

  • Sample response

    When the API is successfully called, the byte stream of the image file is returned.

  • Failed sample response
    {
        "error_code": "AIS.0105",
        "error_msg": "Recognize Failed"
    }

Return Value

  • Normal

    200

  • Abnormal

    Return Value

    Description

    400

    • The request cannot be understood by the server due to malformed syntax. The client should not repeat the request without modifications.
    • The request parameter is incorrect.

    401

    The request requires user authentication.

    403

    No operation permission.

    404

    The server has not found anything matching the Request-URI.

    500

    The server encountered an unexpected condition which prevented it from fulfilling the request.