이미지 배경 바꾸기

이 페이지에서는 이미지의 배경을 바꾸는 방법을 설명합니다. Vertex AI 기반 Imagen을 사용하면 자동 객체 세분화를 사용하여 다른 이미지 콘텐츠를 수정하는 동안 해당 콘텐츠를 유지할 수 있습니다. 또한 Imagen 3을 사용하면 수정 시 추가 제어를 위해 자체 마스크 영역을 제공할 수 있습니다.

수정 및 맞춤설정을 위한 Imagen 모델 카드 보기

제품 이미지 수정 예시

다음 사용 사례는 이미지의 배경을 수정하되 이미지 내 제품의 모양은 보존하여 제품 이미지를 개선하는 방법을 보여줍니다.

콘솔에서 생성된 샘플 이미지
프롬프트에서 Imagen 제품 이미지 수정 특성으로 생성된 이미지: 부티크 매장의 테이블. 원본 이미지 출처: Unsplash이레네 크레데네츠

시작하기 전에

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. Enable the Vertex AI API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Verify that billing is enabled for your Google Cloud project.

  7. Enable the Vertex AI API.

    Enable the API

  8. 환경에 대한 인증을 설정하세요.

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    Python

    로컬 개발 환경에서 이 페이지의 Python 샘플을 사용하려면 gcloud CLI를 설치하고 초기화한 후 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

      If you're using a local shell, then create local authentication credentials for your user account:

      gcloud auth application-default login

      You don't need to do this if you're using Cloud Shell.

      If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.

    자세한 내용은 Google Cloud 인증 문서의 로컬 개발 환경의 ADC 설정을 참조하세요.

    REST

    로컬 개발 환경에서 이 페이지의 REST API 샘플을 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.

      Google Cloud CLI를 설치합니다.

      외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

    자세한 내용은 Google Cloud 인증 문서의 REST 사용을 위한 인증을 참조하세요.

    자동으로 감지된 배경 마스크로 수정

    Imagen을 사용하면 자동 배경 감지를 통해 제품 이미지를 수정할 수 있습니다. 제품 이미지의 배경을 수정하되 제품의 모양은 보존해야 하는 경우에 유용합니다. 제품 이미지 수정은 Google Product Studio (GPS) 제품을 사용합니다. 콘솔 또는 API를 사용하여 GPS 기능을 Imagen의 일부로 사용할 수 있습니다.

    콘솔에서 생성된 샘플 이미지
    프롬프트에서 Imagen 제품 이미지 수정 특성으로 생성된 이미지: 부티크 매장의 테이블. 원본 이미지 출처: Unsplash이레네 크레데네츠

    다음 안내에 따라 자동 배경 감지를 이용해서 제품 이미지 수정을 사용 설정하고 사용합니다.

    Imagen 3

    다음 샘플을 사용하여 Imagen 3 모델을 사용한 제품 이미지 수정 요청을 전송합니다.

    콘솔

    1. Google Cloud 콘솔에서 Vertex AI > Media Studio 페이지로 이동합니다.

      Media Studio로 이동

    2. 업로드를 클릭합니다. 표시된 파일 대화상자에서 업로드할 파일을 선택합니다.
    3. 인페인트를 클릭합니다.
    4. 파라미터 패널에서 제품 배경을 클릭합니다.
    5. 수정 툴바에서 background_replace 추출을 클릭합니다.
    6. 마스크 추출 옵션 중 하나를 선택합니다.

      • 백그라운드 요소: 백그라운드 요소를 감지하고 요소 주위에 마스크를 만듭니다.
      • 포그라운드 요소: 포그라운드 객체를 감지하고 객체 주위에 마스크를 만듭니다.
      • background_replace 사람: 사람을 감지하고 사람 주위에 마스크를 만듭니다.
    7. 선택사항: 매개변수 측면 패널에서 다음 옵션을 조정합니다.
      • 모델: 사용할 Imagen 모델
      • 결과 수: 생성할 결과 수
      • 부정 프롬프트: 생성하지 말아야 할 항목
    8. 프롬프트 필드에 프롬프트를 입력하여 이미지를 수정합니다.
    9. send 생성을 클릭합니다.

    Python

    설치

    pip install --upgrade google-genai

    자세한 내용은 SDK 참고 문서를 참조하세요.

    Vertex AI에서 Gen AI SDK를 사용하도록 환경 변수를 설정합니다.

    # Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
    # with appropriate values for your project.
    export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
    export GOOGLE_CLOUD_LOCATION=us-central1
    export GOOGLE_GENAI_USE_VERTEXAI=True

    from google import genai
    from google.genai.types import (
        RawReferenceImage,
        MaskReferenceImage,
        MaskReferenceConfig,
        EditImageConfig,
    )
    
    client = genai.Client()
    
    # TODO(developer): Update and un-comment below line
    # output_file = "output-image.png"
    
    raw_ref = RawReferenceImage(
        reference_image=Image.from_file(location="test_resources/suitcase.png"),
        reference_id=0,
    )
    mask_ref = MaskReferenceImage(
        reference_id=1,
        reference_image=None,
        config=MaskReferenceConfig(
            mask_mode="MASK_MODE_BACKGROUND",
        ),
    )
    
    image = client.models.edit_image(
        model="imagen-3.0-capability-001",
        prompt="A light blue suitcase in front of a window in an airport",
        reference_images=[raw_ref, mask_ref],
        config=EditImageConfig(
            edit_mode="EDIT_MODE_BGSWAP",
        ),
    )
    
    image.generated_images[0].image.save(output_file)
    
    print(f"Created output image using {len(image.generated_images[0].image.image_bytes)} bytes")
    # Example response:
    # Created output image using 1234567 bytes
    

    REST

    자세한 내용은 이미지 수정 API 참조를 확인하세요.

    요청 데이터를 사용하기 전에 다음을 바꿉니다.

    • PROJECT_ID: Google Cloud 프로젝트 ID
    • LOCATION: 프로젝트의 리전. 예를 들면 us-central1, europe-west2, asia-northeast3입니다. 사용 가능한 리전 목록은 Vertex AI의 생성형 AI 위치를 참조하세요.
    • TEXT_PROMPT: 모델이 생성하는 이미지를 안내하는 텍스트 프롬프트. 이 필드는 생성 및 수정 모두에서 필요합니다.
    • referenceType: ReferenceImage는 이미지 수정을 위한 추가 컨텍스트를 제공하는 이미지입니다. 사용 사례 수정에는 일반 RGB 원시 참고 이미지(REFERENCE_TYPE_RAW)가 필요합니다. 한 요청에 최대 1개의 원시 참고 이미지가 있을 수 있습니다. 출력 이미지의 높이와 너비는 원시 참고 이미지와 같습니다. 마스크 수정 사용 사례에는 마스크 참고 이미지(REFERENCE_TYPE_MASK)가 필요합니다.
    • referenceId: 참고 이미지의 정수 ID입니다. 이 예시에서 두 참고 이미지 객체는 유형이 다르므로 고유한 referenceId 값(12)을 갖습니다.
    • B64_BASE_IMAGE: 수정하거나 확대할 기본 이미지. 이미지는 base64 인코딩 바이트 문자열로 지정되어야 합니다. 크기 제한: 10MB.
    • maskImageConfig.maskMode: 마스크 수정을 위한 마스크 모드입니다. MASK_MODE_BACKGROUND는 사용자 제공 마스크 없이 배경을 자동으로 마스킹하기 위해 사용됩니다.
    • MASK_DILATION - 부동 소수점 수. 이 마스크를 확장할 이미지 너비의 비율입니다. 전경 제품을 확장하지 않도록 0.00 값을 사용하는 것이 좋습니다. 최소: 0, 최대: 1. 기본값: 0.03
    • EDIT_STEPS - 정수. 기본 모델의 샘플링 단계 수입니다. 제품 이미지 수정을 위해 75 단계에서 시작합니다.
    • EDIT_IMAGE_COUNT: 수정된 이미지의 수. 허용되는 정수 값: 1~4. 기본값: 4.

    HTTP 메서드 및 URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict

    JSON 요청 본문:

    {
      "instances": [
        {
          "prompt": "TEXT_PROMPT",
          "referenceImages": [
            {
              "referenceType": "REFERENCE_TYPE_RAW",
              "referenceId": 1,
              "referenceImage": {
                "bytesBase64Encoded": "B64_BASE_IMAGE"
              }
            },
            {
              "referenceType": "REFERENCE_TYPE_MASK",
              "referenceId": 2,
              "maskImageConfig": {
                "maskMode": "MASK_MODE_BACKGROUND",
                "dilation": MASK_DILATION
              }
            }
          ]
        }
      ],
      "parameters": {
        "editConfig": {
          "baseSteps": EDIT_STEPS
        },
        "editMode": "EDIT_MODE_BGSWAP",
        "sampleCount": EDIT_IMAGE_COUNT
      }
    }
    

    요청을 보내려면 다음 옵션 중 하나를 선택합니다.

    curl

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict"

    PowerShell

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
    다음은 제품 배경 수정 요청에 대한 샘플 응답입니다. 응답은 생성된 이미지 바이트를 base64로 인코딩한 4개의 예측 객체를 반환합니다.
    {
      "predictions": [
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "mimeType": "image/png",
          "bytesBase64Encoded": "BASE64_IMG_BYTES"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        }
      ]
    }
    

    Imagen 2

    다음 샘플을 사용해서 Imagen 2 또는 Imagen 모델을 사용하여 제품 이미지 수정 요청을 보냅니다.

    콘솔

    1. Google Cloud 콘솔에서 Vertex AI > Media Studio 페이지로 이동합니다.

      Media Studio로 이동

    2. 하단 태스크 패널에서 이미지 수정을 클릭합니다.

    3. 업로드를 클릭하여 로컬에 저장된 수정할 제품 이미지를 선택합니다.

    4. 파라미터 패널에서 제품 스타일 이미지 수정 사용 설정을 선택합니다.

    5. 프롬프트 필드(여기에 프롬프트 작성)에 프롬프트를 입력합니다.

    6. 생성을 클릭합니다.

    Python

    Vertex AI SDK for Python을 설치하거나 업데이트하는 방법은 Vertex AI SDK for Python 설치를 참조하세요. 자세한 내용은 Python API 참고 문서를 참조하세요.

    
    import vertexai
    from vertexai.preview.vision_models import Image, ImageGenerationModel
    
    # TODO(developer): Update and un-comment below lines
    # PROJECT_ID = "your-project-id"
    # input_file = "input-image.png"
    # output_file = "output-image.png"
    # prompt = "" # The text prompt describing what you want to see in the background.
    
    vertexai.init(project=PROJECT_ID, location="us-central1")
    
    model = ImageGenerationModel.from_pretrained("imagegeneration@006")
    base_img = Image.load_from_file(location=input_file)
    
    images = model.edit_image(
        base_image=base_img,
        prompt=prompt,
        edit_mode="product-image",
    )
    
    images[0].save(location=output_file, include_generation_parameters=False)
    
    # Optional. View the edited image in a notebook.
    # images[0].show()
    
    print(f"Created output image using {len(images[0]._image_bytes)} bytes")
    # Example response:
    # Created output image using 1234567 bytes
    

    REST

    imagegeneration 모델 요청에 대한 자세한 내용은 imagegeneration 모델 API 참조를 확인하세요.

    Imagen 2 버전 006 모델(imagegeneration@006)을 사용하여 제품 이미지 수정을 사용 설정하려면 "editConfig": {} 객체에 "editMode": "product-image" 필드를 포함합니다. 이 요청은 항상 이미지 4개를 반환합니다.

    요청 데이터를 사용하기 전에 다음을 바꿉니다.

    • PROJECT_ID: Google Cloud 프로젝트 ID
    • LOCATION: 프로젝트의 리전. 예를 들면 us-central1, europe-west2, asia-northeast3입니다. 사용 가능한 리전 목록은 Vertex AI의 생성형 AI 위치를 참조하세요.
    • TEXT_PROMPT: 모델이 생성하는 이미지를 안내하는 텍스트 프롬프트. 이 필드는 생성 및 수정 모두에서 필요합니다.
    • B64_BASE_IMAGE: 수정하거나 확대할 기본 이미지. 이미지는 base64 인코딩 바이트 문자열로 지정되어야 합니다. 크기 제한: 10MB.
    • PRODUCT_POSITION: (선택사항) 감지된 제품 또는 객체의 원래 위치를 유지하거나 모델 위치를 변경할 수 있게 해주는 설정입니다. 사용 가능한 값으로는 위치 변경을 허용하는 reposition(기본값) 또는 제품 위치를 유지하는 fixed 등이 있습니다. 정사각형이 아닌 입력 이미지의 경우 'fixed'가 설정되어 있더라도 제품 위치 동작은 항상 'reposition'입니다.

    HTTP 메서드 및 URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagegeneration@006:predict

    JSON 요청 본문:

    {
      "instances": [
        {
          "prompt": "TEXT_PROMPT",
          "image": {
              "bytesBase64Encoded": "B64_BASE_IMAGE"
          },
        }
      ],
      "parameters": {
        "editConfig": {
          "editMode": "product-image",
          "productPosition": "PRODUCT_POSITION",
        }
      }
    }
    
    

    요청을 보내려면 다음 옵션 중 하나를 선택합니다.

    curl

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagegeneration@006:predict"

    PowerShell

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagegeneration@006:predict" | Select-Object -Expand Content
    다음은 제품 배경 수정 요청에 대한 샘플 응답입니다. 응답은 생성된 이미지 바이트를 base64로 인코딩한 4개의 예측 객체를 반환합니다.
    {
      "predictions": [
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "mimeType": "image/png",
          "bytesBase64Encoded": "BASE64_IMG_BYTES"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        }
      ]
    }
    

    정의된 마스크 영역으로 수정

    Imagen이 마스크를 자동으로 감지하도록 하는 대신 대체된 영역을 마스크 처리할 수 있습니다.

    콘솔

    1. Google Cloud 콘솔에서 Vertex AI > Media Studio 페이지로 이동합니다.

      Media Studio로 이동

    2. 업로드를 클릭합니다. 표시된 파일 대화상자에서 업로드할 파일을 선택합니다.
    3. 인페인트를 클릭합니다.
    4. 파라미터 패널에서 제품 배경을 클릭합니다.
    5. 다음 중 하나를 수행합니다.

      • 자체 마스크를 업로드합니다
        1. 컴퓨터에서 마스크를 만듭니다.
        2. 마스크 업로드를 클릭합니다. 표시된 대화상자에서 업로드할 마스크를 선택합니다.
      • 자체 마스크를 정의합니다. 수정 툴바에서 마스크 도구(상자, 브러시 또는 masked_transitions 반전 도구)를 사용하여 콘텐츠를 추가할 영역을 지정합니다.
    6. 선택사항: 파라미터 패널에서 다음 옵션을 조정합니다.
      • 모델: 사용할 Imagen 모델
      • 결과 수: 생성할 결과 수
      • 부정 프롬프트: 생성하지 말아야 할 항목
    7. 프롬프트 필드에 프롬프트를 입력하여 이미지를 수정합니다.
    8. 생성을 클릭합니다.

    Python

    설치

    pip install --upgrade google-genai

    자세한 내용은 SDK 참고 문서를 참조하세요.

    Vertex AI에서 Gen AI SDK를 사용하도록 환경 변수를 설정합니다.

    # Replace the `GOOGLE_CLOUD_PROJECT` and `GOOGLE_CLOUD_LOCATION` values
    # with appropriate values for your project.
    export GOOGLE_CLOUD_PROJECT=GOOGLE_CLOUD_PROJECT
    export GOOGLE_CLOUD_LOCATION=us-central1
    export GOOGLE_GENAI_USE_VERTEXAI=True

    from google import genai
    from google.genai.types import (
        RawReferenceImage,
        MaskReferenceImage,
        MaskReferenceConfig,
        EditImageConfig,
    )
    
    client = genai.Client()
    
    # TODO(developer): Update and un-comment below line
    # output_file = "output-image.png"
    
    raw_ref = RawReferenceImage(
        reference_image=Image.from_file(location="test_resources/suitcase.png"),
        reference_id=0,
    )
    mask_ref = MaskReferenceImage(
        reference_id=1,
        reference_image=Image.from_file(location="test_resources/suitcase_mask.png"),
        config=MaskReferenceConfig(
            mask_mode="MASK_MODE_USER_PROVIDED",
            mask_dilation=0.0,
        ),
    )
    
    image = client.models.edit_image(
        model="imagen-3.0-capability-001",
        prompt="A light blue suitcase in an airport",
        reference_images=[raw_ref, mask_ref],
        config=EditImageConfig(
            edit_mode="EDIT_MODE_BGSWAP",
        ),
    )
    
    image.generated_images[0].image.save(output_file)
    
    print(f"Created output image using {len(image.generated_images[0].image.image_bytes)} bytes")
    # Example response:
    # Created output image using 1234567 bytes
    

    REST

    자세한 내용은 이미지 수정 API 참조를 확인하세요.

    요청 데이터를 사용하기 전에 다음을 바꿉니다.

    • PROJECT_ID: Google Cloud 프로젝트 ID
    • LOCATION: 프로젝트의 리전. 예를 들면 us-central1, europe-west2, asia-northeast3입니다. 사용 가능한 리전 목록은 Vertex AI의 생성형 AI 위치를 참조하세요.
    • TEXT_PROMPT: 모델이 생성하는 이미지를 안내하는 텍스트 프롬프트. 이 필드는 생성 및 수정 모두에서 필요합니다.
    • referenceId: 참고 이미지의 정수 ID입니다. 이 예시에서 두 참고 이미지 객체는 유형이 다르므로 고유한 referenceId 값(12)을 갖습니다.
    • B64_BASE_IMAGE: 수정하거나 확대할 기본 이미지. 이미지는 base64 인코딩 바이트 문자열로 지정되어야 합니다. 크기 제한: 10MB.
    • B64_MASK_IMAGE: 원본 이미지를 수정하기 위해 마스크 레이어로 사용할 흑백 이미지. 이미지는 base64 인코딩 바이트 문자열로 지정되어야 합니다. 크기 제한: 10MB.
    • MASK_DILATION - 부동 소수점 수. 이 마스크를 확장할 이미지 너비의 비율입니다. 전경 제품을 확장하지 않도록 0.00 값을 사용하는 것이 좋습니다. 최소: 0, 최대: 1. 기본값: 0.03
    • EDIT_STEPS - 정수. 기본 모델의 샘플링 단계 수입니다. 제품 이미지 수정을 위해 75 단계에서 시작합니다.
    • EDIT_IMAGE_COUNT: 수정된 이미지의 수. 허용되는 정수 값: 1~4. 기본값: 4.

    HTTP 메서드 및 URL:

    POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict

    JSON 요청 본문:

    {
      "instances": [
        {
          "prompt": "TEXT_PROMPT": [
            {
              "referenceType": "REFERENCE_TYPE_RAW",
              "referenceId": 1,
              "referenceImage": {
                "bytesBase64Encoded": "B64_BASE_IMAGE"
              }
            },
            {
              "referenceType": "REFERENCE_TYPE_MASK",
              "referenceId": 2,
              "referenceImage": {
                "bytesBase64Encoded": "B64_MASK_IMAGE"
              },
              "maskImageConfig": {
                "maskMode": "MASK_MODE_USER_PROVIDED",
                "dilation": MASK_DILATION
              }
            }
          ]
        }
      ],
      "parameters": {
        "editConfig": {
          "baseSteps": EDIT_STEPS
        },
        "editMode": "EDIT_MODE_BGSWAP",
        "sampleCount": EDIT_IMAGE_COUNT
      }
    }
    

    요청을 보내려면 다음 옵션 중 하나를 선택합니다.

    curl

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    curl -X POST \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    -d @request.json \
    "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict"

    PowerShell

    요청 본문을 request.json 파일에 저장하고 다음 명령어를 실행합니다.

    $cred = gcloud auth print-access-token
    $headers = @{ "Authorization" = "Bearer $cred" }

    Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagen-3.0-capability-001:predict" | Select-Object -Expand Content
    다음은 제품 배경 수정 요청에 대한 샘플 응답입니다.
    {
      "predictions": [
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "mimeType": "image/png",
          "bytesBase64Encoded": "BASE64_IMG_BYTES"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        },
        {
          "bytesBase64Encoded": "BASE64_IMG_BYTES",
          "mimeType": "image/png"
        }
      ]
    }
    

    제한사항

    마스크가 불완전한 경우가 있으므로 경계에서 매우 작은 비트가 누락되면 모델이 전경 객체를 완성하려고 할 수 있습니다. 드물게 발생하는 부작용으로, 포그라운드 객체가 이미 완료된 경우 모델에서 약간의 확장 영역을 만들 수 있습니다.

    해결 방법은 모델 출력을 세그먼트화한 후 혼합하는 것입니다. 다음은 해결 방법을 보여주는 Python 스니펫의 예입니다.

    blended = Image.composite(out_images[0].resize(image_expanded.size), image_expanded, mask_expanded)
    

    다음 단계

    Imagen 및 Vertex AI의 기타 생성형 AI 제품 관련 문서 읽기: