POST/v1/codeformer
1const axios = require('axios');
2
3const fs = require('fs');
4const path = require('path');
5
6async function toB64(imgPath) {
7    const data = fs.readFileSync(path.resolve(imgPath));
8    return Buffer.from(data).toString('base64');
9}
10
11const api_key = "YOUR API-KEY";
12const url = "https://api.segmind.com/v1/codeformer";
13
14const data = {
15  "image": "toB64('https://www.segmind.com/codeformer_input.png')",
16  "scale": 1,
17  "fidelity": 0.5,
18  "bg": true,
19  "face": true
20};
21
22(async function() {
23    try {
24        const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } });
25        console.log(response.data);
26    } catch (error) {
27        console.error('Error:', error.response.data);
28    }
29})();
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
Expand

Attributes


imageimage *

Image to Enhance


scalenumber ( default: 1 )

The final upsampling scale of the image

min : 1,

min : 4


fidelitynumber ( default: 0.5 )

level of fidelity or quality desired for the generated image.

min : 0,

min : 1


bgbool ( default: true )

refers to the enhancement of the background present in the image.


facebool ( default: true )

refers to the enhancement of the face present in the image.

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.

CodeFormer: Revolutionizing Face Restoration with Advanced AI

In the ever-evolving landscape of image enhancement, particularly for facial images, the challenges are vast and varied. Whether it's breathing life into old photographs or refining AI-generated facial images, the task often comes with inherent complexities. CodeFormer emerges as a beacon in this space, an innovative face restoration algorithm birthed at the renowned S-Lab of Nanyang Technological University. Spearheaded by luminaries like Shangchen Zhou, Kelvin C.K., Chan Chongyi Li, and Chen Change Loy, CodeFormer is set to become the gold standard in AI-driven face restoration.

Inside CodeFormer: A Technical Deep Dive

CodeFormer's genius lies in its transformative approach: envisioning face restoration as a code prediction challenge. Harnessing the power of a meticulously learned discrete codebook within a streamlined proxy space, the algorithm dramatically reduces the uncertainties tied to restoration processes. This codebook acts as a treasure trove of visual elements, pivotal for crafting pristine facial images. To decipher these codes, CodeFormer boasts a Transformer-based prediction architecture, masterfully capturing the overarching composition and nuances of degraded facial images. Moreover, to address the spectrum of image impairments, an adaptive controllable feature transformation module has been embedded. This ensures a seamless blend between the authenticity and quality of the rejuvenated image.

Why CodeFormer Stands Out in Face Restoration

CodeFormer's resilience against image degradation is unparalleled in the industry. Owing to its rich codebook reservoir and holistic modeling techniques, it consistently eclipses other leading algorithms, delivering unmatched quality and authenticity. Whether dealing with artificially impaired images or those from real-world scenarios, CodeFormer's results are consistently stellar. Its intrinsic capability to strike a perfect balance between image authenticity and quality further elevates its stature in the face restoration arena.

Codeformer use cases

AI Model Enhancement and Correction:

As advanced as AI-generated imagery has become, it can sometimes produce images with unusual artifacts or inconsistencies, especially in faces. Algorithms designed to restore and enhance photos can be utilized to correct and refine these AI-generated outputs, ensuring a more accurate and polished final product.

Personal and Historical Archiving:

This category focuses on rejuvenating personal memories like family photos and videos. Additionally, museums and institutions can utilize these tools to enhance their historical photos, films, and other visual artifacts, providing a clearer lens into the past.

Media, Entertainment, and Arts:

Old movies, TV shows, and artistic projects can benefit from high-quality restoration, offering audiences a refreshed view of classic content. This is also advantageous for documentaries, allowing seamless integration of vintage footage with newer content.

Research, Education, and Cultural Preservation:

Enhanced clarity in old images and videos can provide historians, researchers, and educators with deeper insights and a more immersive teaching medium. Moreover, cultural artifacts can be preserved with higher fidelity, ensuring longevity and continued relevance.

Industry and Marketing:

Brands, fashion designers, and the real estate sector can revitalize old content for contemporary uses. Whether it's for nostalgic marketing campaigns, drawing inspiration from past styles, or showcasing property transformations, high-quality visuals play a pivotal role.

Licensing and Commercial Use of CodeFormer

For those interested in leveraging CodeFormer for commercial endeavors, it's crucial to note that the algorithm comes with licensing restrictions. Direct commercial use without proper authorization is prohibited. However, for commercial licensing and opportunities, please reach out to us directly. We are more than happy to discuss potential collaborations and ensure that you can harness the full potential of CodeFormer in your ventures.