|
| 1 | +--- |
| 2 | +hidden: true |
| 3 | +noIndex: true |
| 4 | +--- |
| 5 | + |
| 6 | +# magic/image-to-3d |
| 7 | + |
| 8 | +{% columns %} |
| 9 | +{% column width="66.66666666666666%" %} |
| 10 | +{% hint style="info" %} |
| 11 | +This documentation is valid for the following list of our models: |
| 12 | + |
| 13 | +* `magic/image-to-3d` |
| 14 | +{% endhint %} |
| 15 | +{% endcolumn %} |
| 16 | + |
| 17 | +{% column width="33.33333333333334%" %} |
| 18 | +<a href="https://aimlapi.com/app/magic/image-to-3d" class="button primary">Try in Playground</a> |
| 19 | +{% endcolumn %} |
| 20 | +{% endcolumns %} |
| 21 | + |
| 22 | +## Model Overview |
| 23 | + |
| 24 | +The model creates a 3D mesh from images of an object captured from multiple viewpoints (1 to 4 images). |
| 25 | + |
| 26 | +## Setup your API Key |
| 27 | + |
| 28 | +If you don’t have an API key for the AI/ML API yet, feel free to use our [Quickstart guide](https://docs.aimlapi.com/quickstart/setting-up). |
| 29 | + |
| 30 | +## API Schema |
| 31 | + |
| 32 | +{% openapi-operation spec="image-to-3d" path="/v1/images/generations" method="post" %} |
| 33 | +[OpenAPI image-to-3d](https://raw.githubusercontent.com/aimlapi/api-docs/refs/heads/main/docs/api-references/3d-generating-models/magic/image-to-3d.json) |
| 34 | +{% endopenapi-operation %} |
| 35 | + |
| 36 | +## Example |
| 37 | + |
| 38 | +{% tabs %} |
| 39 | +{% tab title="Python" %} |
| 40 | +{% code overflow="wrap" %} |
| 41 | +```python |
| 42 | +import requests |
| 43 | + |
| 44 | + |
| 45 | +def main(): |
| 46 | + response = requests.post( |
| 47 | + "https://api.aimlapi.com/v1/images/generations", |
| 48 | + headers={ |
| 49 | + # Insert your AIML API Key instead of <YOUR_AIMLAPI_KEY>: |
| 50 | + "Authorization": "Bearer <YOUR_AIMLAPI_KEY>", |
| 51 | + "Content-Type": "application/json", |
| 52 | + }, |
| 53 | + json={ |
| 54 | + "model": "magic/image-to-3d", |
| 55 | + "front_image_url": "https://upload.wikimedia.org/wikipedia/commons/thumb/2/22/Fly_Agaric_mushroom_05.jpg/576px-Fly_Agaric_mushroom_05.jpg", |
| 56 | + }, |
| 57 | + ) |
| 58 | + |
| 59 | + response.raise_for_status() |
| 60 | + data = response.json() |
| 61 | + url = data["model_mesh"]["url"] |
| 62 | + file_name = data["model_mesh"]["file_name"] |
| 63 | + |
| 64 | + mesh_response = requests.get(url, stream=True) |
| 65 | + |
| 66 | + with open(file_name, "wb") as file: |
| 67 | + for chunk in mesh_response.iter_content(chunk_size=8192): |
| 68 | + file.write(chunk) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + main() |
| 73 | +``` |
| 74 | +{% endcode %} |
| 75 | +{% endtab %} |
| 76 | + |
| 77 | +{% tab title="JavaScript" %} |
| 78 | + |
| 79 | +{% endtab %} |
| 80 | +{% endtabs %} |
| 81 | + |
| 82 | +**Response**: |
| 83 | + |
| 84 | +The example returns a textured 3D mesh in GLB file format. You can view it [here](https://drive.google.com/file/d/1pfA6PGgDY31rEGcoea7qoZW6uhhPYSE6/view?usp=sharing). |
| 85 | + |
| 86 | +For clarity, we took several screenshots of our mushroom from different angles in an online GLB viewer. As you can see, the model understands the shape, but preserving the pattern on the back side (which was not visible on the reference image) could be improved: |
| 87 | + |
| 88 | +<table data-header-hidden><thead><tr><th valign="top"></th><th></th><th></th></tr></thead><tbody><tr><td valign="top"><img src="../../../.gitbook/assets/image (5).png" alt="" data-size="original"></td><td><img src="../../../.gitbook/assets/image (9).png" alt="" data-size="original"></td><td><img src="../../../.gitbook/assets/image (7).png" alt="" data-size="original"></td></tr></tbody></table> |
| 89 | + |
| 90 | +Compare them with the [reference image](https://upload.wikimedia.org/wikipedia/commons/thumb/2/22/Fly_Agaric_mushroom_05.jpg/576px-Fly_Agaric_mushroom_05.jpg): |
| 91 | + |
| 92 | +<table data-header-hidden><thead><tr><th width="279"></th><th data-hidden></th><th data-hidden></th></tr></thead><tbody><tr><td><img src="../../../.gitbook/assets/576px-Fly_Agaric_mushroom_05 (1).jpg" alt="" data-size="original"></td><td></td><td></td></tr></tbody></table> |
| 93 | + |
| 94 | +{% hint style="info" %} |
| 95 | +Try to choose reference images where the target object is not obstructed by other objects and does not blend into the background. Depending on the complexity of the object, you may need to experiment with the resolution of the reference image to achieve a satisfactory mesh. |
| 96 | +{% endhint %} |
0 commit comments