liveBook · Manning

Reconstructed image

As explained in Build a Text-to-Image Generator (from Scratch)

A reconstructed image is an image recovered by decoding a compressed or latent representation.

A reconstructed image is produced by decoding a compressed or latent representation back into image space. Unlike an original image, it may lose information while preserving recognizable content. section 9.2.2 section 11.5.1

The process follows a repeatable pipeline: encode an image, compress or quantize its latent representation, decode it, and compare the result with the original. A VAE maps 3 × 512 × 512 images to 4 × 64 × 64 latents before decoding them back to 3 × 512 × 512. VQGAN similarly reconstructs processed 3 × 384 × 384 images, but quantization through a 1,024-vector codebook introduces visible differences. section 9.2.2 section 11.5.1

A reconstruction can be generated in two equivalent VQGAN routes:

  • Decode the quantized latent vectors directly. section 11.5.2
  • Convert 576 integer indices into codebook vectors, reshape them into the quantized latent representation, and decode them. section 11.5.2
  • Compare both outputs visually; the reconstructions are identical when they use the same quantized representation. section 11.5.2

Comparing original and reconstructed images

Process cat.png and fish.png with VQGAN, obtain reconstruct1 and reconstruct2, and display originals beside reconstructions in a four-panel grid. The images remain similar, but lost information is visible. section 11.5.1

Listing 9.4 Comparing the original and reconstructed images
imgs=[image1.permute(1,2,0),
  torch.clip(reconstruct1[0].permute(1,2,0),
    0,1).detach().cpu().numpy(),
    image2.permute(1,2,0),
  torch.clip(reconstruct2[0].permute(1,2,0),
             0,1).detach().cpu().numpy()]    #1
plt.figure(figsize=(12,3),dpi=100)
for i in range(4):    #2
    plt.subplot(1,4, i+1)
    plt.imshow(imgs[i])
    if i%2==0:
        plt.title("original image")
    else:
        plt.title("reconstructed image")    #3
    plt.axis('off')
plt.tight_layout()
plt.show()

Displays original and reconstructed images in alternating panels, making preservation and distortion directly inspectable. section 9.2.2

How Build a Text-to-Image Generator (from Scratch) covers it

How deep it goes
Traces encoding, latent compression, quantization, codebook lookup, decoding, and visual comparison, but does not derive training procedures.
Examples
Compares beaver, dolphin, cat, and fish images alongside their VAE or VQGAN reconstructions.
What it assumes
Assumes familiarity with image tensors and PyTorch while demonstrating preprocessing, latent tensors, codebook indices, and decoder calls.
What you can do after
Apply pretrained VAE or VQGAN encoders and decoders to reconstruct images and inspect outputs with plotted comparisons.
How it connects
Connects image reconstruction with variational autoencoders, latent representations, VQGAN, quantization, codebooks, and image decoders.

Also explained in

Compare how 2 books explain reconstructed image →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Text-to-Image Generator (from Scratch). The section links point to the parts of the book it draws on.