Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple Image Adjust tool (using Pillow Enhance)
- Loading branch information
Martin Fitzpatrick
committed
Jan 26, 2015
1 parent
4ddd36f
commit 9958cb6
Showing
8 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[Core] | ||
Name = Pillow (PIL fork) | ||
Module = loader | ||
|
||
[Documentation] | ||
Author = Martin Fitzpatrick | ||
Version = 1.0 | ||
Website = http://martinfitzpatrick.name/ | ||
Description = Python Imaging Library image processing tools |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Adjust Image | ||
================= | ||
Peform basic image adjustments (brightness, contrast, color and sharpness) using the [Pillow][] image | ||
library. [Pillow][] is the ‘friendly’ [PIL][] fork by Alex Clark and Contributors. [PIL][] is the Python Imaging Library by Fredrik Lundh and Contributors. | ||
Pathomx tool implementations by [Martin A. Fitzpatrick][] | ||
|
||
|
||
Introduction | ||
------------ | ||
This tool performs basic image adjustments including brightness, contrast, color and sharpness. Add image data to | ||
the *input_image* input (e.g. via the Image import tool) then adjust the sliders to modify the image output. All | ||
adjustments can be performed simultaneously. | ||
|
||
The adjusted image is available via the *output_image* output. | ||
|
||
|
||
[Martin A. Fitzpatrick]: http://martinfitzpatrick.name/ | ||
[Pillow]: https://pillow.readthedocs.org/ | ||
[PIL]: http://www.pythonware.com/products/pil/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from PIL import ImageEnhance | ||
|
||
|
||
output_image = input_image | ||
|
||
if config.get('brightness') != 100: | ||
adjuster = ImageEnhance.Brightness(output_image) | ||
output_image = adjuster.enhance( float(config.get('brightness')) / 100 ) | ||
|
||
if config.get('contrast') != 100: | ||
adjuster = ImageEnhance.Contrast(output_image) | ||
output_image = adjuster.enhance( float(config.get('contrast')) / 100 ) | ||
|
||
if config.get('color') != 100: | ||
adjuster = ImageEnhance.Color(output_image) | ||
output_image = adjuster.enhance( float(config.get('color')) / 100 ) | ||
|
||
if config.get('sharpness') != 100: | ||
adjuster = ImageEnhance.Sharpness(output_image) | ||
output_image = adjuster.enhance( float(config.get('sharpness')) / 100 ) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
import os | ||
|
||
from pathomx.plugins import ProcessingPlugin | ||
|
||
from PIL import Image | ||
|
||
from pathomx.qt import * | ||
|
||
import pathomx.ui as ui | ||
import pathomx.utils as utils | ||
|
||
|
||
# Dialog box for Metabohunter search options | ||
class EnhanceConfigPanel(ui.ConfigPanel): | ||
|
||
def __init__(self, parent, filename=None, *args, **kwargs): | ||
super(EnhanceConfigPanel, self).__init__(parent, *args, **kwargs) | ||
|
||
self.v = parent | ||
self.config = parent.config | ||
gb = QGroupBox('Enhance') | ||
grid = QGridLayout() | ||
|
||
self.bright = QSlider(Qt.Horizontal) | ||
self.bright.setRange(0, 200) | ||
self.bright.setSingleStep(10) | ||
self.bright.setPageStep(50) | ||
grid.addWidget(QLabel('Brightness'), 0, 0) | ||
grid.addWidget(self.bright, 0, 1) | ||
self.config.add_handler('brightness', self.bright) | ||
|
||
self.contrast = QSlider(Qt.Horizontal) | ||
self.contrast.setRange(0, 200) | ||
self.contrast.setSingleStep(10) | ||
self.contrast.setPageStep(50) | ||
grid.addWidget(QLabel('Contrast'), 1, 0) | ||
grid.addWidget(self.contrast, 1, 1) | ||
self.config.add_handler('contrast', self.contrast) | ||
|
||
self.color = QSlider(Qt.Horizontal) | ||
self.color.setRange(0, 200) | ||
self.color.setSingleStep(10) | ||
self.color.setPageStep(50) | ||
grid.addWidget(QLabel('Color'), 2, 0) | ||
grid.addWidget(self.color, 2, 1) | ||
self.config.add_handler('color', self.color) | ||
|
||
self.sharp = QSlider(Qt.Horizontal) | ||
self.sharp.setRange(0, 200) | ||
self.sharp.setSingleStep(10) | ||
self.sharp.setPageStep(50) | ||
grid.addWidget(QLabel('Sharp'), 3, 0) | ||
grid.addWidget(self.sharp, 3, 1) | ||
self.config.add_handler('sharpness', self.sharp) | ||
|
||
gb.setLayout(grid) | ||
|
||
self.layout.addWidget(gb) | ||
|
||
self.finalise() | ||
|
||
|
||
class AdjustApp(ui.GenericTool): | ||
|
||
name = "Adjust Image" | ||
shortname = 'adjust' | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(AdjustApp, self).__init__(*args, **kwargs) | ||
|
||
self.config.set_defaults({ | ||
'brightness': 100, | ||
'contrast': 100, | ||
'color': 100, | ||
'sharpness': 100, | ||
}) | ||
|
||
self.addConfigPanel(EnhanceConfigPanel, 'Settings') | ||
|
||
self.data.add_input('input_image') # Add output slot | ||
self.data.add_output('output_image') # Add output slot | ||
|
||
|
||
class Pillow(ProcessingPlugin): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(Pillow, self).__init__(*args, **kwargs) | ||
self.register_app_launcher(AdjustApp) | ||
|