MCPcopy Create free account
hub / github.com/OpenGVLab/DragGAN / tensorlab2tensor

Function tensorlab2tensor

draggan/deprecated/stylegan2/lpips/util.py:84–100  ·  view source on GitHub ↗
(lab_tensor,return_inbnd=False)

Source from the content-addressed store, hash-verified

82 return np2tensor(img_lab)
83
84def tensorlab2tensor(lab_tensor,return_inbnd=False):
85 from skimage import color
86 import warnings
87 warnings.filterwarnings("ignore")
88
89 lab = tensor2np(lab_tensor)*100.
90 lab[:,:,0] = lab[:,:,0]+50
91
92 rgb_back = 255.*np.clip(color.lab2rgb(lab.astype('float')),0,1)
93 if(return_inbnd):
94 # convert back to lab, see if we match
95 lab_back = color.rgb2lab(rgb_back.astype('uint8'))
96 mask = 1.*np.isclose(lab_back,lab,atol=2.)
97 mask = np2tensor(np.prod(mask,axis=2)[:,:,np.newaxis])
98 return (im2tensor(rgb_back),mask)
99 else:
100 return im2tensor(rgb_back)
101
102def rgb2lab(input):
103 from skimage import color

Callers

nothing calls this directly

Calls 3

tensor2npFunction · 0.85
np2tensorFunction · 0.85
im2tensorFunction · 0.85

Tested by

no test coverage detected