-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
from PIL import Image | ||
|
||
|
||
def load_image(img_path): | ||
image = Image.open(img_path) | ||
def load_image(img_path, img_bits=8, use_tiff=False): | ||
if use_tiff: | ||
img = tifffile.imread(img_path) | ||
else: | ||
img = Image.open(img_path) | ||
|
||
# Define the color for transparency (e.g., transparent black) | ||
transparent_black = (0, 0, 0, 0) | ||
if img_bits == 8: | ||
img = img.convert("RGB") | ||
|
||
# Convert the image to RGBA mode if needed | ||
image = image.convert("RGBA") | ||
return img | ||
|
||
# Create a new image with the specified color for transparency | ||
transparent_color = Image.new("RGBA", image.size, transparent_black) | ||
|
||
# Use alpha_composite to make the specified color transparent | ||
result = Image.alpha_composite(transparent_color, image) | ||
# def load_image(img_path): | ||
# image = Image.open(img_path) | ||
|
||
# Convert the result back to RGB mode | ||
result_rgb = result.convert("RGB") | ||
# # Define the color for transparency (e.g., transparent black) | ||
# transparent_black = (0, 0, 0, 0) | ||
|
||
return result_rgb | ||
# # Convert the image to RGBA mode if needed | ||
# image = image.convert("RGBA") | ||
|
||
# # Create a new image with the specified color for transparency | ||
# transparent_color = Image.new("RGBA", image.size, transparent_black) | ||
|
||
# # Use alpha_composite to make the specified color transparent | ||
# result = Image.alpha_composite(transparent_color, image) | ||
|
||
# # Convert the result back to RGB mode | ||
# result_rgb = result.convert("RGB") | ||
|
||
# return result_rgb |