Skip to content

Commit

Permalink
Add basic PIL image filters
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fitzpatrick committed Jan 26, 2015
1 parent 34b5a60 commit 7d13bd7
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 5 deletions.
6 changes: 3 additions & 3 deletions pathomx/plugins/pillow/adjust.md
@@ -1,10 +1,10 @@
Adjust Image
=================
Image Adjust
============

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
Expand Down
18 changes: 18 additions & 0 deletions pathomx/plugins/pillow/filter.md
@@ -0,0 +1,18 @@
Image Filter
============

Apply the standard image filters available in 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 simple image filter operations. Add image data to
the *input_image* input (e.g. via the Image import tool) then select the filter to apply.

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/
13 changes: 13 additions & 0 deletions pathomx/plugins/pillow/filter.py
@@ -0,0 +1,13 @@
from PIL import ImageFilter

output_image = input_image.filter({
'contour': ImageFilter.CONTOUR,
'detail': ImageFilter.DETAIL,
'edge_enhance': ImageFilter.EDGE_ENHANCE,
'edge_enhance_more': ImageFilter.EDGE_ENHANCE_MORE,
'emboss': ImageFilter.EMBOSS,
'find_edges': ImageFilter.FIND_EDGES,
'smooth': ImageFilter.SMOOTH,
'smooth_more': ImageFilter.SMOOTH_MORE,
'sharpen': ImageFilter.SHARPEN,
}[ config.get('filter') ])
57 changes: 55 additions & 2 deletions pathomx/plugins/pillow/loader.py
Expand Up @@ -63,7 +63,7 @@ def __init__(self, parent, filename=None, *args, **kwargs):

class AdjustApp(ui.GenericTool):

name = "Adjust Image"
name = "Image Adjust"
shortname = 'adjust'

def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -98,7 +98,7 @@ class ChopsConfigPanel(ui.ConfigPanel):
'Subtract (Modulo)': 'subtract_modulo',
}

def __init__(self, parent, filename=None, *args, **kwargs):
def __init__(self, parent, *args, **kwargs):
super(ChopsConfigPanel, self).__init__(parent, *args, **kwargs)

self.v = parent
Expand Down Expand Up @@ -138,11 +138,64 @@ def __init__(self, *args, **kwargs):



class FilterConfigPanel(ui.ConfigPanel):
filter_types = {
'Contour': 'contour',
'Detail': 'detail',
'Edge Enhance': 'edge_enhance',
'Edge Enhance (More)': 'edge_enhance_more',
'Emboss': 'emboss',
'Find Edges': 'find_edges',
'Smooth': 'smooth',
'Smooth (More)': 'smooth_more',
'Sharpen': 'sharpen',
}

def __init__(self, parent, *args, **kwargs):
super(FilterConfigPanel, self).__init__(parent, *args, **kwargs)

self.v = parent
self.config = parent.config
gb = QGroupBox('Apply Filter')
grid = QGridLayout()

self.cb_op = QComboBox()
self.cb_op.addItems(list(self.filter_types.keys()))
grid.addWidget(QLabel('Filter'), 1, 0)
grid.addWidget(self.cb_op, 1, 1)
self.config.add_handler('filter', self.cb_op, self.filter_types)
gb.setLayout(grid)

self.layout.addWidget(gb)

self.finalise()


class FilterApp(ui.GenericTool):

name = "Image Filter"
shortname = 'filter'

def __init__(self, *args, **kwargs):
super(FilterApp, self).__init__(*args, **kwargs)

self.config.set_defaults({
'filter': 'smooth'
})

self.addConfigPanel(FilterConfigPanel, 'Settings')

self.data.add_input('input_image')
self.data.add_output('output_image')




class Pillow(ProcessingPlugin):

def __init__(self, *args, **kwargs):
super(Pillow, self).__init__(*args, **kwargs)
self.register_app_launcher(AdjustApp)
self.register_app_launcher(ChopsApp)
self.register_app_launcher(FilterApp)

0 comments on commit 7d13bd7

Please sign in to comment.