Categories: Blog

How to Insert Images into Google Colab Notebooks (Upload, Display, and Inline Methods)

Google Colab is awesome. It runs in your browser. It feels like magic. And yes, you can work with images inside it very easily. If you have ever wondered how to upload, display, or insert images into your notebook, this guide will make it simple and fun.

TLDR: You can insert images into Google Colab in three main ways: upload from your computer, use images from Google Drive, or display images from a URL. The most common method uses Python libraries like IPython.display, matplotlib, or PIL. Uploading is easy with a built-in file upload tool. Once the image is in your environment, you can display it inline in just a few lines of code.

Let’s break it down step by step.

Method 1: Upload an Image from Your Computer

This is the simplest way to get started. You have an image on your laptop. You want it inside Colab. Done in seconds.

Colab has a built-in upload tool. You can use it with this code:

from google.colab import files
uploaded = files.upload()

When you run this cell, a file picker pops up. Choose your image. That’s it. Your file is now inside the session.

Important: Colab sessions are temporary. If you restart the runtime, your uploaded files disappear. So keep that in mind.

After uploading, you can display the image.

Display with IPython.display

This is one of the easiest display methods:

from IPython.display import Image
from IPython.display import display

display(Image('your_image_name.jpg'))

Replace the file name with yours. The image will appear directly below the code cell. Nice and clean.

Image not found in postmeta

Method 2: Display Images Using Matplotlib

If you are doing data science or machine learning, you will love this method. It gives more control. You can resize. Add titles. Hide axes. Customize everything.

First, install and import the needed libraries. Usually, they are already available in Colab:

import matplotlib.pyplot as plt
import matplotlib.image as mpimg

Now load and show the image:

img = mpimg.imread('your_image_name.jpg')
plt.imshow(img)
plt.axis('off')
plt.show()

Let’s break that down:

  • imread() loads the image.
  • imshow() displays it.
  • axis(‘off’) removes the axis lines.
  • show() renders the image.

Simple. But powerful.

You can also add a title:

plt.title('My Awesome Image')

This is great when presenting results.

Method 3: Using PIL (Python Imaging Library)

PIL is another easy option. In modern Python, you usually use Pillow, which is the updated version of PIL.

Here’s how:

from PIL import Image
import matplotlib.pyplot as plt

img = Image.open('your_image_name.jpg')
plt.imshow(img)
plt.axis('off')

Why use PIL?

  • You can resize images easily.
  • You can crop them.
  • You can convert formats.
  • You can manipulate pixels.

For example, resizing:

img_resized = img.resize((200, 200))
plt.imshow(img_resized)
plt.axis('off')

Very handy for machine learning preprocessing.

Method 4: Insert Images from Google Drive

What if your image is not on your computer, but in Google Drive?

No problem.

First, mount your Drive:

from google.colab import drive
drive.mount('/content/drive')

You will see a link. Click it. Authorize. Paste the code back. Done.

Your files are now accessible like normal folders.

Example path:

/content/drive/MyDrive/images/photo.jpg

Now display it using any method from above. For example:

display(Image('/content/drive/MyDrive/images/photo.jpg'))

This method is great for:

  • Large datasets
  • Projects you revisit often
  • Team collaboration
Image not found in postmeta

Method 5: Display an Image from a URL

You do not even need to upload files. You can display images directly from the internet.

Here’s how:

import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt

url = "https://example.com/image.jpg"
response = requests.get(url)
img = Image.open(BytesIO(response.content))

plt.imshow(img)
plt.axis('off')

This is perfect when:

  • Working with web data
  • Testing quickly
  • Building web scraping projects

Just make sure the URL is public and accessible.

Inline Images in Markdown Cells

So far, we displayed images using Python code. But what about documentation?

Colab supports Markdown cells. You can embed images inside them.

Click + Text to add a Markdown cell. Then use:

![Alt Text](image_url)

Example:

![Cat](https://example.com/cat.jpg)

The image will appear inline. Clean. Beautiful. Great for reports.

You can also resize using basic HTML inside Markdown:

<img src="image_url" width="300">

This gives you more control over size.

Image not found in postmeta

Common Problems and Quick Fixes

Sometimes things do not work. Don’t panic. Here are quick fixes.

Problem 1: File Not Found Error

  • Check spelling.
  • Check file extension.
  • Use !ls to list files in the directory.
!ls

Problem 2: Image Not Displaying

  • Make sure plt.show() is called.
  • Check if the image loaded correctly.
  • Print the image object to debug.

Problem 3: Drive Not Mounting

  • Re-run the mount cell.
  • Restart runtime if needed.
  • Make sure you completed authorization.

Best Practices for Working with Images in Colab

Here are some tips to make your life easier:

  • Keep images organized in folders.
  • Rename files with simple names.
  • Use Google Drive for long-term projects.
  • Resize large images to save memory.
  • Comment your code so future you understands it.

Also remember: Colab sessions reset. If something is important, store it in Drive.

When to Use Each Method

Here is a quick comparison:

  • Quick testing? Upload from computer.
  • Long project? Use Google Drive.
  • Web data? Load from URL.
  • Fancy visualization? Use Matplotlib.
  • Image processing? Use PIL.
  • Documentation? Use Markdown inline images.

Each method has its moment. Pick what fits your goal.

Final Thoughts

Working with images in Google Colab is not scary. It is actually fun. You upload. You display. You customize. Done.

The key idea is simple:

  • Get the image into the environment.
  • Use a library to display it.
  • Adjust it if needed.

That’s the whole story.

Whether you are building a deep learning model, writing a tutorial, or just experimenting, inserting images into Colab notebooks is easy once you know these tricks.

Now open a notebook. Upload an image. Try each method. Play with resizing. Add titles. Break things. Fix them.

Learning sticks when you experiment.

And remember. In Google Colab, images are just one upload away.

Issabela Garcia

I'm Isabella Garcia, a WordPress developer and plugin expert. Helping others build powerful websites using WordPress tools and plugins is my specialty.

Recent Posts

Quick-Start Guide to Structuring Pages for AEO and Answer Engines

As search evolves beyond traditional keyword matching, websites must now be structured not only for…

4 hours ago

Transforming Construction Estimating with Onscreen Takeoff and AI

Construction estimating used to be slow. Very slow. Plans arrived in thick rolls of paper.…

1 day ago

Hidden 6 Internal Knowledge Base Tools Agencies Use Instead of Notion

Many digital agencies start with Notion as their internal knowledge base, but as teams grow…

2 days ago

Are Vibe Coding Apps Any Good – Our Top Picks

Over the last few years, “vibe coding” apps have emerged as a new category of…

2 days ago

Top Audited No-Logs VPN Services in 2026: Verified Privacy Protection Comparison

As online surveillance becomes more sophisticated and governments introduce stricter data retention laws, privacy-conscious users…

3 days ago

5 VPNs That Work With Netflix in 2026: Reliable Streaming VPNs You Can Trust

Streaming Netflix reliably across borders has remained a challenge as the platform continues to improve…

3 days ago