POST
javascript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 const axios = require('axios'); const FormData = require('form-data'); const api_key = "YOUR API-KEY"; const url = "https://api.segmind.com/v1/material-transfer"; const reqBody = { "steps": 6, "prompt": "marble sculpture", "max_width": 1920, "max_height": 1920, "output_format": "webp", "subject_image": "https://segmind-sd-models.s3.amazonaws.com/display_images/bird.png", "guidance_scale": 2, "material_image": "https://segmind-sd-models.s3.amazonaws.com/display_images/ruby.png", "output_quality": 80, "material_strength": "medium", "return_intermediate_images": false }; (async function() { try { const formData = new FormData(); // Append regular fields for (const key in reqBody) { if (reqBody.hasOwnProperty(key)) { formData.append(key, reqBody[key]); } } // Convert and append images as Base64 if necessary const response = await axios.post(url, formData, { headers: { 'x-api-key': api_key, ...formData.getHeaders() } }); console.log(response.data); } catch (error) { console.error('Error:', error.response ? error.response.data : error.message); } })();
RESPONSE
image/jpeg
HTTP Response Codes
200 - OKImage Generated
401 - UnauthorizedUser authentication failed
404 - Not FoundThe requested URL does not exist
405 - Method Not AllowedThe requested HTTP method is not allowed
406 - Not AcceptableNot enough credits
500 - Server ErrorServer had some issue with processing

Attributes


seedint ( default: 1 )

Set a seed for reproducibility. Random by default.


stepsint ( default: 6 )

Number of steps. 6 steps gives good results, but try increasing to 15 or 20 if you need more detail


promptstr ( default: marble sculpture )

Use a prompt that describe the image when the material is applied


max_widthint ( default: 1920 )

Max width of the output image


max_heightint ( default: 1920 )

Max height of the output image


output_formatenum:str ( default: webp )

An enumeration.

Allowed values:


subject_imagestr *

Subject image to transfer the material to


guidance_scalefloat ( default: 2 )

Guidance scale for the diffusion process

min : 1,

max : 10


material_imagestr *

Material to transfer to the input image


output_qualityint ( default: 80 )

Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.

min : 0,

max : 100


negative_promptstr ( default: 1 )

What you do not want to see in the image


material_strengthenum:str ( default: medium )

An enumeration.

Allowed values:


return_intermediate_imagesbool ( default: 1 )

Return intermediate images like mask, and annotated images. Useful for debugging.

To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.

Material Transfer

Material Transfer is based on zero-shot material transfer to an object in an input image given a material exemplar image. For example, given a subject image (e.g., a photo of an bird) and a single material example image (e.g., marble), Material transfer model can transfer the marble material from the material image onto the bird.

This process allows for the realistic transfer of material properties from one image to another, even when the two images have different structures and lighting conditions. It’s a powerful tool in image editing.

Key Components of Material Transfer

Under the hood of Material Transfer is a combination of IP Adapter + ControlNet Depth + Inpainting.

  1. An image encoder (IP Adapter) understands unique characteristics of a certain material and captured from a reference image. This image is known as the material image.

  2. ControlNet Depth: In this step, the input image, which is the image onto which the material properties will be transferred, is processed to understand its structure and lighting conditions. The structure is understood by estimating the depth of different parts of the image.

  3. Inpainting: The final step is where the extracted material properties are applied to the input image. This is done in a way that takes into account the structure and lighting conditions of the input image, resulting in a new image where the material properties from the material image have been realistically transferred.

How to use Material Transfer

  1. Subject image: Start by selecting an image that you want to modify. This is the image where the new material will be applied. This should ideally be of a single material type.

  2. Material Image: Next, choose an image that represents the type of material you want to transfer. This could be any material like rock, marble, glass, etc. The properties of this material will be extracted and applied to the input image.

  3. Prompt: provide a text prompt of what you want the final output to look like. For example, if you’re transferring the properties of marble onto an image of a bird, your prompt might be “marble sculpture.”

  4. Material Strength: Adjust this parameter to control the strength of the material transfer. You can choose between ‘strong’ and ‘medium’ options. ‘Strong’ will result in a more pronounced material effect, while ‘medium’ will be more subtle.