Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
python3-imagej-tiff
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
python3-imagej-tiff
Commits
091eaecb
Commit
091eaecb
authored
Sep 06, 2018
by
Oleg Dzhimiev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
no need
parent
dddf1d4a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
74 deletions
+0
-74
imagej_tiffwriter_test.py
imagej_tiffwriter_test.py
+0
-74
No files found.
imagej_tiffwriter_test.py
deleted
100644 → 0
View file @
dddf1d4a
#!/usr/bin/env python3
import
struct
import
numpy
import
tifffile
import
math
def
imagej_metadata_tags
(
metadata
,
byteorder
):
"""Return IJMetadata and IJMetadataByteCounts tags from metadata dict.
The tags can be passed to the TiffWriter.save function as extratags.
"""
header
=
[{
'>'
:
b
'IJIJ'
,
'<'
:
b
'JIJI'
}[
byteorder
]]
bytecounts
=
[
0
]
body
=
[]
def
writestring
(
data
,
byteorder
):
return
data
.
encode
(
'utf-16'
+
{
'>'
:
'be'
,
'<'
:
'le'
}[
byteorder
])
def
writedoubles
(
data
,
byteorder
):
return
struct
.
pack
(
byteorder
+
(
'd'
*
len
(
data
)),
*
data
)
def
writebytes
(
data
,
byteorder
):
return
data
.
tobytes
()
metadata_types
=
(
(
'Info'
,
b
'info'
,
1
,
writestring
),
(
'Labels'
,
b
'labl'
,
None
,
writestring
),
(
'Ranges'
,
b
'rang'
,
1
,
writedoubles
),
(
'LUTs'
,
b
'luts'
,
None
,
writebytes
),
(
'Plot'
,
b
'plot'
,
1
,
writebytes
),
(
'ROI'
,
b
'roi '
,
1
,
writebytes
),
(
'Overlays'
,
b
'over'
,
None
,
writebytes
))
for
key
,
mtype
,
count
,
func
in
metadata_types
:
if
key
not
in
metadata
:
continue
if
byteorder
==
'<'
:
mtype
=
mtype
[::
-
1
]
values
=
metadata
[
key
]
if
count
is
None
:
count
=
len
(
values
)
else
:
values
=
[
values
]
header
.
append
(
mtype
+
struct
.
pack
(
byteorder
+
'I'
,
count
))
for
value
in
values
:
data
=
func
(
value
,
byteorder
)
body
.
append
(
data
)
bytecounts
.
append
(
len
(
data
))
body
=
b
''
.
join
(
body
)
header
=
b
''
.
join
(
header
)
data
=
header
+
body
bytecounts
[
0
]
=
len
(
header
)
bytecounts
=
struct
.
pack
(
byteorder
+
(
'I'
*
len
(
bytecounts
)),
*
bytecounts
)
return
((
50839
,
'B'
,
len
(
data
),
data
,
True
),
(
50838
,
'I'
,
len
(
bytecounts
)
//
4
,
bytecounts
,
True
))
def
hamming_window
(
x
,
N
):
y
=
0.54
-
0.46
*
math
.
cos
(
2
*
math
.
pi
*
x
/
(
N
-
1
))
return
y
hw
=
hamming_window
image
=
numpy
.
array
([[(
255
-
0
*
25
)
*
hw
(
i
,
512
)
*
hw
(
j
,
512
)
for
i
in
range
(
512
)]
for
j
in
range
(
512
)],
numpy
.
float32
)
image
=
image
[
numpy
.
newaxis
,
...
]
ijtags
=
imagej_metadata_tags
({
'Labels'
:[
"Name1"
,
"Name2"
,
"Name3"
,
"Name4"
,
"Name5"
]},
'<'
)
with
tifffile
.
TiffWriter
(
"multipage_test.tiff"
,
bigtiff
=
False
,
imagej
=
True
)
as
tif
:
for
i
in
range
(
5
):
tif
.
save
(
image
,
metadata
=
{
'version'
:
'20180905'
,
'loop'
:
False
},
extratags
=
ijtags
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment