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

support non-square shaped tiles #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]

steps:
- name: Checkout
Expand Down
4 changes: 2 additions & 2 deletions examples/example_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# If you don't have any data to try on, you can run the 'example_create_synthetic_dataset.py' script

# We then parse this data using the parser:
tiles = paprica.tileParser(path=path, frame_size=2048)
tiles = paprica.tileParser(path=path, frame_size_h=2048, frame_size_v=2048)

# Next, we batch convert the data. Please refer to the original paper to understand and set correctly the
# conversion parameters. The parameters that do not appear below are automatically determined but can also be
Expand All @@ -27,6 +27,6 @@
)

# It is also possible to batch reconstruct data
tiles_tiff = paprica.tileParser(path='path_to_tiff_data', frame_size=2048)
tiles_tiff = paprica.tileParser(path='path_to_tiff_data', frame_size_h=2048, frame_size_v=2048)
converter = paprica.tileConverter(tiles_tiff)
converter.batch_reconstruct_pixel()
2 changes: 1 addition & 1 deletion examples/example_segmentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def compute_features(apr, parts):
# If you don't have any data to try on, you can run the 'example_create_synthetic_dataset.py' script

# We then parse this data using the parser
tiles = paprica.tileParser(path=path, frame_size=2048, ftype='apr')
tiles = paprica.tileParser(path=path, frame_size_h=2048, frame_size_v=2048, ftype='apr')

# Here we will manually train the segmenter on the first tile
trainer = paprica.tileTrainer(tiles[0, 0], func_to_compute_features=compute_features)
Expand Down
2 changes: 1 addition & 1 deletion examples/example_stitching.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# If you don't have any data to try on, you can run the 'example_create_synthetic_dataset.py' script

# We then parse this data using the parser
tiles = paprica.tileParser(path=path, frame_size=2048, ftype='apr')
tiles = paprica.tileParser(path=path, frame_size_h=2048, frame_size_v=2048, ftype='apr')
# The previous parser expect the data to be in y_x.apr naming convention, this behavior can be adapted by creating
# your own parsing class that inherits from tileParser. We provide an example for COLM data where we just need to
# parse the data to associate each tile with its position on the grid:
Expand Down
3 changes: 2 additions & 1 deletion paprica/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ def batch_convert_to_apr(self,
if self.is_multitile:
# Modify tileParser object to use APR instead
self.tiles = paprica.parser.tileParser(folder_apr,
frame_size=self.tiles.frame_size,
frame_size_h=self.tiles.frame_size_h,
frame_size_v=self.tiles.frame_size_v,
ftype='apr')

def batch_reconstruct_pixel(self, mode='constant', progress_bar=True):
Expand Down
34 changes: 24 additions & 10 deletions paprica/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def tile_from_apr(apr, parts):
neighbors=None,
neighbors_tot=None,
neighbors_path=None,
frame_size=2048,
frame_size_h=apr.shape(2),
frame_size_v=apr.shape(1),
folder_root=None,
channel=None)

Expand Down Expand Up @@ -76,7 +77,8 @@ def tile_from_path(path):
neighbors=None,
neighbors_tot=None,
neighbors_path=None,
frame_size=2048,
frame_size_h=2048,
frame_size_v=2048,
folder_root=os.path.basename(path),
channel=None)

Expand All @@ -86,7 +88,16 @@ class tileLoader():
Class to load each tile, neighboring tiles, segmentation and neighboring segmentation.

"""
def __init__(self, path, row, col, ftype, neighbors, neighbors_tot, neighbors_path, frame_size, folder_root,
def __init__(self, path,
row,
col,
ftype,
neighbors,
neighbors_tot,
neighbors_path,
frame_size_h,
frame_size_v,
folder_root,
channel):
"""
Constructor of tileLoader object.
Expand Down Expand Up @@ -131,8 +142,10 @@ def __init__(self, path, row, col, ftype, neighbors, neighbors_tot, neighbors_pa
in this case neighbors_tot = [[0, 0], [0, 2], [1, 1]]
neighbors_path: list
path of the neighbors whose coordinates are stored in neighbors
frame_size: int
camera frame size (only square sensors are supported for now).
frame_size_h: int
horizontal camera frame size.
frame_size_v: int
vertical camera frame size.
folder_root: str
root folder where everything should be saved.
channel: int
Expand All @@ -147,7 +160,8 @@ def __init__(self, path, row, col, ftype, neighbors, neighbors_tot, neighbors_pa
self.neighbors = neighbors
self.neighbors_tot = neighbors_tot
self.neighbors_path = neighbors_path
self.frame_size = frame_size
self.frame_size_h = frame_size_h
self.frame_size_v = frame_size_v
self.folder_root = folder_root
self.channel = channel
self.is_loaded = False
Expand Down Expand Up @@ -373,7 +387,7 @@ def _load_data(self, path):
elif self.type == 'clearscope':
u = self._load_clearscope(path)
elif self.type == 'tiff3D':
u = imread(path)
u = np.squeeze(imread(path))
elif self.type == 'apr':
apr = pyapr.APR()
parts = pyapr.ShortParticles()
Expand Down Expand Up @@ -401,7 +415,7 @@ def _load_raw(self, path):
numpy array containing the data.
"""
u = np.fromfile(path, dtype='uint16', count=-1)
return u.reshape((-1, self.frame_size, self.frame_size))
return u.reshape((-1, self.frame_size_v, self.frame_size_h))

def _load_colm(self, path):
"""
Expand All @@ -419,7 +433,7 @@ def _load_colm(self, path):
"""
files_sorted = sorted(glob(os.path.join(path, '*CHN0' + str(self.channel) + '_*tif')))
n_files = len(files_sorted)
v = np.empty((n_files, self.frame_size, self.frame_size), dtype='uint16')
v = np.empty((n_files, self.frame_size_v, self.frame_size_h), dtype='uint16')
for i, f in enumerate(tqdm(files_sorted, desc='Loading sequence', leave=False)):
v[i] = imread(f)
return v
Expand All @@ -440,7 +454,7 @@ def _load_clearscope(self, path):
"""
files_sorted = sorted(glob(os.path.join(path, '*')))
n_files = len(files_sorted)
v = np.empty((n_files, self.frame_size, self.frame_size), dtype='uint16')
v = np.empty((n_files, self.frame_size_v, self.frame_size_h), dtype='uint16')
for i, f in enumerate(tqdm(files_sorted, desc='Loading sequence', leave=False)):
v[i] = imread(f)

Expand Down
45 changes: 29 additions & 16 deletions paprica/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,25 @@ class baseParser():
Class used to parse several independent tiles (not multitile).

"""
def __init__(self, path, frame_size, ftype, verbose=True):
def __init__(self, path, frame_size_h, frame_size_v, ftype, verbose=True):
"""
Constructor of the baseParser object.

Parameters
----------
path: string
path where to look for the data.
frame_size: int
size of each frame (camera resolution).
frame_size_h: int
horizontal camera frame size.
frame_size_v: int
vertical camera frame size.
ftype: string
input data type in 'apr', 'tiff2D' or 'tiff3D'

"""
self.path = path
self.frame_size = frame_size
self.frame_size_h = frame_size_h
self.frame_size_v = frame_size_v
self.type = ftype
self.channel = None
self.tiles_list = self._get_tile_list()
Expand Down Expand Up @@ -403,7 +406,8 @@ def __getitem__(self, item):
neighbors=self.neighbors,
neighbors_tot=self.neighbors_tot,
neighbors_path=self.neighbors_path,
frame_size=self.frame_size,
frame_size_h=self.frame_size_h,
frame_size_v=self.frame_size_v,
folder_root=self.folder_root,
channel=self.channel)

Expand All @@ -429,7 +433,8 @@ def __iter__(self):
neighbors=self.neighbors,
neighbors_tot=self.neighbors_tot,
neighbors_path=self.neighbors_path,
frame_size=self.frame_size,
frame_size_h=self.frame_size_h,
frame_size_v=self.frame_size_v,
folder_root=self.folder_root,
channel=self.channel)

Expand All @@ -447,23 +452,26 @@ class tileParser(baseParser):
stitched later on.

"""
def __init__(self, path, frame_size=2048, ftype=None, verbose=True):
def __init__(self, path, frame_size_h=2048, frame_size_v=2048, ftype=None, verbose=True):
"""
Constructor of the tileParser object.

Parameters
----------
path: string
path where to look for the data.
frame_size: int
size of each frame (camera resolution).
frame_size_h: int
horizontal camera frame size.
frame_size_v: int
vertical camera frame size.
ftype: string
input data type in 'apr', 'tiff2D' or 'tiff3D'

"""

self.path = path
self.frame_size = frame_size
self.frame_size_h = frame_size_h
self.frame_size_v = frame_size_v
self.channel = None
if ftype is None:
self.type = self._get_type()
Expand Down Expand Up @@ -602,7 +610,8 @@ def __getitem__(self, item):
neighbors=neighbors,
neighbors_tot=neighbors_tot,
neighbors_path=neighbors_path,
frame_size=self.frame_size,
frame_size_h=self.frame_size_h,
frame_size_v=self.frame_size_v,
folder_root=self.folder_root,
channel=self.channel)

Expand All @@ -626,7 +635,8 @@ def __getitem__(self, item):
neighbors=neighbors,
neighbors_tot=neighbors_tot,
neighbors_path=neighbors_path,
frame_size=self.frame_size,
frame_size_h=self.frame_size_h,
frame_size_v=self.frame_size_v,
folder_root=self.folder_root,
channel=self.channel)

Expand Down Expand Up @@ -665,7 +675,8 @@ def __iter__(self):
neighbors=neighbors,
neighbors_tot=neighbors_tot,
neighbors_path=neighbors_path,
frame_size=self.frame_size,
frame_size_h=self.frame_size_h,
frame_size_v=self.frame_size_v,
folder_root=self.folder_root,
channel=self.channel)

Expand Down Expand Up @@ -712,7 +723,7 @@ def __init__(self, path, channel=0, verbose=True):
self.ncol = u.shape[1]
self.nrow = u.shape[0]
path = os.path.join(path, 'VW0')
super().__init__(path, frame_size=2048, ftype='colm', verbose=verbose)
super().__init__(path, frame_size_h=2048, frame_size_v=2048, ftype='colm', verbose=verbose)

self.channel = channel

Expand Down Expand Up @@ -832,7 +843,8 @@ def __init__(self, path, channel=0, verbose=True):
self.channel = channel
self.folder_settings, self.name_acq = os.path.split(path)
self._parse_settings()
self.frame_size = 2048
self.frame_size_h = 2048
self.frame_size_v = 2048
self.type = 'clearscope'
self.tiles_list = self._get_tile_list()
self.n_tiles = len(self.tiles_list)
Expand Down Expand Up @@ -1074,7 +1086,8 @@ def _get_n_channels(path):
# """
#
# self.path = path
# self.frame_size = 2048
# self.frame_size_h = 2048
# self.frame_size_v = 2048
# self.channel = channel
# self.channel_wavelength = self._get_channel_wavelength(channel)
# self.type = 'mesospim'
Expand Down
Loading