HSL GUI in Python

I recently wrote a post on RGB/HSL Conversions in Python and as a follow-up I decided to put together a simple Tkinter application which enables users to display a colour by selecting any combination of hue, saturation and lightness.

This application is only a toy but playing with it for a few minutes does give an intuitive understanding of the HSL system, and reinforces my conviction that it is easier to comprehend than RGB. And if you have never used Tkinter this project also provides a simple introduction to the topic.

Continue reading

Normal Distributions in Python

One of the most useful bits of number-crunching you can do is to calculate the probability distribution of a set of data in the earnest hope that it will be a reasonable fit for one of the recognised distributions such as the normal distribution. In this project I will write a Python class to calculate the normal distribution for a given data set.

Continue reading

Speed Experiments in Python

Some time ago I wrote a post on calculating a selection of statistics from a list on numbers. I got some criticism from people saying that for some of the statistics I should have used Python built-in functions or functions from the Python Standard Library statistics module.

Doing so, however, would cause each of those functions to iterate over the entire dataset. If you want to calculate a number of different statistics in one go you can increase efficiency considerably with just one iteration.

I started writing a simple experiment to calculate the minimum, maximum, sum, mean and standard deviation of a list of numbers using Python's own functions, calculating them again using a single loop, and then comparing the performance.

I then decided to expand the experiment somewhat, firstly by running the plain Python code with PyPy instead of CPython, and then re-writing the Python as Cython. This article explores these experiments and presents the results.

Continue reading

Tkinter Pillow Application 0.4

This is Version 0.4 of my Tkinter Pillow Application which adds the following functionality:

  • A dialog box prompting the user to select image quality on saving
  • A prompt to save any changes when an image or the application are closed
  • Buttons in the Resize dialog to calculate the height or width from the other value to maintain the height/width ratio
Continue reading

Tkinter Pillow Application 0.2

This is Version 0.2 of my Tkinter Pillow Application, Version 0.1 being here.

This is an ongoing project to develop an image editing application using Tkinter for the UI (with other GUI toolkits as a long-term objective) and the Pillow library for image editing functionality.

Version 0.1 established the overall architecture of the solution and enabled users to open and display an image. For Version 0.2 I will add a number of essential improvements to the user interface.

Continue reading

Moving Averages in Python

Everyone understands averages, both their meaning and how to calculate them. However, there are situations, particularly when dealing with real-time data, when a conventional average is of little use because it includes old values which are no longer relevant and merely give a misleading impression of the current situation.

The solution to this problem is to use moving averages, ie. the average of the most recent values rather than all values, which is the subject of this post.

Continue reading

Tkinter Pillow Application 0.1

In my post An Introduction to Image Manipulation with Pillow I commented that "You could in principle use it [Pillow] as the basis of a sort of lightweight Photoshop type application using perhaps Tkinter or PyQT". At the time I wasn't actually intending to do so but recently the idea has started to appeal to me so I thought I'd give it a go.

Although I'm not attempting to compete with Photoshop this is still a fairly ambitious project which will spread over a number of posts, and to start with I'll just get something very basic up and running.

Continue reading