> ## Documentation Index
> Fetch the complete documentation index at: https://cloudinary.com/documentation/llms.txt
> Use this file to discover all available pages before exploring further.

# Image quality analysis


You may want to determine the quality of images uploaded to your product environment, particularly for [user-generated content](user_generated_content).  If you set the `quality_analysis` parameter to `true`, a quality analysis focus score between 0.0 and 1.0 is returned indicating the quality of focus in the image. A score of 0.0 means the image is blurry and out of focus and 1.0 means the image is sharp and in focus.  

You can request quality analysis while [uploading](image_upload_api_reference#upload) an image, or by using the [explicit](image_upload_api_reference#explicit) method on an already uploaded image.

**See also**: [Image quality analysis](cloudinary_ai_content_analysis_addon#image_quality_analysis) using the Cloudinary AI Content Analysis add-on.

## Quality analysis while uploading

You can request quality analysis while uploading by specifying the `quality_analysis` parameter in the upload method.

For example, uploading the "user_photo.jpg" image and requesting quality analysis:

``` multi
|ruby 
Cloudinary::Uploader.upload("user_photo.jpg", 
  quality_analysis: true)

|php_2
$cloudinary->uploadApi()->upload("user_photo.jpg",
  [ "quality_analysis" => true ]);

|nodejs
cloudinary.v2.uploader
.upload("user_photo.jpg",
  { quality_analysis: true })
.then(result=>console.log(result)); 

|python
cloudinary.uploader.upload("user_photo.jpg",
  quality_analysis = 1)

|java
cloudinary.uploader().upload("user_photo.jpg", 
  Cloudinary.asMap("quality_analysis", true));

|csharp
var uploadParams = new ImageUploadParams(){
  File = new FileDescription(@"user_photo.jpg"),
  QualityAnalysis = true};
var uploadResult = cloudinary.Upload(uploadParams); 

|go
resp, err := cld.Upload.Upload(ctx, "user_photo.jpg", uploader.UploadParams{
	QualityAnalysis: api.Bool(true)})

|cli
cld uploader upload user_photo.jpg quality_analysis=true

|curl
curl https://api.cloudinary.com/v1_1/demo/image/upload -X POST --data 'file=user_photo.jpg&quality_analysis=true&timestamp=173719931&api_key=436464676&signature=a788d68f86a6f868af'
```

> **TIP**: Take a look at the [profile picture sample project](profile_picture_sample_project), which demonstrates the use of the quality analysis on upload in a Next.js app.

## Quality analysis on already uploaded images

There are two ways to request quality analysis on already uploaded images:

* Use the [Explicit](image_upload_api_reference#explicit_method) method of the Upload API to request quality analysis on a single asset. This method is not rate-limited and requires a signature to be generated on the server side.
* Use the [Update resources](admin_api#update_resources) method of the Admin API. This method is rate-limited and requires your API key and secret, so is not suitable for use in client-side code.

### Explicit example

The following example uses the [Explicit](image_upload_api_reference#explicit_method) method of the Upload API to request quality analysis on the image with a public ID of "user1":

``` multi
|ruby 
Cloudinary::Uploader.explicit("user1", 
  type: "upload",
  quality_analysis: true)

|php_2
$cloudinary->uploadApi()->explicit("user1",[ 
    "type" => "upload",
    "quality_analysis" => true ]);

|nodejs
cloudinary.v2.uploader.explicit("user1",
  { type: "upload",
    quality_analysis: true })
.then(result=>console.log(result)); 

|python
cloudinary.uploader.explicit("user1",
  type = "upload",
  quality_analysis = 1)

|java
cloudinary.uploader().explicit("user1", 
  Cloudinary.asMap(
    "type", "upload",
    "quality_analysis", true));

|csharp
var explicitParams = new ExplicitParams("user1"){
  Type = "upload",
  QualityAnalysis = true};
var uploadResult = cloudinary.Explicit(explicitParams); 

|go
resp, err := cld.Upload.Explicit(ctx, uploader.ExplicitParams{
    PublicID: "user1",
    Type: "upload",
	QualityAnalysis: api.Bool(true)})

|cli
cld uploader explicit user1 type="upload" quality_analysis=true

|curl
curl https://api.cloudinary.com/v1_1/cld-docs/image/explicit -X POST --data 'type=upload&public_id=user1&quality_analysis=true&timestamp=173719931&api_key=614335564976464&signature=a788d68f86a6f868af'
```

### Update resources example

The following example uses the [Update resources](admin_api#update_resources) method of the Admin API to request quality analysis on an uploaded image with a public ID of "table":

```multi
|curl
curl \
 -d "type=upload&quality_analysis=true" \
 -X POST \
 https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<cloud_name>/resources/image/upload/table
        
|ruby
result = Cloudinary::Api
.update("table",
  type: "upload",
  quality_analysis: true)

|php_2
$result = $api
->update("table", [
    "type" => "upload",
    "quality_analysis" => true]);

|python
result = cloudinary.api\
.update("table",
  type = "upload",
  quality_analysis = True)

|nodejs
cloudinary.v2.api
.update("table", 
  { type: "upload",
    quality_analysis: true})
.then(result=>console.log(result)); 

|java
result = cloudinary.api()
.update("table",
  ObjectUtils.asMap(
    "type", "upload",
    "quality_analysis", true));

|csharp
var updateParams = new UpdateParams("table"){
  Type = "upload",
  QualityAnalysis = true};
var updateResult = cloudinary.UpdateResource(updateParams); 

|go
	resp, err := cld.Admin.UpdateAsset(ctx, admin.UpdateAssetParams{
	PublicID:         "table",
	Type:           "upload",
	QualityAnalysis:  api.Bool(true)})

|cli
cld admin update table type="upload" quality_analysis=true
```

## Sample response

```json
{
    "asset_id": "a05d0aea705f27dc534dd6fdb842fce2",
    "public_id": "vbfrhy4tyzyn7albdmhk",
    "version": 1719306992,
    "version_id": "510847884e6a730606178f8bc37111f2",
    "signature": "ec10ea8e97fbbe223e2d9596e4486106f50e1c42",
    "width": 1920,
    "height": 1281,
    "format": "jpg",
    "resource_type": "image",
    "created_at": "2024-06-25T09:16:32Z",
    "tags": [],
    "pages": 1,
    "bytes": 310479,
    "type": "upload",
    "etag": "a8f8236455d352b8cee6aba0e3fbc87e",
    "placeholder": false,
    "url": "http://res.cloudinary.com/cld-docs/image/upload/v1719306992/vbfrhy4tyzyn7albdmhk.jpg",
    "secure_url": "https://res.cloudinary.com/cld-docs/image/upload/v1719306992/vbfrhy4tyzyn7albdmhk.jpg",
    "asset_folder": "",
    "display_name": "vbfrhy4tyzyn7albdmhk",
    "quality_analysis": {
        "focus": 0.7031299471855164
    },
    "original_filename": "user_photo",
    "api_key": "614335564976464"
}
```

## Extended quality analysis

A more detailed quality analysis of uploaded images is available through **extended quality analysis**.

> **INFO**:
>
> **Extended quality analysis** is currently in Beta. Some implementation details may change before the official release. If you have a paid account, you can [request to take part](https://support.cloudinary.com/hc/en-us/requests/new) in the Beta trial.  We invite you to share any feedback via our [support team](https://support.cloudinary.com/hc/en-us/requests/new).

With **extended quality analysis** activated, the response to an [upload](image_upload_api_reference#upload) or [explicit](image_upload_api_reference#explicit) request with `quality_analysis` set to `true` includes scores for different quality factors in addition to the normally available focus related score.  An overall weighted quality score is also included:

```json
  "quality_analysis": {
    "jpeg_quality": 0.76,
    "jpeg_chroma": 0.25,
    "focus": 0.16,
    "noise": 1.0,
    "contrast": 0.85,
    "exposure": 0.97,
    "saturation": 1.0,
    "lighting": 1.0,
    "pixel_score": 0.27,
    "color_score": 0.91,
    "dct": 0.29,
    "blockiness": 1.0,
    "chroma_subsampling": 0.06,
    "resolution": 0.08
  },
  "quality_score": 0.47,
```

* Scores vary from 0.0 (worst) to 1.0 (best).
* For multi-page images, only the first page is evaluated. 
* `jpeg_*` scores are only present for JPEG originals.
* JPEG quality is considered best (1.0) if chroma is present for all pixels (no chroma subsampling).
* Estimation of compression artifacts (DCT, blockiness and chroma subsampling) is not done for images above 10 MP
* Resolution gives preference to HD (1920 x 1080) and higher.
* `pixel_score` is a measure of how the image looks in terms of compression artifacts (blockiness, ringing etc.) and in terms of capture quality (focus and sensor noise). Downscaling can improve the perceived visual quality of an image with a poor pixel score.
* `color_score` takes into account factors such as exposure, white balance, contrast and saturation.  Downscaling makes no difference to the perceived color quality.

The `quality_score`, `quality_analysis.color_score` and `quality_analysis.pixel_score` fields can be used in the [search method](search_method) when `quality_analysis` is set to `true` in the [upload](image_upload_api_reference#upload) request or an [upload preset](upload_presets). Note that these scores are not indexed for search when returned as part of an [explicit](image_upload_api_reference#explicit) request.
