Closed MarekKowalski closed 1 year ago
Hi,
You may need to apply gamma correction to get the more natural-colored image. Here's a rough example of how this can be achieved:
def gammaCorrect(img: Union[th.Tensor, np.ndarray], dim: int = -1) -> Union[th.Tensor, np.ndarray]:
if dim == -1:
dim = len(img.shape) - 1
assert(img.shape[dim] == 3)
gamma, black, color_scale = 2.0, 3.0 / 255.0, [1.4, 1.1, 1.6]
if dim == -1:
dim = len(img.shape) - 1
if th.is_tensor(img):
scale = th.FloatTensor(color_scale).view([3 if i == dim else 1 for i in range(img.dim())])
img = img * scale.to(img) / 1.1
return th.clamp((((1.0 / (1 - black)) * 0.95 * th.clamp(img - black, 0, 2)) ** (1.0 / gamma)) - 15.0 / 255.0, 0, 2,)
else:
scale = np.array(color_scale).reshape([3 if i == dim else 1 for i in range(img.ndim)])
img = img * scale / 1.1
return np.clip((((1.0 / (1 - black)) * 0.95 * np.clip(img - black, 0, 2)) ** (1.0 / gamma)) - 15.0 / 255.0, 0, 2, )
color_corr = lambda x: (255 * gammaCorrect(x / 255.0, dim=1)).clamp(0, 255)
img = color_corr(img)
Thanks a lot, we'll try this and post results here!
Much better indeed, thanks!
Hello!
Let me start by saying that it is amazing you published this dataset, it's a great service to the academic community! The GIF you have in the readme shows a set of images that look something like this:
and then renders that look like this:
This skin colour in the second image is a lot more natural, while the images in the dataset look more like the first image.
Is there a transform we could apply to go from one to the other?
Thanks,
Marek