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
5dde41f8
Commit
5dde41f8
authored
6 years ago
by
Niko Ehrenfeuchter
Browse files
Options
Downloads
Patches
Plain Diff
Add 'imagej.split' module
parent
dab5faea
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
src/imcflibs/imagej/split.py
+44
-0
44 additions, 0 deletions
src/imcflibs/imagej/split.py
with
44 additions
and
0 deletions
src/imcflibs/imagej/split.py
0 → 100644
+
44
−
0
View file @
5dde41f8
"""
Functions for splitting channels and or slices.
"""
import
os
from
ij
import
IJ
,
ImagePlus
# pylint: disable-msg=E0401
from
ij.io
import
FileSaver
# pylint: disable-msg=E0401
from
ij.plugin
import
ChannelSplitter
# pylint: disable-msg=E0401
def
split_by_c_and_z
(
log
,
dname
,
imgf
,
skip_top
,
skip_bottom
):
"""
Helper function to open, split and save a file.
Load the file specified, split by channels and z-slices, create a directory
for each channel using the channel number as a name suffix and export
each slice as an individual TIF file.
Parameters
----------
log : logger or scijava-logservice
The logger object to be used for logging.
dname : str
The directory to load TIF files from.
imgf : str
The file name to load and split.
skip_top : int
Number of slices to skip at the top.
skip_bottom : int
Number of slices to skip at the bottom.
"""
log
.
info
(
"
Processing file [%s]
"
%
imgf
)
imp
=
IJ
.
openImage
(
dname
+
"
/
"
+
imgf
)
fname
=
os
.
path
.
splitext
(
imgf
)
channels
=
ChannelSplitter
().
split
(
imp
)
for
channel
in
channels
:
c_name
=
channel
.
getTitle
().
split
(
"
-
"
)[
0
]
tgt_dir
=
os
.
path
.
join
(
dname
,
fname
[
0
]
+
"
-
"
+
c_name
)
if
not
os
.
path
.
isdir
(
tgt_dir
):
os
.
mkdir
(
tgt_dir
)
stack
=
channel
.
getStack
()
for
z
in
range
(
1
+
skip_top
,
stack
.
getSize
()
+
1
-
skip_bottom
):
proc
=
stack
.
getProcessor
(
z
)
fout
=
"
%s/%s-z%s%s
"
%
(
tgt_dir
,
fname
[
0
],
z
,
fname
[
1
])
# fout = dname + "/" + c_name + "/" + fname[0] + "-z" + z + fname[1]
log
.
info
(
"
Writing channel %s, slice %s: %s
"
%
(
c_name
,
z
,
fout
))
FileSaver
(
ImagePlus
(
fname
[
0
],
proc
)).
saveAsTiff
(
fout
)
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