Blog Post

Microsoft 365 Insider Blog
3 MIN READ

Analyze images with Python in Excel

ndeyanta's avatar
ndeyanta
Icon for Microsoft rankMicrosoft
Aug 13, 2025

Hi, Insiders! I’m Ndeyanta Jallow, a Product Manager on the Excel team. I’m excited to announce a powerful new Python capability in Microsoft Excel for Windows, Excel for Mac, and Excel for the web: images as input.

Analyze images with Python in Excel

Analyzing, manipulating, and gathering important information from images in Excel just became easier and faster! This feature unlocks a whole new class of data analysis workflows: Now you can drop an image into a cell and run Python code on it with no extra tools or steps.

How it works

Let’s work through an example of how to analyze images with Python in Excel. Follow along with the steps outlined below to detect if an image is likely blurry or sharp. The code checks how much detail is in an image by applying a special filter. If there’s not much variation, it means the image is probably blurry; if there’s a lot, it’s likely sharp.

  1. Insert an image into cell A1 by using the =IMAGE() function or selecting Insert > Illustrations > Pictures > Place in Cell, and select an image from your device, from a stock library, or from an online source. Then, select InsertNOTE: To reference the image in Python code, it must be in a single cell and not over cells.
  2. In cell B1, create a Python formula by typing =PY( into the cell. Copy and paste the following code into cell B1 to analyze the image in cell A1

    from PIL import Image 

    import numpy as np 

    from scipy.signal import convolve2d 

    # Convert image to grayscale and array 

    image = xl("A1") 

    arr = np.array(image.convert("L"), dtype=np.float32) 

    # Apply Laplacian filter 

    laplacian = convolve2d(arr, [[0, 1, 0], [1, -4, 1], [0, 1, 0]], mode='same', boundary='symm') 

    # Classify based on variance 

    "Blurry" if np.var(laplacian) < 100 else "Sharp" 

    NOTE: Just like referencing ranges and tables, image is referenced in the code above with the xl() function. You can reference cells with images in Python code by typing xl(“A1”) or selecting the cell that contains the image while in edit mode.
  3. Press Ctrl + Enter to run the code, and then notice that “Sharp” or “Blurry” is displayed in the cell based on the quality of the image analyzed.

Test this out with other images and see the results! 

Tips and tricks

  • Check out our introduction to Python in Excel and get started with Python in Excel articles for more information on how to use Python in Excel.
  • To analyze images with Python, Pillow is currently the most useful library available. It provides efficient tools for opening, processing, and analyzing image data, including pixel-level access, filtering, transformations, and metadata extraction. 
  • To help manage performance and stay within the per-cell data limit, we’ve added a new setting under File > Options > Advanced >When calculating this workbook > Python in Excel. You can choose to adjust your image size to Actual size (default), Large (1280x960), Medium (640x480), or Small (320x240). If you exceed the per-cell data limit, you’ll see a helpful error with guidance on how to adjust your settings.

Scenarios to try

Here are other image analyses you can conduct using Python in Excel:

  • Image manipulation: You can adjust brightness, change color, overlay logos, or watermark product images for brand consistency.
  • Metadata analysis: Try analyzing image metadata and generating plots to explore image structure and composition.

Availability

This feature is available to Excel users who have access to Python in Excel (learn more) and are running: 

  • Windows: Version 2509 (Build 19204.20002) or later.
  • Mac: Version 16.101 (Build 25080524) or later.

It is rolling out to Excel for the web users.

Feedback

Have ideas for how you’d use images in Python in Excel? Want to see more image libraries supported? Let us know in the comments below, or select Help > Feedback in Excel to provide your thoughts and suggestions!

 

Learn about the Microsoft 365 Insider program and sign up for the Microsoft 365 Insider newsletter to get the latest information about Insider features in your inbox once a month!

Updated Aug 14, 2025
Version 2.0