Coding with LLMs


Before starting this lesson, you should be familiar with:

Learning Objectives

After completing this lesson, learners should be able to:
  • Use a large language model (LLM) to create bioimage analysis code

  • Use a LLM to understand bioimage analysis code


Creating and understanding bioimage anlaysis code can be very challenging, especially for coding beginners. Large language models (LLMs) are very useful tools to generate code based on instructions formulated in normal language. Moreover, LLMs can also be asked to explain parts of the code in normal language. Therefore, using LLMs can save a lot of time when creating code for bioimage analysis or other tasks.

Concept map

graph TD P("Prompt") --> LLM("Large language model (LLM)") LLM --> C("Code")


The figure was created by an AI model. It should show how a human asks a computer to create code. This figure couuld be improved... :-)


Create code using a LLM

Ask an LLM to create code that implements a bioimage analysis task.

Activities that could be solved using a LLM:

Tips for creating the prompt:

Fixing errors:

Understanding the code:

Show activity for:  

chatGPT python

  • Go to the openAI chatGPT website:
    • You may have to log in, e.g. using your Google account, but it should be for free.
  • To get started, enter the following prompt: Which programming language and which libraries would you recommend for bioimage analysis?
    • You may get an answer such as: “For bioimage analysis, Python is a popular choice due to its versatility, extensive libraries, and ease of use. Here are some recommended libraries: 1. scikit-image: This library provides a collection of algorithms for image processing. It’s user-friendly and efficient, making it suitable for various tasks in bioimage analysis. 2. OpenCV: OpenCV is a powerful library for computer vision tasks, including image processing and analysis. It offers a wide range of functionalities for tasks such as image segmentation, feature extraction, and object detection. 3. NumPy: NumPy is essential for scientific computing in Python. It provides support for large, multi-dimensional arrays and matrices, along with a collection of mathematical functions to operate on these arrays efficiently…”.
    • Check whether your answer differs from this, also compare what other course participants got.
  • Now ask it to create some code: Write python code that opens and displays the image at
    • Depending on the python environment that you are working with you may need to specify which library to use to open the image also how to display it.
  • Continue by asking it to write code for more complex image analysis workflows as are suggested in the activity preface.


True or false

  1. If you ask a large language model to generate code for you it will reprodcibly give you the exact same answer.
  2. The code that is produced by a large language model can be used to do reproducible science.


  1. This is generally wrong; several common models have some randomicity in their outputs.
  2. This is true; you just have to store code once it has been generated, e.g. using version control systems such as git.


Follow-up material

Recommended follow-up modules:

Learn more: