Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NutriMorph
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
DEBREUVE Eric
NutriMorph
Commits
3b79f558
Commit
3b79f558
authored
5 years ago
by
NADAL Morgane
Browse files
Options
Downloads
Patches
Plain Diff
modif FindVoxelDimensionInMicrons() w/ re expression + try-except
parent
0aa2d768
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
brick/processing/input.py
+32
-20
32 additions, 20 deletions
brick/processing/input.py
nutrimorph.py
+1
-1
1 addition, 1 deletion
nutrimorph.py
parameters.py
+1
-0
1 addition, 0 deletions
parameters.py
with
34 additions
and
21 deletions
brick/processing/input.py
+
32
−
20
View file @
3b79f558
...
@@ -34,6 +34,9 @@ import numpy as np_
...
@@ -34,6 +34,9 @@ import numpy as np_
import
sys
as
sy_
import
sys
as
sy_
from
PIL
import
Image
from
PIL
import
Image
from
PIL.ExifTags
import
TAGS
from
PIL.ExifTags
import
TAGS
import
re
size_voxel_in_micron
=
None
def
ImageVerification
(
image
:
array_t
,
channel
:
str
)
->
array_t
:
def
ImageVerification
(
image
:
array_t
,
channel
:
str
)
->
array_t
:
...
@@ -70,6 +73,10 @@ def ImageVerification(image: array_t, channel: str) -> array_t:
...
@@ -70,6 +73,10 @@ def ImageVerification(image: array_t, channel: str) -> array_t:
def
IntensityNormalizedImage
(
image
:
array_t
)
->
array_t
:
def
IntensityNormalizedImage
(
image
:
array_t
)
->
array_t
:
'''
Relative normalization of the image between 0 and 1.
No division per 0 since the image should not be constant (ImageVerification function).
'''
#
#
print
(
'
Relative Intensity Normalization between 0 and 1. Need to reevaluate the parameters !!!
'
)
print
(
'
Relative Intensity Normalization between 0 and 1. Need to reevaluate the parameters !!!
'
)
...
@@ -94,30 +101,35 @@ def IntensityNormalizedImage(image: array_t) -> array_t:
...
@@ -94,30 +101,35 @@ def IntensityNormalizedImage(image: array_t) -> array_t:
# return result
# return result
def
VoxelDimensionInMicrons
(
data_path
:
str
)
->
array_t
:
def
FindVoxelDimensionInMicrons
(
data_path
:
str
)
->
array_t
:
# TODO Verify if metadata are in the same format for all the images - if not, add a raise error ?
#
if
size_voxel_in_micron
is
not
None
:
return
np_
.
array
(
size_voxel_in_micron
)
else
:
print
(
'
The size of a voxel is not specified in the parameters.
'
)
try
:
with
Image
.
open
(
data_path
)
as
img
:
# Find the voxels dimensions in micron in the metadata.
meta_dict
=
{
TAGS
.
get
(
key
,
'
missing
'
):
img
.
tag
[
key
]
for
key
in
img
.
tag
}
# Use the exif tags into the image metadata
with
Image
.
open
(
data_path
)
as
img
:
# Find the voxels dimensions in micron in the metadata.
# Decode the tags text
meta_dict
=
{
TAGS
.
get
(
key
,
'
missing
'
):
img
.
tag
[
key
]
for
key
in
metadata
=
meta_dict
[
'
missing
'
].
decode
(
'
utf8
'
)
# Decode the tags text
img
.
tag
}
# Use the exif tags into the image metadata
metadata
=
metadata
.
replace
(
'
\x00
'
,
''
)
# Decode the tags text
voxel_size
=
[]
# Initialize the list of voxel size in str
metadata
=
meta_dict
[
'
missing
'
].
decode
(
'
utf8
'
)
# Decode the tags text
for
axe
in
'
XYZ
'
:
metadata
=
metadata
.
replace
(
'
\x00
'
,
''
)
pattern
=
'
Voxel
'
+
axe
+
'
.+\= (\d.+E.\d.)
'
# Regular expression
voxel_size
.
append
(
re
.
findall
(
pattern
,
metadata
)[
0
])
voxel_size
=
[
''
,
''
,
''
]
# Initialize the list of voxel size in str
voxel_size
=
np_
.
array
(
list
(
map
(
float
,
voxel_size
)))
for
idaxe
,
axe
in
enumerate
(
'
XYZ
'
):
voxel_size_microns
=
1.0e6
*
voxel_size
idvox
=
metadata
.
find
(
'
dblVoxel
'
+
axe
)
# Get the index of the voxel size for the axe X, Y, Z
print
(
'
Voxel dimension in the image is [X Y Z] =
'
,
voxel_size_microns
,
'
in microns.
'
)
idvox
+=
15
return
voxel_size_microns
while
metadata
[
idvox
]
!=
'
\n
'
:
voxel_size
[
idaxe
]
+=
metadata
[
idvox
]
idvox
+=
1
voxel_size
=
np_
.
asarray
(
list
(
map
(
float
,
voxel_size
)))
voxel_size_microns
=
1.0e6
*
voxel_size
print
(
'
Voxel dimension in the image is [X Y Z] =
'
,
voxel_size_microns
,
'
in microns. WARNING this method highly
'
'
depends on the format of the metadata.
'
)
return
voxel_size_microns
except
:
print
(
'
Unable to find the voxel dimensions in micron in the metadata. Please specify it in the parameters.
'
)
def
ToPixels
(
micron
:
float
,
voxel_size_microns
:
array_t
)
->
int
:
def
ToPixels
(
micron
:
float
,
voxel_size_microns
:
array_t
)
->
int
:
...
...
This diff is collapsed.
Click to expand it.
nutrimorph.py
+
1
−
1
View file @
3b79f558
...
@@ -89,7 +89,7 @@ start_time = tm_.time()
...
@@ -89,7 +89,7 @@ start_time = tm_.time()
# --- Images
# --- Images
voxel_micron
=
in_
.
VoxelDimensionInMicrons
(
data_path
)
voxel_micron
=
in_
.
Find
VoxelDimensionInMicrons
(
data_path
)
image
=
io_
.
imread
(
data_path
)
image
=
io_
.
imread
(
data_path
)
...
...
This diff is collapsed.
Click to expand it.
parameters.py
+
1
−
0
View file @
3b79f558
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
data_path
=
"
./data/DIO_6H_6_1.70bis_2.2_3.tif
"
data_path
=
"
./data/DIO_6H_6_1.70bis_2.2_3.tif
"
channel
=
'
G
'
channel
=
'
G
'
size_voxel_in_micron
=
None
# -> list [X,Y,Z]
with_plot
=
True
with_plot
=
True
soma_low_c
=
0.15
soma_low_c
=
0.15
...
...
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