Centroid Calculator

A Max Westerman Project

Hi! Here's the centroid calculator. See below for info.

LinkedInLinkLink

What does it do?

This Python program will find the center of an object. It will consider the RGB values the user gives as not part of the object and find the center of the rest. This can be useful for finding the center of very complex shapes, such as states, congressional districts, or parts with complex geometry. This can also be used to find the center of mass for physics and engineering.

The calculator will automatically size the centroid dot, text positioning, and text sizing based on the size of the image. If you want to change the default settings, when you run your centroid calculation there's an option to customize these parameters, seen in the F22 custom centroid below.

F22 Raptor Custom Centroid 

The program allows for the following custom settings: circle sizing, text sizing, text offset from the centroid, and text color. This centroid omitted white pixels.

Transparent Example

When you insert a transparent image it will convert all transparent pixels to white, then find the centroid relating to the white pixels given 255,255,255 as inputs.

Centroid of the United States

Calculated the geographic center of mass for the contiguous United States. This matches the center of mass shown on Wikipedia. In this image, the pure black pixels were removed from the calculation.

How to set up

Download the required libraries:

How to use

Run the program and insert the pathname of the image you want the centroid to be calculated from as well as the place you want the file to be saved to. Enter the RGB of the pixels you don't want to be counted towards the centroid as well as optional custom formatting. Once finished, the image will show on your screen and be saved.

Future Improvements