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

