All Projects → flrs → blend_modes

flrs / blend_modes

Licence: MIT License
Python package that implements image blend modes

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to blend modes

Photoshopcclinux
Photoshop CC v19 installer for Gnu/Linux
Stars: ✭ 2,894 (+2978.72%)
Mutual labels:  photoshop, gimp
PhotoMP
The AppImage version of GIMP for those who come from Photoshop.
Stars: ✭ 68 (-27.66%)
Mutual labels:  photoshop, gimp
image-editor-effects
💎 A WebGL example of image adjustment / effects shaders found in Photoshop, other image editors and game engines.
Stars: ✭ 68 (-27.66%)
Mutual labels:  photoshop, gimp
gradient-rs
A command line tool for playing with color gradients
Stars: ✭ 93 (-1.06%)
Mutual labels:  gimp
photoshop-react-redux-ramda
🎨😱💀⚛️
Stars: ✭ 24 (-74.47%)
Mutual labels:  photoshop
psd-to-sketch-converter
Convert PSD to Sketch for free
Stars: ✭ 42 (-55.32%)
Mutual labels:  photoshop
Fixture
A no-bullshit, free and open source raster graphics editor.
Stars: ✭ 33 (-64.89%)
Mutual labels:  photoshop
faceapp.js
JavaScript API wrapper for the FaceApp tool for Android and iOS
Stars: ✭ 59 (-37.23%)
Mutual labels:  photoshop
ManTraNet-pytorch
Implementation of the famous Image Manipulation\Forgery Detector "ManTraNet" in Pytorch
Stars: ✭ 47 (-50%)
Mutual labels:  photoshop
multiverse
Adobe Photoshop scripts for making generative art
Stars: ✭ 21 (-77.66%)
Mutual labels:  photoshop
C-Sharp-Learning-Journey
Some of the projects i made when starting to learn c#, winfroms and wpf
Stars: ✭ 95 (+1.06%)
Mutual labels:  photoshop
gimp-hidpi
A theme for HiDPI displays
Stars: ✭ 72 (-23.4%)
Mutual labels:  gimp
palette
🎨 Soothing pastel theme to use within your projects!
Stars: ✭ 50 (-46.81%)
Mutual labels:  gimp
YuzuMarker
🍋 [WIP] Manga Translation Tool
Stars: ✭ 76 (-19.15%)
Mutual labels:  photoshop
ImageStitching
A CV project, based on cimg library to deal with simple Image Stitching task.
Stars: ✭ 40 (-57.45%)
Mutual labels:  image-blending
gimp-tilemap-gb
Tilemap GB - Console App - AND - GIMP plugin for importing & exporting Game Boy game tilemaps and tilesets (as bitmap images or .GBM/.GBR files. Related tools: GBTD, GBMB, GBDK, Zal0-ZGB)
Stars: ✭ 42 (-55.32%)
Mutual labels:  gimp
psd
Blazing fast, zero-dependency PSD parser for the web and Node.js
Stars: ✭ 549 (+484.04%)
Mutual labels:  photoshop
image-optimisation-tools-comparison
A Benchmarking Suite for popular Image Optimisation Tools
Stars: ✭ 28 (-70.21%)
Mutual labels:  photoshop
Apssistant
A Photoshop Tweak Tool on Windows. It can disable ALT to activate the menu bar.
Stars: ✭ 48 (-48.94%)
Mutual labels:  photoshop
Photoshop-Javascript-Tools
Utility scripts to speed up daily photoshopping and automate annoying tasks
Stars: ✭ 35 (-62.77%)
Mutual labels:  photoshop

PyPI version Conda-forge version Documentation Status Build Status

Blend Modes

This Python package implements blend modes for images.

Description

The Blend Modes package enables blending different images, or image layers, by means of blend modes. These modes are commonly found in graphics programs like Adobe Photoshop or GIMP.

Blending through blend modes allows to mix images in a variety of ways. This package currently supports the following blend modes (name of the respective functions in the package in italics):

  • Soft Light (blend_modes.soft_light)
  • Lighten Only (blend_modes.lighten_only)
  • Dodge (blend_modes.dodge)
  • Addition (blend_modes.addition)
  • Darken Only (blend_modes.darken_only)
  • Multiply (blend_modes.multiply)
  • Hard Light (blend_modes.hard_light)
  • Difference (blend_modes.difference)
  • Subtract (blend_modes.subtract)
  • Grain Extract (known from GIMP, blend_modes.grain_extract)
  • Grain Merge (known from GIMP, blend_modes.grain_merge)
  • Divide (blend_modes.divide)
  • Overlay (blend_modes.overlay)
  • Normal (blend_modes.normal)

The intensity of blending can be controlled by means of an opacity parameter that is passed into the functions. See Usage for more information.

The Blend Modes package is optimized for speed. It takes advantage of vectorization through Numpy. Further speedup can be achieved when implementing the package in Cython. However, Cython implementation is not part of this package.

Installation

The Blend Modes package can be installed through pip:

pip install blend_modes

or conda:

conda install -c conda-forge blend_modes

Usage

The blend mode functions take image data expressed as arrays as an input. These image data are usually obtained through functions from image processing packages. Two popular image processing packages in Python are PIL or its fork Pillow and OpenCV. The examples in this chapter show how to blend images using these packages.

Input and Output Formats

A typical blend mode operation is called like this:

blended_img = soft_light(bg_img, fg_img, opacity)

The blend mode functions expect Numpy float arrays in the format [pixels in dimension 1,pixels in dimension 2,4] as an input. Both images needs to have the same size, so the pixels in dimension 1 must be the same for bg_img and fg_img. Same applies to the pixels in dimension 2. Thus, a valid shape of the arrays would be bg_img.shape == (640,320,4) and fg_img.shape == (640,320,4).

The order of the channels in the third dimension should be R, G, B, A, where A is the alpha channel. All values should be floats in the range 0.0 <= value <= 255.0.

The blend mode functions return arrays in the same format as the input format.

Examples

The following examples show how to use the Blend Modes package in typical applications.

The examples are structured in three parts:

  1. Load background and foreground image. The foreground image is to be blended onto the background image.

  2. Use the Blend Modes package to blend the two images via the "soft light" blend mode. The package supports multiple blend modes. See the Description for a full list.

  3. Display the blended image.

PIL/Pillow Example

The following example shows how to use the Blend Modes package with the PIL or Pillow packages.

from PIL import Image
import numpy
from blend_modes import soft_light

# Import background image
background_img_raw = Image.open('background.png')  # RGBA image
background_img = numpy.array(background_img_raw)  # Inputs to blend_modes need to be numpy arrays.
background_img_float = background_img.astype(float)  # Inputs to blend_modes need to be floats.

# Import foreground image
foreground_img_raw = Image.open('foreground.png')  # RGBA image
foreground_img = numpy.array(foreground_img_raw)  # Inputs to blend_modes need to be numpy arrays.
foreground_img_float = foreground_img.astype(float)  # Inputs to blend_modes need to be floats.

# Blend images
opacity = 0.7  # The opacity of the foreground that is blended onto the background is 70 %.
blended_img_float = soft_light(background_img_float, foreground_img_float, opacity)

# Convert blended image back into PIL image
blended_img = numpy.uint8(blended_img_float)  # Image needs to be converted back to uint8 type for PIL handling.
blended_img_raw = Image.fromarray(blended_img)  # Note that alpha channels are displayed in black by PIL by default.
                                                # This behavior is difficult to change (although possible).
                                                # If you have alpha channels in your images, then you should give
                                                # OpenCV a try.

# Display blended image
blended_img_raw.show()

OpenCV Example

The following example shows how to use the Blend Modes package with OpenCV.

import cv2  # import OpenCV
import numpy
from blend_modes import soft_light

# Import background image
background_img_float = cv2.imread('background.png',-1).astype(float)

# Import foreground image
foreground_img_float = cv2.imread('foreground.png',-1).astype(float)

# Blend images
opacity = 0.7  # The opacity of the foreground that is blended onto the background is 70 %.
blended_img_float = soft_light(background_img_float, foreground_img_float, opacity)

# Display blended image
blended_img_uint8 = blended_img_float.astype(numpy.uint8)  # Convert image to OpenCV native display format
cv2.imshow('window', blended_img_uint8)
cv2.waitKey()  # Press a key to close window with the image.

Documentation

Full documentation for the latest version of this package is available on Read the Docs.

Dependencies

The Blend Modes package needs Numpy to function correctly. For loading images the following packages have been successfully used:

See Also

Blend modes are further described on Wikipedia. An actual implementation can be found in the GIMP source code.

Contribution

I am happy about any contribution or feedback. Please let me know about your comments via the Issues tab on GitHub.

License

The Blend Modes package is distributed under the MIT License (MIT). Please also take note of the licenses of the dependencies.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].