Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transparency channel to output canvas #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions ico_sampler/icosahedral_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ def get_face_image(self, face_no, eq_image):
xy = self.__get_triangle_coords(self.resolution, is_up, normalize=False, homogeneous=False, center=False)

triangle_height = 3**0.5/2
canvas = np.zeros([int(self.resolution*triangle_height), self.resolution, 3], dtype=np.uint8)
canvas[xy[:, 1], xy[:, 0]] = colors
canvas = np.zeros([int(self.resolution*triangle_height), self.resolution, 4], dtype=np.uint8)
canvas[xy[:, 1], xy[:, 0],2::-1] = colors
canvas[xy[:, 1], xy[:, 0], 3] = 255 # Set alpha to opaque where color is present
return canvas

# =============================================== UNWRAP ===========================================================
Expand All @@ -243,7 +244,7 @@ def unwrap(self, eq_image, face_offset=0):

colors = [self.get_face_rgb(i, eq_image) for i in range(20)]
h_res = int(3**0.5/2*self.resolution)
canvas = np.ones([3*h_res, int(5.5*self.resolution), 3], dtype=np.uint8)*255
canvas = np.zeros([3*h_res, int(5.5*self.resolution), 4], dtype=np.uint8)

# coordinates for moving the color from faces to canvas
xy_up = self.__get_triangle_coords(self.resolution, True, normalize=False, homogeneous=False, center=False)
Expand All @@ -253,13 +254,17 @@ def unwrap(self, eq_image, face_offset=0):

# move colors from faces to canvas
for num, loc in loc_generator:
canvas[xy_up[..., 1], int((loc+0.5)*self.resolution)+xy_up[..., 0]] = colors[num]
canvas[xy_up[..., 1], int((loc+0.5)*self.resolution)+xy_up[..., 0],2::-1] = colors[num]
canvas[xy_up[..., 1], int((loc+0.5)*self.resolution)+xy_up[..., 0],3] = 255
for num, loc in loc_generator:
canvas[h_res+xy_down[..., 1], int((loc+0.5)*self.resolution)+xy_down[..., 0]] = colors[5+num]
canvas[h_res+xy_down[..., 1], int((loc+0.5)*self.resolution)+xy_down[..., 0],2::-1] = colors[5+num]
canvas[h_res+xy_down[..., 1], int((loc+0.5)*self.resolution)+xy_down[..., 0],3] = 255
for num, loc in loc_generator:
canvas[h_res+xy_up[..., 1], loc*self.resolution+xy_up[..., 0]] = colors[10+num]
canvas[h_res+xy_up[..., 1], loc*self.resolution+xy_up[..., 0],2::-1] = colors[10+num]
canvas[h_res+xy_up[..., 1], loc*self.resolution+xy_up[..., 0],3] = 255
for num, loc in loc_generator:
canvas[2*h_res+xy_down[..., 1], loc*self.resolution+xy_down[..., 0]] = colors[15+num]
canvas[2*h_res+xy_down[..., 1], loc*self.resolution+xy_down[..., 0],2::-1] = colors[15+num]
canvas[2*h_res+xy_down[..., 1], loc*self.resolution+xy_down[..., 0],3] = 255

return canvas