MCPcopy Create free account
hub / github.com/aigc3d/LHM / path_to_image

Function path_to_image

engine/BiRefNet/utils.py:11–25  ·  view source on GitHub ↗
(path, size=(1024, 1024), color_type=['rgb', 'gray'][0])

Source from the content-addressed store, hash-verified

9
10
11def path_to_image(path, size=(1024, 1024), color_type=['rgb', 'gray'][0]):
12 if color_type.lower() == 'rgb':
13 image = cv2.imread(path)
14 elif color_type.lower() == 'gray':
15 image = cv2.imread(path, cv2.IMREAD_GRAYSCALE)
16 else:
17 print('Select the color_type to return, either to RGB or gray image.')
18 return
19 if size:
20 image = cv2.resize(image, size, interpolation=cv2.INTER_LINEAR)
21 if color_type.lower() == 'rgb':
22 image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)).convert('RGB')
23 else:
24 image = Image.fromarray(image).convert('L')
25 return image
26
27
28

Callers 2

__init__Method · 0.85
__getitem__Method · 0.85

Calls 3

printFunction · 0.85
convertMethod · 0.80
resizeMethod · 0.45

Tested by

no test coverage detected