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);
}
})();
Set a seed for reproducibility. Random by default.
Number of steps. 6 steps gives good results, but try increasing to 15 or 20 if you need more detail
Use a prompt that describe the image when the material is applied
Max width of the output image
Max height of the output image
An enumeration.
Allowed values:
Subject image to transfer the material to
Guidance scale for the diffusion process
min : 1,
max : 10
Material to transfer to the input image
Quality of the output images, from 0 to 100. 100 is best quality, 0 is lowest quality.
min : 0,
max : 100
What you do not want to see in the image
An enumeration.
Allowed values:
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 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.
Under the hood of Material Transfer is a combination of IP Adapter + ControlNet Depth + Inpainting.
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.
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.
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.
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.
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.
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.”
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.