Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zolfa-nd2reader
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lorenzo ZOLFANELLI
zolfa-nd2reader
Commits
078bba08
Commit
078bba08
authored
3 years ago
by
William Niu
Committed by
Lorenzo ZOLFANELLI
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update stitched.py
Fixes rbnvrw/nd2reader#56.
parent
80ae9909
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nd2reader/stitched.py
+7
-24
7 additions, 24 deletions
nd2reader/stitched.py
with
7 additions
and
24 deletions
nd2reader/stitched.py
+
7
−
24
View file @
078bba08
# -*- coding: utf-8 -*-
import
numpy
as
np
# type: ignore
import
warnings
def
get_unwanted_bytes_ids
(
image_group_data
,
image_data_start
,
height
,
width
):
# Check if the byte array size conforms to the image axes size. If not, check
# that the number of unexpected (unwanted) bytes is a multiple of the number of
# rows (height), as the same
u
nmber of unwanted bytes is expected to be
# rows (height), as the same n
u
mber of unwanted bytes is expected to be
# appended at the end of each row. Then, returns the indexes of the unwanted
# bytes.
# Skip the first 4 elements that correspond to the time stamp
...
...
@@ -15,27 +14,16 @@ def get_unwanted_bytes_ids(image_group_data, image_data_start, height, width):
if
not
n_unwanted_bytes
:
return
np
.
arange
(
0
)
assert
0
==
n_unwanted_bytes
%
height
,
(
"
An unexpected number of extra bytes was encountered based on the expected
"
+
"
frame size, therefore the file could not be parsed.
"
"
An unexpected number of extra bytes was encountered based on the expected
"
+
"
frame size, therefore the file could not be parsed.
"
)
return
np
.
arange
(
image_data_start
+
height
*
number_of_true_channels
,
image_data_start
+
width
*
number_of_true_channels
,
len
(
image_group_data
)
-
n_unwanted_bytes
+
1
,
height
*
number_of_true_channels
,
width
*
number_of_true_channels
,
)
def
remove_bytes_by_id
(
byte_ids
,
image_group_data
,
height
):
# Remove bytes by ID.
bytes_per_row
=
len
(
byte_ids
)
//
height
warnings
.
warn
(
f
"
{
len
(
byte_ids
)
}
(
{
bytes_per_row
}
*
{
height
}
) unexpected zero
"
+
"
bytes were found in the ND2 file and removed to allow further parsing.
"
)
for
i
in
range
(
len
(
byte_ids
)):
del
image_group_data
[
byte_ids
[
i
]
:
(
byte_ids
[
i
]
+
bytes_per_row
)]
def
remove_parsed_unwanted_bytes
(
image_group_data
,
image_data_start
,
height
,
width
):
# Stitched ND2 files have been reported to contain unexpected (according to
# image shape) zero bytes at the end of each image data row. This hinders
...
...
@@ -45,11 +33,6 @@ def remove_parsed_unwanted_bytes(image_group_data, image_data_start, height, wid
image_group_data
,
image_data_start
,
height
,
width
)
if
0
!=
len
(
unwanted_byte_ids
):
assert
np
.
all
(
image_group_data
[
unwanted_byte_ids
+
np
.
arange
(
len
(
unwanted_byte_ids
))]
==
0
),
(
f
"
{
len
(
unwanted_byte_ids
)
}
unexpected non-zero bytes were found
"
+
"
in the ND2 file, the file could not be parsed.
"
)
remove_bytes_by_id
(
unwanted_byte_ids
,
image_group_data
,
height
)
image_group_data
=
np
.
delete
(
np
.
array
(
image_group_data
),
unwanted_byte_ids
)
return
image_group_data
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment