C++CodeDelphiLearn PythonPython GUIRAD Studio

Easily Perform Powerful Computer Vision Functions In Python GUI App With Mahotas Library

Do you want to perform some Image Processing tasks in your Delphi GUI App? This post will get to understand how to use Mahotas Python Library using Python4Delphi in Delphi/C++ application. Mahotas is a computer vision and image processing library for Python.

Mahotas contains traditional image processing functions such as filtering and morphological operations as well as more modern computer vision functions for feature computation, including interest point detection and local descriptors.

Python for Delphi (P4D) is a set of free components that wrap up the Python DLL into Delphi. They let you easily execute Python scripts, create new Python modules and new Python types. You can use Python4Delphi a number of different ways such as:

  • Create a Windows GUI around your existing Python app.
  • Add Python scripting to your Delphi Windows apps.
  • Add parallel processing to your Python apps through Delphi threads.
  • Enhance your speed-sensitive Python apps with functions from Delphi for more speed.


  • If not python and Python4Delphi is not installed on your machine, Check this how to run a simple python script in Delphi application using Python4Delphi sample app
  • Open windows open command prompt, and type pip install -U mahotas to install Mahotas. For more info for Installing Python Modules check here
  • First, run the Demo1 project for executing Python script in Python for Delphi. Then load the Texblob sample script in the Memo1 field and press the Execute Script button to see the result. On Clicking Execute Button the script strings are executed using the below code. Go to GitHub to download the Demo1 source.

Mahotas Python Library sample script details:

  • How to label a region in an image. Labeled images are integer images where the values correspond to different regions. I.e., region 1 is all of the pixels which have value 1, region two is the pixels with value 2, and so on. By convention, region 0 is the background and often handled differently.
  • Thresholding is a type of image segmentation, where we change the pixels of an image to make the image easier to analyze. In thresholding, we convert an image from color or grayscale into a binary image, i.e., one that is simply black and white. A well-known thresholding method is Otsu’s method which is demonstrated below.
  • Color space conversion is the translation of the representation of a color from one basis to another. An RGB image is represented as a 3-dimensional array of shape (h,w,3), where each pixel is represented by three values, red/green/blue. Image color space conversion using rgb2grey,rgb2sepia method were shown below.
Labeling Images
Thresholding Otsu’s Method
Mahotas Color Space conversions Demo

Note: Samples used for demonstration were picked from here with only the difference of printing the outputs. You can check the APIs and some more samples from the same place.

You have read the quick overview of Mahotas library, download this library from here, and perform image processing fuctions such as watershed, filtering regions, morphological processing, in your applications. Check out Python4Delphi and easily build Python GUIs for Windows using Delphi.

Related posts
DelphiDelphiVCLPythonPython GUIWindows

What Is The DelphiVCL.Application.CreateForm Method?

DelphiDelphiVCLPythonPython GUIWindows

This Is How The OnGetMainFormHandle Event Works

DelphiDelphiVCLPythonPython GUIWindows

What does the OnMessage Event in DelphiVCL.Application do?

Learn PythonPythonPython GUIVideos

Why You Should Debug Your Programs The Easy Way

Leave a Reply

Your email address will not be published.