Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should images be normailzed to [-1, 1] or [0, 1]? #6

Closed
luccachiang opened this issue Nov 18, 2023 · 3 comments
Closed

Should images be normailzed to [-1, 1] or [0, 1]? #6

luccachiang opened this issue Nov 18, 2023 · 3 comments

Comments

@luccachiang
Copy link

luccachiang commented Nov 18, 2023

Hi, thanks for your codebase! In calculate_lpips.py, it says image should be RGB, IMPORTANT: normalized to [-1,1]. https://github.com/JunyaoHu/common_metrics_on_video_quality/blob/c12e449540cf27c1b1412c8012ecc35413fda6a7/calculate_lpips.py#L26C59-L26C59 However, in the README notice section, it says Make sure the pixel value of videos should be in [0, 1].

3. Make sure the pixel value of videos should be in [0, 1].
. How to normalize to raw video whose values is in range [0, 255]? Would you please provide detailed value ranges of all the four metrics?

@JunyaoHu
Copy link
Owner

Hello, I am working for CVPR deadline, please wait for my answer.

@luccachiang
Copy link
Author

Hello, I am working for CVPR deadline, please wait for my answer.

Same as well... Wish you good luck.

@JunyaoHu
Copy link
Owner

JunyaoHu commented Nov 18, 2023

the inital video input range [0-1].

FVD -> [0-1] to [0-255]

def preprocess(videos, target_resolution=224):
# we should tras videos in [0-1] [b c t h w] as th.float
# -> videos in {0, ..., 255} [b t h w c] as np.uint8 array
videos = einops.rearrange(videos, 'b c t h w -> b t h w c')
videos = (videos*255).numpy().astype(np.uint8)

SSIM -> no trans [0-1] to [0-1]

def calculate_ssim_function(img1, img2):
# [0,1]

LPIPS -> [0-1] to [-1-1]

def trans(x):
# if greyscale images add channel
if x.shape[-3] == 1:
x = x.repeat(1, 1, 3, 1, 1)
# value range [0, 1] -> [-1, 1]
x = x * 2 - 1
return x
def calculate_lpips(videos1, videos2, device):
# image should be RGB, IMPORTANT: normalized to [-1,1]
print("calculate_lpips...")
assert videos1.shape == videos2.shape
# videos [batch_size, timestamps, channel, h, w]
# support grayscale input, if grayscale -> channel*3
# value range [0, 1] -> [-1, 1]
videos1 = trans(videos1)
videos2 = trans(videos2)

PSNR -> no trans [0-1] to [0-1]

def img_psnr(img1, img2):
# [0,1]
# compute mse


How to normalize ?

if you input is [0-255]

you can

video = video/255.0

and then calculate


Wish you good luck too.


image should be RGB, IMPORTANT: normalized to [-1,1] is copied form other repos like

image

@JunyaoHu JunyaoHu pinned this issue Nov 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants