Skip to main content

Detect whether an object in an image is centered

Detect Center transformation allows users to detect whether or not an object in an image is in the center.

This transformation supports png, jpeg, jpg, webp, cr2, nef, rw2, dng, orf, raw, heic, heif, avif, tiff and tif type of files.

The result of Detect Center is a JSON, as shown below:


{
{
"data": {
"output": {
"is_center": false,
"distance_x_px": 83,
"distance_y_px": 19,
"distance_x_perc": 25,
"distance_y_perc": 7,
"original_input_size": "(512, 640, 3)"
}
},
"name": "detect",
"params": {
"dist_perc": "10"
}
}
}

The JSON keys are explained in the below table:

PropertyDescription
is_centerThe boolean value specifies whether or not an image object is in the center. If the value is true, the image's object is in the center; if the value is false, the image's object is not in the center.
distance_x_pxThe distance in pixels between the y-axes drawn from the image's center and the object's center.
distance_y_pxThe distance in pixels between the x-axes drawn from the image's center and the object's center.
distance_x_percThe distance_x_px expressed in percentage is calculated after dividing an image's width in half.
distance_y_percThe distance_y_px expressed in percentage is calculated after dividing an image's height in half.
original_input_sizeA dimension of the input image (height, width, and channel).
note

Instead of getting the output in a traditional CDN URL, you will find the JSON output from the Context API while the CDN URL will return the original image without any modifications.

The Context API Response (dist_perc=10 (default)) tab consists of a JSON response that has an is_center property false, which states that the object in the image is not in the center. As shown in the below image, point "A" is the center of the image, and point "B" is the center of the object. The distance_x_px is 31 px, and the distance_x_perc is 9.538%, which is calculated after dividing an image's width in half. The distance_y_px is 32 px, and the distance_y_perc is 18.285%, which is calculated after dividing an image's height in half. In this case, the center of the object is 9.538% (31 px) to the right and 18.285% (32 px) to the top. The dist_perc is 10%, indicating that the object is centered as long as its center does not deviate above 10% from the center of the image.

The horizontal (x) deviation is 9.538% to the right, which is less than the dist_perc of 10%, while the vertical (y) deviation is 18.285% to the right, which is greater than the dist_perc of 10%. Since neither of the percentage values is greater than 18.285%, the is_center property has returned false.

To make the is_center property true in the above image, increase the dist_perc amount above 18.285%.

The Context API Response (dist_perc=20) tab contains a JSON response that is obtained when the dist_perc parameter is set to 20%. In this case, the is_center property is returned as true in the JSON.

Transform and enhance your images using our powerful AI technology. Organize your images in more efficient manner and our extensible APIs enables seamless integration with your system unleashing the power of our platform. Join the large community of users who use PixelBin to transform their image libraries and achieve excellent performance

Is this page useful?