Skip to content

Commit 2123bee

Browse files
DrosrinDrosrin
and
Drosrin
authored
merged (#110)
* Upload ./stage2_diffusion folder * 1. Update color: border 2. The white edges of septas have been optimized 3. Fixed keep_memory bug 4. Simple README is provided(not completed) * format fix * fixed a float bug * Merged. Implement sharpening & post-processing * fixed a type bug * Correctly Merged * Fixed type * 这会总该是对的了吧 * Figure fixed * 这个真是对的了 --------- Co-authored-by: Drosrin <[email protected]>
1 parent 3a6723c commit 2123bee

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed

stage2_diffusion/figure.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -251,22 +251,19 @@ def __handle_curve(
251251
return curve_points[:, 0], curve_points[:, 1], center
252252

253253
def __get_essential_info(self, shape, width, color, trans):
254-
if width is None:
255-
width = self.__get_width(shape)
256-
if color is None:
257-
color = self.__get_color(shape)
258-
color = np.clip(color, 0, 1)
259-
if trans is None:
260-
trans = self.__get_transparency(shape)
261-
return width, color, trans
254+
w = self.__get_width(shape, width)
255+
c = self.__get_color(shape, color)
256+
c = np.clip(c, 0, 1)
257+
t = self.__get_transparency(shape, trans)
258+
return w, c, t
262259

263-
def __get_width(self, shape):
260+
def __get_width(self, shape, width: float):
264261
try:
265262
return shape["width"]
266263
except Exception:
267-
return 1.8
264+
return 1.8 if width is None else width
268265

269-
def __get_color(self, shape):
266+
def __get_color(self, shape, color):
270267
try:
271268
return shape["color"]
272269
except Exception:
@@ -276,19 +273,22 @@ def __get_color(self, shape):
276273
else:
277274
return (1, 1, 1, 1)
278275
except Exception:
279-
return (random.random(), random.random(), random.random())
276+
return (random.random(), random.random(), random.random()) if color is None else color
280277

281-
def __get_transparency(self, shape):
278+
def __get_transparency(self, shape, trans):
282279
try:
283280
if shape["fill_mode"] == "no":
284-
trans = (0, 0, 0, 0)
281+
return (0, 0, 0, 0)
285282
elif shape["fill_mode"] == "white":
286-
trans = (1, 1, 1, 1)
283+
return (1, 1, 1, 1)
287284
elif shape["fill_mode"] == "black":
288-
trans = (0, 0, 0, 1)
285+
return (0, 0, 0, 1)
286+
elif shape["fill_mode"] == "border":
287+
return (0, 0, 0, 0)
288+
else:
289+
raise Exception("Invalid fill_mode arg")
289290
except Exception:
290-
trans = (0, 0, 0, 0) # no
291-
return trans
291+
return trans if trans is not None else (0, 0, 0, 0)
292292

293293
def transfer_to_cv2_wrapper(self):
294294
buf2 = BytesIO()

stage2_diffusion/process.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ def fill_septas(xs, ys, centers, cv2_fig: np.ndarray, alpha_channel: np.ndarray)
208208
return cv2_fig, alpha_channel
209209

210210

211+
def post_processing(img: np.ndarray):
212+
img = cv2.convertScaleAbs(img, alpha=1.5, beta=0)
213+
laplacian = cv2.Laplacian(img, cv2.CV_64F)
214+
laplacian = np.uint8(np.absolute(laplacian))
215+
sharpened = cv2.addWeighted(img, 1, laplacian, 1, 0)
216+
return sharpened
217+
218+
211219
def generate_one_img(
212220
idx,
213221
sample,
@@ -259,10 +267,11 @@ def generate_one_img(
259267
blended_img = np.where(alpha_mask == 255, septa_overlayer, diffused_img)
260268

261269
blended_img = cv2.cvtColor(blended_img, cv2.COLOR_BGRA2GRAY)
270+
final_img = post_processing(blended_img)
262271
img_path = f"{keyword}/{img_path}"
263272
if not os.path.exists(f"{keyword}"):
264273
os.mkdir(f"{keyword}")
265-
cv2.imwrite(img_path, blended_img)
274+
cv2.imwrite(img_path, final_img)
266275

267276

268277
def main():

0 commit comments

Comments
 (0)