Google Vision DetectLabels
Google Vision DetectLabels transformation allows users to automatically detect objects, scenes, and concepts within images.
Using machine learning algorithms, the DetectLabels API analyzes visual content and returns a list of labels with associated confidence scores. These labels can include things like a person, car, dog, mountain, beach, and many others.
This DetectLabels API is part of the Google Cloud Vision API, which provides a wide range of image analysis capabilities, including image labeling, face detection, optical character recognition (OCR), and more.
Installing the Google Vision add-on is a must for using this transformation.
Params
Maximum Labels (l
)
This parameter is used to specify the maximum number of labels that should be returned in the API response.
Available values are from 0
to 10
. The default value is 5
.
If the number of labels detected in an image is greater than the specified max_results value, the API will only return the top max_results labels with the highest confidence scores.
For example, if l
is set to 6
and Google Vision detects 10
labels in an image, it will return only the top 6
labels with the highest confidence scores.
Adjusting the l
parameter can be useful in cases where you only need to retrieve the most relevant labels for your application or when you want to reduce the size of the API response.
Instead of getting the output in a traditional CDN URL, you will get a JSON output from the Context API while the CDN URL will return the original image without any modifications.
- Input Image
- Context API Response
- URL
- React
- JavaScript
- Node.js
- Python
- Golang
- Kotlin
- C#
- PHP
<PixelBinImage
url="https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg"
/>
import Pixelbin from "@pixelbin/core";
const obj = {
cloudName: "dummy-cloudname",
zone: "FIDrmb",
version: "v2",
transformations: [],
filePath: "images/transformation/basic_girl_2.jpeg",
baseUrl: "https://cdn.pixelbin.io",
};
const url = Pixelbin.default.utils.objToUrl(obj);
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
const Pixelbin = require("@pixelbin/admin");
const obj = {
cloudName: "dummy-cloudname",
zone: "FIDrmb",
version: "v2",
transformations: [],
filePath: "images/transformation/basic_girl_2.jpeg",
baseUrl: "https://cdn.pixelbin.io",
};
const url = Pixelbin.url.objToUrl(obj);
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
from pixelbin.utils.url import obj_to_url
obj = {
"cloudName": "dummy-cloudname",
"zone": "FIDrmb",
"version": "v2",
"transformations": [],
"filePath": "images/transformation/basic_girl_2.jpeg",
"baseUrl": "https://cdn.pixelbin.io",
}
url = obj_to_url(obj)
# url
# https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
package main
import (
"fmt"
"github.com/pixelbin-dev/pixelbin-go/v2/sdk/utils/url"
)
func main() {
obj := map[string]interface{}{
"cloudName": "dummy-cloudname",
"zoneSlug": "FIDrmb",
"version": "v2",
"transformations": []map[string]interface{}{
},
"filePath": "images/transformation/basic_girl_2.jpeg",
"baseUrl": "https://cdn.pixelbin.io",
"options": map[string]interface{}{},
}
urlstring, err := url.ObjToUrl(obj)
if err != nil {
fmt.Println(err)
}
}
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
import com.pixelbin.url.UrlObj
import com.pixelbin.Utils
import com.pixelbin.transformation.TransformationObj
fun main(){
val obj = UrlObj(
cloudName = "dummy-cloudname",
zone = "FIDrmb",
version = "v2",
transformation = arrayListOf(
),
filePath = "images/transformation/basic_girl_2.jpeg",
baseUrl = "https://cdn.pixelbin.io"
)
val url = Utils.objToUrl(obj)
}
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
using System;
using System.Collections.Generic;
using System.IO;
using Pixelbin.Utils;
namespace ExampleNamespace
{
class ExampleClass
{
static void Main(string[] args)
{
UrlObj obj = new UrlObj(
version: "v2",
cloudName: "dummy-cloudname",
filePath: "images/transformation/basic_girl_2.jpeg",
zone: "FIDrmb",
baseUrl: "https://cdn.pixelbin.io",
transformations: new List<UrlTransformation>() {
}
);
string url = Url.ObjToUrl(obj);
}
}
}
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
<?php
require 'vendor/autoload.php';
use Pixelbin\Utils\Url;
$obj = [
"cloudName" => "dummy-cloudname",
"zone" => "FIDrmb",
"version" => "v2",
"options" => [],
"transformations" => [
],
"filePath" => "images/transformation/basic_girl_2.jpeg",
"baseUrl" => "https://cdn.pixelbin.io",
];
$url = Url::obj_to_url($obj);
// url
// https://cdn.pixelbin.io/v2/dummy-cloudname/FIDrmb/original/images/transformation/basic_girl_2.jpeg
?>
The response for an API call with the above request body can look like this.
{
"Hair": {
"mid": "/m/03q69",
"description": "Hair",
"score": 0.9838786,
"topicality": 0.9838786
},
"Face": {
"mid": "/m/0dzct",
"description": "Face",
"score": 0.98373497,
"topicality": 0.98373497
},
"Joint": {
"mid": "/m/01dvt1",
"description": "Joint",
"score": 0.9769478,
"topicality": 0.9769478
},
"Skin": {
"mid": "/m/06z04",
"description": "Skin",
"score": 0.9744162,
"topicality": 0.9744162
},
"Lip": {
"mid": "/m/06pj2k",
"description": "Lip",
"score": 0.97003114,
"topicality": 0.97003114
}
}
The Context API Response tab includes an array of labels, where each label is represented by a JSON object that contains the following information:
Property | Description |
---|---|
mid | The mid stands for "machine identifier". When the response returns a mid parameter in the response, that corresponds to the knowledge graph mid associated with the label. This parameter can be used to retrieve additional information about the label from the knowledge graph, such as its description, properties, and relationships to other entities. |
description | A string value that represents the name of the label detected in the image. |
score | A float value between 0 and 1 represents the level of confidence that the label is present in the image. |
topicality | A float value between 0 and 1 represents the level of relevance of the label to the image. |
Overall, the Context API Response
provides information about the labels detected in the image, along with their confidence level, relevance, and associated properties. This information can be used for tasks such as image classification, object recognition, and content moderation.
To learn more about this transformation, click here.