Skip to content
Snippets Groups Projects
Commit f792f177 authored by ogueler@idiap.ch's avatar ogueler@idiap.ch
Browse files

removed redundant custom transform function

parent 5f0b0dd2
No related branches found
No related tags found
2 merge requests!5Tbx11k,!4Moved code to lightning
......@@ -19,7 +19,7 @@ def _maker(protocol, RGB=False):
return mk(
[raw.subsets(protocol)],
[RGBtoGreyscale8bit()],
[],
[ElasticDeformation(p=0.8)],
post_transforms,
)
......@@ -42,39 +42,6 @@ class SingleAutoLevel16to8:
).convert("L")
class RGBtoGreyscale8bit:
"""Converts a 24-bit RGB image to an 8-bit greyscale representation.
This transform assumes that the input image is RGB with 24 bits.
Converts the RGB image to a greyscale image using the well-known formula:
Y = 0.299 * R + 0.587 * G + 0.114 * B
This formula is based on the relative luminance of the RGB channels in the sRGB color space
consider such a range should be mapped to the [0,255] range of the
destination image.
"""
def __call__(self, img):
# Use the formula to convert the RGB image to a greyscale image
img_array = numpy.array(img).astype(float)
grey_array = (
0.299 * img_array[:, :, 0]
+ 0.587 * img_array[:, :, 1]
+ 0.114 * img_array[:, :, 2]
)
# Normalize the greyscale image to the range [0, 255] and convert it to uint8
grey_array = numpy.round(
255.0
* (grey_array - grey_array.min())
/ (grey_array.max() - grey_array.min())
).astype("uint8")
# Create a new greyscale PIL image from the normalized array
return PIL.Image.fromarray(grey_array).convert("L")
class RemoveBlackBorders:
"""Remove black borders of CXR."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment