~ubuntu-branches/debian/squeeze/python-imaging/squeeze

« back to all changes in this revision

Viewing changes to PIL/ImageFilter.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-08-28 23:14:10 UTC
  • mfrom: (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20060828231410-lca9enmne3ecmkup
Tags: 1.1.5-11
* python-imaging-sane: Depend on python-numarray. Closes: #382190.
* Add dependencies on ${shlibs:Depends}, lost in -6. Closes: #378596.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#
2
2
# The Python Imaging Library.
3
 
# $Id: //modules/pil/PIL/ImageFilter.py#11 $
 
3
# $Id: ImageFilter.py 2134 2004-10-06 08:55:20Z fredrik $
4
4
#
5
5
# standard filters
6
6
#
7
7
# History:
8
 
# 1995-11-27 fl     Created
9
 
# 2002-06-08 fl     Added rank and mode filters
 
8
# 1995-11-27 fl   Created
 
9
# 2002-06-08 fl   Added rank and mode filters
 
10
# 2003-09-15 fl   Fixed rank calculation in rank filter; added expand call
10
11
#
11
 
# Copyright (c) Secret Labs AB 1997-2002.
12
 
# Copyright (c) Fredrik Lundh 1995-2002.
 
12
# Copyright (c) 1997-2003 by Secret Labs AB.
 
13
# Copyright (c) 1995-2002 by Fredrik Lundh.
13
14
#
14
15
# See the README file for information on usage and redistribution.
15
16
#
69
70
    #
70
71
    # @param size The kernel size, in pixels.
71
72
    # @param rank What pixel value to pick.  Use 0 for a min filter,
72
 
    #    size/2 for a median filter, size-1 for a max filter, etc.
 
73
    #    size*size/2 for a median filter, size*size-1 for a max filter,
 
74
    #    etc.
73
75
 
74
76
    def __init__(self, size, rank):
75
77
        self.size = size
76
78
        self.rank = rank
77
79
 
78
80
    def filter(self, image):
 
81
        image = image.expand(self.size/2, self.size/2)
79
82
        return image.rankfilter(self.size, self.rank)
80
83
 
81
84
##
92
95
 
93
96
    def __init__(self, size=3):
94
97
        self.size = size
95
 
        self.rank = size/2
 
98
        self.rank = size*size/2
96
99
 
97
100
##
98
101
# Min filter.  Picks the lowest pixel value in a window with the given
124
127
 
125
128
    def __init__(self, size=3):
126
129
        self.size = size
127
 
        self.rank = size-1
 
130
        self.rank = size*size-1
128
131
 
129
132
##
130
133
# Mode filter.  Picks the most frequent pixel value in a box with the