MCPcopy
hub / github.com/XingangPan/DragGAN / preprocess_mask_info

Function preprocess_mask_info

visualizer_drag_gradio.py:115–151  ·  view source on GitHub ↗

Function to handle mask information. 1. last_mask is None: Do not need to change mask, return mask 2. last_mask is not None: 2.1 global_state is remove_mask: 2.2 global_state is add_mask:

(global_state, image)

Source from the content-addressed store, hash-verified

113
114
115def preprocess_mask_info(global_state, image):
116 """Function to handle mask information.
117 1. last_mask is None: Do not need to change mask, return mask
118 2. last_mask is not None:
119 2.1 global_state is remove_mask:
120 2.2 global_state is add_mask:
121 """
122 if isinstance(image, dict):
123 last_mask = get_valid_mask(image['mask'])
124 else:
125 last_mask = None
126 mask = global_state['mask']
127
128 # mask in global state is a placeholder with all 1.
129 if (mask == 1).all():
130 mask = last_mask
131
132 # last_mask = global_state['last_mask']
133 editing_mode = global_state['editing_state']
134
135 if last_mask is None:
136 return global_state
137
138 if editing_mode == 'remove_mask':
139 updated_mask = np.clip(mask - last_mask, 0, 1)
140 print(f'Last editing_state is {editing_mode}, do remove.')
141 elif editing_mode == 'add_mask':
142 updated_mask = np.clip(mask + last_mask, 0, 1)
143 print(f'Last editing_state is {editing_mode}, do add.')
144 else:
145 updated_mask = mask
146 print(f'Last editing_state is {editing_mode}, '
147 'do nothing to mask.')
148
149 global_state['mask'] = updated_mask
150 # global_state['last_mask'] = None # clear buffer
151 return global_state
152
153
154valid_checkpoints_dict = {

Callers 4

on_click_startFunction · 0.85
on_click_enable_drawFunction · 0.85
on_click_remove_drawFunction · 0.85
on_click_add_pointFunction · 0.85

Calls 1

get_valid_maskFunction · 0.90

Tested by

no test coverage detected