Skip to main content

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


Download files

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

Source Distribution

pyhighlight-1.0.2.tar.gz (3.4 kB view hashes)

Uploaded Source

Built Distribution

pyhighlight-1.0.2-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page