Skip to content

Commit

Permalink
Merge pull request #35 from the-database/dev
Browse files Browse the repository at this point in the history
grayscale upscale fixes
  • Loading branch information
the-database authored Jul 31, 2024
2 parents bff5015 + e97ca6f commit d12667e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions MangaJaNaiConverterGui/backend/src/run_upscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ def get_tile_size(tile_size_str: str) -> TileSize:
def standard_resize(image: np.ndarray, new_size: tuple[int, int]) -> np.ndarray:
new_image = image.astype(np.float32) / 255.0
new_image = resize(new_image, new_size, ResizeFilter.Lanczos, False)
return (new_image * 255).round().astype(np.uint8)
new_image = (new_image * 255).round().astype(np.uint8)

_, _, c = get_h_w_c(image)

if c == 1 and new_image.ndim == 3:
new_image = np.squeeze(new_image, axis=-1)

return new_image


"""
Expand All @@ -139,10 +146,7 @@ def dotgain20_resize(image: np.ndarray, new_size: tuple[int, int]) -> np.ndarray
if blur_size > 250:
blur_size = 250

if c == 1:
pil_image = Image.fromarray(image, mode="L")
else:
pil_image = Image.fromarray(image[:, :, 0], mode="L")
pil_image = Image.fromarray(image, mode="L")
pil_image = pil_image.filter(ImageFilter.GaussianBlur(radius=blur_size))
pil_image = ImageCms.applyTransform(pil_image, dotgain20togamma1transform, False)

Expand Down Expand Up @@ -170,7 +174,6 @@ def get_system_codepage() -> Any:


def enhance_contrast(image: np.ndarray) -> MatLike:
# print('1', image[199][501], np.min(image), np.max(image))
image_p = Image.fromarray(image).convert("L")

# Calculate the histogram
Expand Down Expand Up @@ -417,7 +420,7 @@ def ai_upscale_image(
image: np.ndarray, model_tile_size: TileSize, model: ImageModelDescriptor | None
) -> np.ndarray:
if model is not None:
return upscale_image_node(
result = upscale_image_node(
context,
image,
model,
Expand All @@ -427,6 +430,14 @@ def ai_upscale_image(
256,
False,
)

_, _, c = get_h_w_c(image)

if c == 1 and result.ndim == 3:
result = np.squeeze(result, axis=-1)

return result

return image


Expand Down

0 comments on commit d12667e

Please sign in to comment.