arXiv:1802.01009v1 [] 3 Feb 2018

Image Posterization Using Fuzzy Logic and
Bilateral Filter
Mahmoud Afifi
IT Dept., Assiut University, Egypt
email: m.afifi@aun.edu.eg
20 Dec, 2016

Abstract
Image posterization is converting images with a large number of tones into
synthetic images with distinct flat areas and a fewer number of tones. In this
technical report, we present the implementation and results of using fuzzy logic
in order to generate a posterized image in a simple and fast way. The image
filter is based on fuzzy logic and bilateral filtering; where, the given image is
blurred to remove small details. Then, the fuzzy logic is used to classify each
pixel into one of three specific categories in order to reduce the number of colors.
This filter was developed during building the Specs on Face dataset in order to
add a new level of difficulty to the original face images in the dataset. This
filter does not hurt the human detection performance; however, it is considered
a hindrance evading the face detection process. This filter can be used generally
for posterizing images, especially those have a high contrast to get images with
vivid colors.

Figure 1: Image posterization filter. (a) The original image. (b) The posterized
image.

0.1

Introduction

Image posterization is converting an image that has a large number of tones into
an image with distinct flat areas and a fewer number of tones. In this technical
report, we present the implementation and results of image posterization using
fuzzy logic and bilateral filtering. This image filter is considered a simple way to
obtain a posterized image in low computational time. Figure 1 shows the result
of the image filter. The image posterization filter is based on pre-smoothing of
the original image using bilateral filtering [1] that smooths the original image
without affecting the edges in the blurred image. The reason of smoothing
the image is to remove small details before the quantization process. Next, an
image quantization process is applied to the blurred image to generate the final
synthetic image. In this process, fuzzy logic is used to classify each pixel in each
channel of the color model into one of three categories which are: 1) bright, 2)
gray, or 3) dark [2]. After the classification process, each pixel is assigned to a
specific intensity value, that for each color channel, based on its category. The
synthetic image filter gives vivid color images compared with Adobe Photoshop
Poster Edges filter. If this filter is applied to a face image, it does not hurt
the human detection performance; however, this filter is considered a hindrance
evading the face detection process. For that reason, this filter was developed
within constructing the Specs on Face dataset [3] in order to add a new level of
difficulty to the original face images in the dataset.

0.2

Image Posterization

For generating a posterized image, two main stages are performed. The first
stage is to remove small details of the given image. To that end, the bilateral
filter is used for preserving the edges in the filtered image [1]. The bilateral
filter closes to Gaussian smoothing by using a weighted average of the pixels.
However, the bilateral filter considers two pixels close together not only relying
on the spatial coordinates of them, but they must close enough in their intensity.
Thus, the bilateral filter is considered edge-preserving filter. Figure 2 shows the

1

Figure 2: The pre-blurring process. (a) The original image. (b) The pre-blured
image using the bilateral filter
blurred image after using the bilateral filter. The enlargement of the ground
region shows the result of removing small objects.
After preparing the given image to the image quantization process, fuzzy logic
plays the role of classifying each pixel into one of three categories which are:
1) bright, 2) gray, or 3) dark [2]. Fuzzy logic solves the problem of crisp sets
using membership functions that determine the element’s degree of belonging
to each set. In other words, the membership function υ maps element x to
degree of membership in the fuzzy set A, i.e., υ(x) = Degree(x ∈ A). Where,
A = {x, υ(x)}. Thus, the element x may be a full member of the set (υ(x) = 1),
not a member of the set (υ(x) = 0), or has a partial membership in the set
(0 < υ(x) < 1) [2]. By using linguistic labels, each element has its membership
to one or more labels using a set of (IF-THEN) rules. Scaler inputs are converted
into fuzzy sets using the fuzzification process. After that, combining rules using
(ANDs or ORs) are performed to establish a robust rule. After determining the
fuzzy output, the defuzzification process is performed to generate the final crisp
output.
Fuzzy logic is used in this context to determine the category (the linguistics
label) of each pixel in the given image. There are three linguistics labels which
are: 1) dark, 2) gray, or 3) bright. For each pixel in each channel of the color
model, the fuzzification process is performed and the membership of the three
categories is calculated. As shown in Figure 3, the dark membership function
is represented using the following sigma function:

−p
1 − adr
if adr ≤ p ≤ adr + bdr

bdr






dr )
1 − (p−a
if p < adr
cdr
υdr (p) =
(1)





otherwise,

 0

2

Figure 3: The membership functions.
Gray membership function is represented using the following triangular function:

ag −p

if ag − bg ≤ p < ag
 1 − bg






(p−a )
1 − bg g if ag ≤ p ≤ ag + bg
υg (p) =
(2)





0
otherwise,



Bright membership function is represented using the following sigma function:

−p
1 − abr
if abr − bbr ≤ p ≤ abr

bbr






br )
1 − (p−a
if abr < p
cbr
υbr (p) =
(3)





otherwise,

 0
where aK , bK , and cK are the parameters of the membership functions. υK (p)
represents the membership’s degree of the intensity of the current pixel p where,
K ∈ {dr, g, br}. dr, g, and br denote dark, gray, and bright linguistics, respectively.
The defuzzification process is performed for determining the crisp output of the
current pixel. By determining the center of gravity which is given by:
PN

v0 = Pv=1
N

vQ(v)

v=1

Q(v)

,

(4)

where Q denotes the fuzzy output, v is the output variable, and N is the possible
values of Q. In our case, the output of the membership functions are constants,
so equ. 4 can be represented as:
v0 =

υdr (p)vdr + υg (p)vg + υbr (p)vbr
,
υdr (p) + υg (p) + υbr (p)
3

(5)

where vdr , vg , and vbr are the output variables of dark, gray, and bright membership functions, respectively.
By getting the final value, the final crisp output is given by finding the minimum
between v0 and the output variables of the membership functions:
min(jv0 − vdr j, jv0 − vg j, jv0 − vbr j).

(6)

The minimum value refers to the category of the pixel, either dark, gray, or
bright. By Applying the following rules, the new intensity of the pixel is found:
IF p is dark, THEN make it vdr .
IF p is gray, THEN make it vg .
IF p is bright, THEN make it vbr .
To get several effects, a series of posterized images can be generated by:
• max(I, O),
• min(I, O),
• α O+ (1-α) I,
where I is the original image, O is the raw output of the posterization process,
and α is the blending weight.

0.3

Implementation

This filter is implemented using both Matlab and OpenCV. In the next lines,
the pseudocode of the image posterization filter is presented:
----------------------------------------Pseudocode
----------------------------------------Function F = Posterization(I)
-- Posterization Filter
I=Bilateral(I)
if I is colored image
for i=1 to 3
F.ColorChannel(i)=...
Fuzzy(I.ColorChannel(i))
end
else
F=Fuzzy(I)
end
Return F
////////////////////////////////
Function F = Fuzzy(I)
-- Fuzzy logic
foreach pixel p in I
vDR=darkkMembFunc(I(p))
vG=grayMembFunc(I(p))
vBR=brightMembFunc(I(p))
4

v=(vDR*vd+vG*vg+vBR*vb)/...
(vDR+vG+vBR)
index=min([abs(v-vd),...
abs(v-vg),abs(v-vb)])
if index=1
F(p)=vd
else
if index=2
F(p)=vg
else
F(p)=vb;
end
end
return F
/////////////////////////////////
Function vBR=brightMembFunc(z)
-- Bright Membership function
if a-b<=z<=a
vBR=1-(a-z)/b
else
if z>a
vBR=1
else
vBR=0
end
end
return vBR
/////////////////////////////////
Function vG=grayMembFunc(z)
-- Gray Membership function
if a-b<=z<=a
vG=1-(a-z)/b
else
if a<=z<a+b
vG=1-(z-a)/b
else
vG=0
end
end
return vG
/////////////////////////////////
Function vDR=darkkMembFunc(z)
-- Dark Membership function
if a<=z<=a+b
vDR=1-(a+b-z)/a
else
if z<a
vDR=1
else
vDR=0
end
end
return vDR
////////////////////////////////
You can download the Matlab source code
from the links below.

1

and the OpenCV source code

2

1 https://www.dropbox.com/s/mlt7ks4p3irq9bk/Image%20Posterization%20Filter%20Matlab.rar?dl=0
2 https://www.dropbox.com/s/cdaqluqvyhtvn98/Image%20Posterization%20Filter.rar?dl=0

5

Figure 4: The results of the image filter. Each row shows (a) the original image,
the results of the Adobe Photoshop Poster Edges filter using posterization =
0, 1,and 3 in (b), (c), and (d), respectively. (e) shows the results of the image
posterization filter.

Figure 5: A comparison between the image posterization using fuzzy logic and
the pixelated image abstraction method [4]. (a) The original image. (b) The
result of [4] using six colors. The results of the posterization using fuzzy logic
using (c) α = 0.3, (d) α = 0.5, (e) α = 0.7, (f) α = 1.0, (g) min(I, O), and (h)
max(I, O).

6

0.4

Results

Figure 5 shows the results of the synthetic image filter compared to the Adobe
Photoshop Poster Edges filter. Membership function’s variables are vdr = 0,
vg = 127, vbr = 255, adr = 73, bdr = 50, ag = 127, bg = 50, abr = 177,
and bbr = 50. The Adobe Photshop filter’s parameters are edgethickness = 0,
edgeintensity = 0 and posterization = 0, 1, and 2. As shown, the posterization
image filter generates images with vivid colors compared with the results of the
Adobe Photoshop Poster Edges filter. Figure 6 shows the effect of using three
different weights (0.3, 0.5, 0.7) and the min/max operations. Again, the image
posterization filter gives images that have more contrast in comparison with the
pixelated image abstraction method [4].

7

Bibliography
[1] Paris, Sylvain, et al. A gentle introduction to bilateral filtering and its applications. ACM SIGGRAPH 2007 courses. ACM, 2007.
[2] Gonzalez, Rafael C., and Richard E. Woods. Digital image processing. Pearson/Prentice Hall, 2008.
[3] Mahmoud Afifi and Abdelrahman. AFIF4 : Deep gender classification based
on an AdaBoost-based fusion of isolated facial features and foggy faces. arXiv
preprint arXiv:1706.04277, 2017.
[4] Gerstner, Timothy, et al. Pixelated image abstraction with integrated user
constraints. Computers & Graphics 37.5, 333-347, 2013.

8

