Skip to content

Commit

Permalink
Merge pull request #2 from rysuds/working
Browse files Browse the repository at this point in the history
Added column support
  • Loading branch information
rysuds committed Jun 6, 2020
2 parents 95461fe + 4b0a1f2 commit 4ee54dc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
16 changes: 11 additions & 5 deletions exsprite/core/sprite_sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from PIL import Image
import cv2
import fire
from exsprite.utils import show, unique, filter_bounds, get_bounds
from exsprite.utils import show, unique, filter_bounds, get_bounds, transpose


def get_chunk(tup, labeled):
Expand All @@ -38,12 +38,16 @@ def get_labeled_for_rows(labeled, row_tups):
sprite_rows.append(unique(max_row))
return sprite_rows


# TODO allow foldername kwarg
# TODO allow for col/row selection
class SpriteSheet(object):
def __init__(self, filename, background=0):
def __init__(self, filename, background=0, orient='row'):
self.filename = filename
self.foldername = f"{filename.split('.')[0]}_groups"
self.img = io.imread(filename)
self.orient=orient
if self.orient=='col':
self.img=transpose(self.img)
self.background=background
self.boolean_image=None
self.num_labels=None
Expand All @@ -63,12 +67,12 @@ def _get_labeled_image(self):
self.num_labels = ncomponents

def _get_sprite_groups(self):
print(self.boolean_image)
bound_tups = filter_bounds(get_bounds(self.boolean_image))
sprite_groups = get_labeled_for_rows(self.labeled_image, bound_tups)
return sprite_groups

#TODO allow for custom foldernames
# TODO fix bug for allowing existing foldername (verify whole path exists)
def _check_create_folder(self,foldername=None):
foldername = foldername if foldername else self.foldername
if foldername not in set(os.listdir()):
Expand All @@ -88,5 +92,7 @@ def save(self):
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.orient=='col':
sub_image = transpose(sub_image)
#show(sub_image,50)
io.imsave(filename,sub_image)
io.imsave(filename,sub_image,check_contrast=False)
4 changes: 4 additions & 0 deletions exsprite/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import matplotlib.pyplot as plt
import numpy as np
from skimage import io, data, filters

def transpose(img_array):
return np.array([list(i) for i in zip(*img_array)])

def centroid(t1,t2):
return (int(sum(t1)/2), int(sum(t2)/2))

Expand Down

0 comments on commit 4ee54dc

Please sign in to comment.