Bases: Subfunction_Base
A Subfunction class which fixes the problem of Color Constancy in an image.
Warning
Can only be applied on RGB images.
"The paper Improving dermoscopy image classification using color constancy shows
that using a color compensation technique to reduce the influence of the acquisition
setup on the color features extracted from the images provides a improvement on the
performance for skin cancer classification."
Cite
Description from: https://www.kaggle.com/apacheco/shades-of-gray-color-constancy
Reference - Implementation
https://github.com/nickshawn/Shades_of_Gray-color_constancy_transformation
Reference - Publication
Catarina Barata; M. Emre Celebi; Jorge S. Marques. 2014.
Improving Dermoscopy Image Classification Using Color Constancy.
https://ieeexplore.ieee.org/abstract/document/6866131
Source code in aucmedi/data_processing/subfunctions/color_constancy.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 | class ColorConstancy(Subfunction_Base):
""" A Subfunction class which fixes the problem of Color Constancy in an image.
???+ warning
Can only be applied on RGB images.
"The paper Improving dermoscopy image classification using color constancy shows
that using a color compensation technique to reduce the influence of the acquisition
setup on the color features extracted from the images provides a improvement on the
performance for skin cancer classification."
???+ cite
Description from: https://www.kaggle.com/apacheco/shades-of-gray-color-constancy
??? abstract "Reference - Implementation"
https://github.com/nickshawn/Shades_of_Gray-color_constancy_transformation
??? abstract "Reference - Publication"
Catarina Barata; M. Emre Celebi; Jorge S. Marques. 2014.
Improving Dermoscopy Image Classification Using Color Constancy.
<br>
https://ieeexplore.ieee.org/abstract/document/6866131
"""
#---------------------------------------------#
# Initialization #
#---------------------------------------------#
def __init__(self, power=6):
""" Initialization function for creating a ColorConstancy Subfunction which can be passed to a
[DataGenerator][aucmedi.data_processing.data_generator.DataGenerator].
Args:
power (int): Exponent for the image.
"""
self.power = power
#---------------------------------------------#
# Transformation #
#---------------------------------------------#
def transform(self, image):
# Verify if image is RGB
if image.shape[-1] != 3:
raise ValueError("Image have to be RGB for Color Constancy application!",
"Last axis of image is not 3 (RGB):", image.shape)
# Apply color constancy filtering (Shades of Gray)
img = image.astype('float32')
img_power = np.power(img, self.power)
axes = tuple(range(len(image.shape[:-1])))
rgb_vec = np.power(np.mean(img_power, axes), 1/self.power)
rgb_norm = np.sqrt(np.sum(np.power(rgb_vec, 2.0)))
rgb_vec = rgb_vec / rgb_norm
rgb_vec = 1 / (rgb_vec * np.sqrt(3))
img_filtered = np.multiply(img, rgb_vec)
# Return filtered image
return img_filtered
|
__init__(power=6)
Initialization function for creating a ColorConstancy Subfunction which can be passed to a
DataGenerator.
Parameters:
Name |
Type |
Description |
Default |
power |
int
|
Exponent for the image. |
6
|
Source code in aucmedi/data_processing/subfunctions/color_constancy.py
| def __init__(self, power=6):
""" Initialization function for creating a ColorConstancy Subfunction which can be passed to a
[DataGenerator][aucmedi.data_processing.data_generator.DataGenerator].
Args:
power (int): Exponent for the image.
"""
self.power = power
|