Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python-imcflibs
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
imcf
python-imcflibs
Commits
fd63418a
Commit
fd63418a
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add imagej.bioformats module
parent
49f6011d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/imcflibs/imagej/__init__.py
+0
-0
0 additions, 0 deletions
src/imcflibs/imagej/__init__.py
src/imcflibs/imagej/bioformats.py
+103
-0
103 additions, 0 deletions
src/imcflibs/imagej/bioformats.py
with
103 additions
and
0 deletions
src/imcflibs/imagej/__init__.py
0 → 100644
+
0
−
0
View file @
fd63418a
This diff is collapsed.
Click to expand it.
src/imcflibs/imagej/bioformats.py
0 → 100644
+
103
−
0
View file @
fd63418a
"""
Bio-Formats related helper functions.
NOTE: this is *NOT* about using [python-bioformats][1] but rather about calling
the corresponding functions provided by ImageJ.
[1]: https://pypi.org/project/python-bioformats/
"""
import
os
from
ij
import
IJ
from
loci.plugins
import
BF
from
loci.plugins.in
import
ImporterOptions
from
..pathtools
import
image_basename
def
import_image
(
filename
,
color_mode
=
'
color
'
,
split_c
=
False
,
split_z
=
False
,
split_t
=
False
):
"""
Open an image file using the Bio-Formats importer.
Parameters
----------
filename : str
The full path to the file to be imported through Bio-Formats.
color_mode : str, optional
The color mode to be used for the resulting ImagePlus, one of
'
color
'
,
'
composite
'
,
'
gray
'
and
'
default
'
.
split_c : bool, optional
Whether to split the channels into separate ImagePlus objects.
split_z : bool, optional
Whether to split the z-slices into separate ImagePlus objects.
split_t : bool, optional
Whether to split the time points into separate ImagePlus objects.
Returns
-------
ij.ImagePlus[]
A list of ImagePlus objects resulting from the import.
"""
options
=
ImporterOptions
()
mode
=
{
'
color
'
:
ImporterOptions
.
COLOR_MODE_COLORIZED
,
'
composite
'
:
ImporterOptions
.
COLOR_MODE_COMPOSITE
,
'
gray
'
:
ImporterOptions
.
COLOR_MODE_GRAYSCALE
,
'
default
'
:
ImporterOptions
.
COLOR_MODE_DEFAULT
,
}
options
.
setColorMode
(
mode
[
color_mode
])
options
.
setSplitChannels
(
split_c
)
options
.
setSplitFocalPlanes
(
split_z
)
options
.
setSplitTimepoints
(
split_t
)
options
.
setId
(
filename
)
# log.info("Reading [%s]" % filename)
orig_imps
=
BF
.
openImagePlus
(
options
)
return
orig_imps
def
export
(
imp
,
filename
):
"""
Simple wrapper to export an image to a given file.
Parameters
----------
imp : ImagePlus
The ImagePlus object to be exported by Bio-Formats.
filename : str
The output filename, may include a full path.
"""
# log.info("Exporting to [%s]" % out_file)
IJ
.
run
(
imp
,
"
Bio-Formats Exporter
"
,
"
save=[
"
+
filename
+
"
]
"
)
# log.debug("Exporting finished.")
def
export_using_orig_name
(
imp
,
path
,
orig_name
,
tag
,
suffix
):
"""
Export an image to a given path, deriving the name from the input file.
The input filename is stripped to its pure file name, without any path or
suffix components, then an optional tag (e.g.
"
-avg
"
) and the new format
suffix is added.
Parameters
----------
imp : ImagePlus
The ImagePlus object to be exported by Bio-Formats.
path : str or object that can be cast to a str
The output path.
orig_name : str or object that can be cast to a str
The input file name, may contain arbitrary path components.
tag : str
An optional tag to be added at the end of the new file name, can be used
to denote information like
"
-avg
"
for an average projection image.
suffix : str
The new file name suffix, which also sets the file format for BF.
Returns
-------
out_file : str
The full name of the exported file.
"""
out_file
=
os
.
path
.
join
(
path
,
image_basename
(
orig_name
)
+
tag
+
suffix
)
export
(
imp
,
out_file
)
return
out_file
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