# AI Item Removal Mask

{% hint style="danger" %}
Kindly bear in mind that this feature is currently available. However, to activate it, please reach out to <noshad@aihomedesign.com>.
{% endhint %}

### Overview

The Item Removal Mask service allows users to remove unwanted objects from an image by applying a mask. Users can mask areas of an image and submit it for processing. This document outlines the API endpoints required for fetching the latest masked image, applying manual masks, and submitting the final image.

### Workflow

* Retrieve the latest masked image.
* Apply masking by brushing the image and submitting the masked version.
* Submit the final masked image.
* Retrieve the updated masked image for verification.
* Finalize order

### Front-End Implementation Guide for Item Removal Mask

The front-end implementation involves using a **canvas** to allow users to brush over areas they want to remove. The brushed image must then be sent to the back-end API in the correct format to ensure accurate processing.

{% hint style="success" %}
Check out example code for Front-End Canvas Implementation from [here](https://doc.aihomedesign.com/api-endpoints/code-examples/mask-canvas).
{% endhint %}

1. Image Handling
   1. Load the latest masked image from the [#retrieve-the-latest-masked-image](#retrieve-the-latest-masked-image "mention").
   2. Display the image on an **HTML5 canvas** to allow user interaction.
   3. Ensure that the **size of the canvas matches the original image size** to maintain accurate alignment.
2. Brushing Requirements
   1. Users should be able to **brush over the image** to mark areas for removal.
   2. The **brush color must be `#7878CD`** (a specific shade of blue).
   3. The brushed strokes should be **opaque**, meaning the marked areas will be clearly visible.
3. Exporting the Masked Image
   1. Once the user finishes brushing, generate a **masked image as a PNG file**.
   2. The **PNG must have the exact same dimensions** as the original image to ensure perfect overlap.
   3. Only the brushed areas should be visible on the PNG, with the rest of the image being transparent.
4. Sending the Masked Image to the Back End
   1. Convert the canvas to a **PNG file**.
   2. Send the **masked PNG file** to the API [#submit-the-final-masked-image](#submit-the-final-masked-image "mention").

### **API Endpoints**

### **Retrieve the Latest Masked Image**

***

<mark style="color:green;">**GET**</mark> **`https://api.aihomedesign.com/v1/order/{order_id}/last-temp-image`**

***

Fetches the latest version of the masked image. This allows users to view the most recent changes before making additional edits.

#### **Request Parameters:**

* **`order_id`**: This should match the `order_id` returned by the Image Upload API.

#### Headers

| Key                                         | Value                  |
| ------------------------------------------- | ---------------------- |
| x-api-key<mark style="color:red;">\*</mark> | {your\_api\_key\_here} |

#### Response

{% tabs %}
{% tab title="200: OK " %}

<pre class="language-json"><code class="lang-json"><strong>{
</strong>   "image_id": string,
   "url": string
}
</code></pre>

{% endtab %}

{% tab title="400: Bad Request " %}

```json
{
    "error": string,
    "key": string
}
```

{% endtab %}
{% endtabs %}

### Apply Manual Mask

***

<mark style="color:green;">POST</mark> **`https://api.aihomedesign.com/v1/order/manual-mask`**

***

Uploads a masked image where unwanted items have been selected for removal.&#x20;

#### Request Body

Ensure that your request body is in <mark style="color:red;">**Form Data**</mark> the  format.

```
{
    "mask": binary,
    "order_id": string
}
```

* **`mask`**: This must be the binary file of the masked part
* **`order_id`**: This should match the `order_id` returned by the Image Upload API.

#### Headers

| Key                                         | Value                  |
| ------------------------------------------- | ---------------------- |
| x-api-key<mark style="color:red;">\*</mark> | {your\_api\_key\_here} |

#### **Response**

{% tabs %}
{% tab title="200: OK" %}

```
{
    "maskId": string
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```
{
    "error": string,
    "key": string
}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The `maskId` will be required in future versions. For now, it can be ignored, and only the most recent mask image will be used.
{% endhint %}

#### <mark style="color:red;">Note</mark>

&#x20;When using the Item Removal Mask Tool, please note that after you upload an image, we automatically resize it. This means that the mask image you provide must be in the same dimensions as the resized image, not the original one.\
You can check the correct image size by calling the API endpoint already included in the documentation:\
[https://api.aihomedesign.com/v1/order/{order\_id}/last-temp-image](https://api.aihomedesign.com/v1/order/%7Border_id%7D/last-temp-image)\
Use the dimensions from this image to ensure your mask matches perfectly.

### Submit the Final Masked Image

***

<mark style="color:green;">POST</mark> **`https://api.aihomedesign.com/v1/order`**

***

Submit the final masked image for processing.

#### Request Body

Ensure that your request body is in <mark style="color:red;">**RAW-JSON**</mark> the  format.

```
{
    "order_id": string,
    "service_name": "service-item-removal-mask"
}
```

* **`order_id`**: This should match the `order_id` returned by the Image Upload API.
* **`service_name`**: this value is fixed and must be "service-item-removal-mask"

#### Headers

| Key                                         | Value                  |
| ------------------------------------------- | ---------------------- |
| x-api-key<mark style="color:red;">\*</mark> | {your\_api\_key\_here} |

#### Response

{% tabs %}
{% tab title="200: OK" %}

```
{    
    "order_id": string,
    "image_id": string,
    "eta": integer
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```
{    
    "error": string,
    "key": integer
}
```

{% endtab %}
{% endtabs %}

### Retrieve the Updated Masked Image

***

<mark style="color:green;">**GET**</mark> **`https://api.aihomedesign.com/v1/order/{order_id}/last-temp-image`**

***

Fetches the updated masked image after submission to confirm the final result.

#### **Request Parameter:**

* **`order_id`**: This should match the `order_id` returned by the Image Upload API.

#### Headers

| Key                                         | Value                  |
| ------------------------------------------- | ---------------------- |
| x-api-key<mark style="color:red;">\*</mark> | {your\_api\_key\_here} |

#### Response

{% tabs %}
{% tab title="200: OK" %}

```
{    
    "image_id": string,
    "url": string
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```
{    
    "error": string,
    "key": integer
}
```

{% endtab %}
{% endtabs %}

### Finalize Order

***

<mark style="color:green;">**POST**</mark> [**`https://api.aihomedesign.com/v1/order/done`**](https://api.aihomedesign.com/v1/order/done)

***

Finalize order to save selected result into order

#### **Request Parameter:**

* **`order_id`**: This should match the `order_id` returned by the Image Upload API.
* **`image_id`**: This should match the `image_id` returned by the Last Temp Image API

#### Headers

| Key                                         | Value                  |
| ------------------------------------------- | ---------------------- |
| x-api-key<mark style="color:red;">\*</mark> | {your\_api\_key\_here} |

#### Response

{% tabs %}
{% tab title="200: OK" %}

```
{    
    "message": "order done successfully"
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```
{    
    "error": string,
    "key": integer
}
```

{% endtab %}
{% endtabs %}

###
