Skip to content

Commit

Permalink
Adding command line progress bars
Browse files Browse the repository at this point in the history
  • Loading branch information
rysuds committed Jun 8, 2020
1 parent 197a577 commit 025685f
Show file tree
Hide file tree
Showing 38 changed files with 19 additions and 14 deletions.
30 changes: 17 additions & 13 deletions exsprite/core/sprite_sheet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from tqdm import tqdm
from functools import reduce
import numpy as np
from skimage import io
Expand Down Expand Up @@ -65,10 +66,10 @@ def _get_sprite_groups(self):

def _check_create_folder(self,folderpath=None):
folderpath = folderpath if folderpath else self.folderpath
if folderpath not in set(os.listdir()):
try:
os.mkdir(folderpath)
else:
print(f'{folderpath} already exists')
except FileExistsError:
print(f'Saving to existing folder: {folderpath}')
return folderpath

def save(self):
Expand All @@ -77,13 +78,16 @@ def save(self):
for group_num, group in enumerate(sprite_groups):
group_folderpath = f"{self.folderpath}/{self.group}_{group_num}"
self._check_create_folder(group_folderpath)
for i, label_num in enumerate(group):
filepath = f"{group_folderpath}/{self.group}{group_num}_{i}.png"
raw_inds = np.where(self.labeled_image == label_num)
rrow, rcol = raw_inds
minr, maxr = int(min(rrow)), int(max(rrow))
minc, maxc = int(min(rcol)), int(max(rcol))
sub_image = self.img[minr:maxr+1, minc:maxc+1]
if self.group == 'col':
sub_image = transpose(sub_image)
io.imsave(filepath, sub_image, check_contrast=False)
with tqdm(total=len(group)) as pbar:
for i, label_num in enumerate(group):
filepath = f"{group_folderpath}/{self.group}{group_num}_{i}.png"
raw_inds = np.where(self.labeled_image == label_num)
rrow, rcol = raw_inds
minr, maxr = int(min(rrow)), int(max(rrow))
minc, maxc = int(min(rcol)), int(max(rcol))
sub_image = self.img[minr:maxr+1, minc:maxc+1]
if self.group == 'col':
sub_image = transpose(sub_image)
io.imsave(filepath, sub_image, check_contrast=False)
pbar.update(1)
pbar.set_description(f"Saving {self.group} {group_num}")
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'scikit-image',
'scipy',
'fire',
'matplotlib'
'matplotlib',
'tqdm'
]

setup(
Expand Down
Binary file added skelly_groups_col/col_0/col0_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_0/col0_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_0/col0_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_0/col0_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_1/col1_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_1/col1_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_1/col1_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_1/col1_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_2/col2_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_2/col2_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_2/col2_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_2/col2_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_3/col3_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_3/col3_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_3/col3_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_3/col3_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_4/col4_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_4/col4_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_4/col4_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_4/col4_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_5/col5_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_5/col5_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_5/col5_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_5/col5_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_6/col6_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added skelly_groups_col/col_6/col6_1.png
Binary file added skelly_groups_col/col_6/col6_2.png
Binary file added skelly_groups_col/col_6/col6_3.png
Binary file added skelly_groups_col/col_7/col7_0.png
Binary file added skelly_groups_col/col_7/col7_1.png
Binary file added skelly_groups_col/col_7/col7_2.png
Binary file added skelly_groups_col/col_7/col7_3.png
Binary file added skelly_groups_col/col_8/col8_0.png
Binary file added skelly_groups_col/col_8/col8_1.png
Binary file added skelly_groups_col/col_8/col8_2.png
Binary file added skelly_groups_col/col_8/col8_3.png

0 comments on commit 025685f

Please sign in to comment.