Meningkatkan kualitas gambar menggunakan Imagen

Anda dapat menggunakan Imagen di Vertex AI untuk meningkatkan skala gambar, yang akan meningkatkan ukurannya tanpa mengurangi kualitas gambar.

imagen-4.0-upscale-preview mendukung peningkatan kualitas gambar di Pratinjau.

Sebelum memulai

  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.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  4. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

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

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

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

  7. Enable the Vertex AI API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  8. Siapkan autentikasi untuk lingkungan Anda.

    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.

    REST

    Untuk menggunakan contoh REST API di halaman ini dalam lingkungan pengembangan lokal, gunakan kredensial yang Anda berikan ke gcloud CLI.

      Instal Google Cloud CLI. Setelah penginstalan, inisialisasi Google Cloud CLI dengan menjalankan perintah berikut:

      gcloud init

      Jika Anda menggunakan penyedia identitas (IdP) eksternal, Anda harus login ke gcloud CLI dengan identitas gabungan Anda terlebih dahulu.

    Untuk mengetahui informasi selengkapnya, lihat Melakukan autentikasi untuk menggunakan REST dalam dokumentasi autentikasi Google Cloud .

    Meningkatkan skala gambar

    Konsol

    1. Di konsol Google Cloud , buka halaman Vertex AI > Vertex AI Studio > Generate media.

      Buka Buat Media

    2. Klik Imagen. Halaman Media playground akan ditampilkan.

    3. Klik upload gambar, lalu pilih gambar yang akan diupload.

    4. Klik Ekspor gambar, lalu Tingkatkan skala gambar juga.

    5. Pilih faktor penskalaan, lalu klik Ekspor.

    Watermark digital otomatis ditambahkan ke gambar yang di-upgrade. Anda tidak dapat menonaktifkan watermark digital untuk peningkatan skala gambar menggunakan konsol Google Cloud .

    REST

    Sebelum menggunakan salah satu data permintaan, lakukan penggantian berikut:

    • REGION: Region tempat project Anda berada. Untuk mengetahui informasi selengkapnya tentang region yang didukung, lihat Lokasi AI Generatif di Vertex AI.
    • PROJECT_ID: Google Cloud Project ID Anda.
    • BASE64_SUBJECT_IMAGE: Gambar subjek yang dienkode base64.
    • ADD_WATERMARK: Nilai Boolean opsional. Setel ke true untuk mengaktifkan gambar yang memiliki watermark, atau false untuk menonaktifkan gambar yang memiliki watermark. Nilai defaultnya adalah true.
    • GCS_IMAGE_PATH: Jalur Cloud Storage ke file gambar.
    • GCS_OUTPUT_PATH: jalur Cloud Storage untuk menyimpan output yang dihasilkan.
    • OUTPUT_MIMETYPE: String opsional yang menentukan jenis file output gambar. Nilai berikut diterima: "image/png" atau "image/jpeg". Defaultnya adalah "image/png".
    • COMPRESSION_QUALITY: Nilai bilangan bulat opsional yang menentukan tingkat detail yang dipertahankan model untuk gambar JPEG. Rentang nilai berikut diterima: 0 - 100. Nilai yang lebih tinggi menentukan tingkat kompresi yang lebih tinggi. Defaultnya adalah 75.
    • UPSCALE_FACTOR: Faktor penskalaan untuk gambar yang di-upscale. Resolusi output akhir gambar setelah menerapkan faktor peningkatan kualitas tidak boleh melebihi 17 megapiksel. Nilai berikut diterima:
      • "x2"
      • "x3"
      • "x4"

    Metode HTTP dan URL:

    POST https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict

    Meminta isi JSON:

    {
      "instances": [
        {
          "prompt": "Upscale the image",
          "image": {
            // use one of the following to specify the image to upscale
            "bytesBase64Encoded": "BASE64_SUBJECT_IMAGE"
            "gcsUri": "GCS_IMAGE_PATH"
            // end of base image input options
          },
        }
      ],
      "parameters": {
        "mode": "upscale",
        "storageUri": "GCS_OUTPUT_PATH",
        "outputOptions": {
          "mimeType": "OUTPUT_MIMETYPE",
          "compressionQuality": COMPRESSION_QUALITY
        },
        "upscaleConfig": {
          "upscaleFactor": "UPSCALE_FACTOR"
        }
      }
    }
    

    Untuk mengirim permintaan Anda, pilih salah satu opsi berikut:

    curl

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

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

    PowerShell

    Simpan isi permintaan dalam file bernama request.json, dan jalankan perintah berikut:

    $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://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/publishers/google/models/imagen-4.0-upscale-preview:predict" | Select-Object -Expand Content
    Permintaan ini akan menampilkan objek gambar. Dalam contoh ini, objek gambar ditampilkan sebagai objek prediksi dengan gambar berenkode base64.
    {
      "predictions": [
        {
          "mimeType": "image/png",
          "bytesBase64Encoded": "BASE64_IMG_BYTES"
        }
      ]
    }
    
    
    

    Langkah berikutnya

    Baca artikel tentang Imagen dan produk AI Generatif lainnya di Vertex AI: