Skip to main content
Join the official Python Developers Survey 2018 and win valuable prizes: Start the survey!

Tiny package to help highlight portions of an image with matplotlib

Project description

imghighlight

A tiny Python 3 wrapper to make highlighting portions of an image much easier

Installation

Installing is best done using pip:

python3 -m pip install pyhighlight

Another option is to clone the repo and copy the pyhighlight module folder (containing __init__.py) into your project directory.

Usage

The wrapper utilizes three functions:

Name Description
pyhighlight(image_path) The constructor, takes in the base image's file path
highlight(points, color, transparency) Highlights a portion of the image.
  • points - An array of arrays containing the corresponding points (ie. [[1, 1], [2, 2]]). Note: the points must be in order or the highlighted image will look weird. Required.
  • color - A string for the desired color of the highlighted portion. Defaults to 'blue'. Optional.
  • transparency - A float between 0 and 1 for how transparent the highlighting should be. Optional.
save(output_path) Saves the generated image to the file path specified

Example

Let's say you have an image of some buildings you want to highlight:

Example buildings

Assuming you know the points on the image that you want to highlight, a tiny script can be written to easily generate a new image with those buildings highlighted:

import pyhighlight as ph

# Assuming we want to highlight buildings A, B, and C
# from the example image
points = {
    'A': [[45, 156], [155, 50], [156, 160]],
    'B': [[37, 253], [206, 253], [206, 276], [90, 276], [90, 297], [206, 297],
         [206, 330], [90, 330], [90, 352], [210, 352], [210, 386], [37, 386]],
    'C': [[352, 57], [518, 57], [518, 128], [410, 128], [410, 190], [352, 190]]
}

test = ph.pyhighlight('example_buildings.png')
test.highlight(points['A'])
test.highlight(points['B'], color='red', transparency=0.5)
test.highlight(points['C'], color='green')

test.save('example.png')

The final result:

Final result

License

MIT License

Copyright (c) 2018 Tyler Burdsall

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Project details


Release history Release notifications

This version
History Node

1.0.2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pyhighlight-1.0.2-py3-none-any.whl (3.4 kB) Copy SHA256 hash SHA256 Wheel py3 Jul 7, 2018
pyhighlight-1.0.2.tar.gz (3.4 kB) Copy SHA256 hash SHA256 Source None Jul 7, 2018

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page