Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Olena
pylene
Commits
0b45cd9c
Commit
0b45cd9c
authored
Oct 07, 2021
by
Baptiste Esteban
Browse files
Start a program generating illustrations for the MToS
parent
c20f011c
Pipeline
#30501
passed with stages
in 24 minutes and 19 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
doc/source/snippets/CMakeLists.txt
View file @
0b45cd9c
...
...
@@ -64,6 +64,8 @@ add_image("watershed_hierarchy_example" "${PYLENE_IMAGE_DIR}/lena.pgm" watershed
add_image
(
"saliency_example"
"
${
PYLENE_IMAGE_DIR
}
/lena.pgm"
saliency_watershed.png
)
add_image
(
"mtos_example"
"
${
PYLENE_IMAGE_DIR
}
/lena.ppm"
depth_map.png
)
add_custom_target
(
build-images
DEPENDS
"
${
DOCUMENTATION_IMAGES
}
"
)
...
...
@@ -88,5 +90,6 @@ add_executable(area_filter area_filter.cpp)
add_executable
(
cdt cdt.cpp
)
add_executable
(
first_start_1 first_start_1.cpp
)
add_executable
(
intro-1 intro-1.cpp
)
add_executable
(
mtos_example mtos_example.cpp
)
target_compile_definitions
(
erosion-cli PRIVATE BOOST_ALL_NO_LIB
)
\ No newline at end of file
doc/source/snippets/mtos_example.cpp
0 → 100644
View file @
0b45cd9c
#include
<mln/core/colors.hpp>
#include
<mln/core/image/ndimage.hpp>
#include
<mln/core/image/view/channel.hpp>
#include
<mln/core/image/view/transform.hpp>
#include
<mln/io/imread.hpp>
#include
<mln/io/imsave.hpp>
#include
<mln/morpho/tos.hpp>
#include
<mln/morpho/private/trees_fusion.hpp>
#include
<iostream>
#include
<vector>
#include
"lut.hpp"
namespace
{
mln
::
image2d
<
mln
::
rgb8
>
add_border
(
mln
::
image2d
<
mln
::
rgb8
>
ima
)
{
mln
::
image2d
<
mln
::
rgb8
>
res
(
ima
.
width
()
+
2
,
ima
.
height
()
+
2
);
std
::
vector
<
mln
::
rgb8
>
border
;
border
.
reserve
(
2
*
ima
.
width
()
+
2
*
ima
.
height
()
-
4
);
mln_foreach
(
auto
p
,
ima
.
domain
())
res
(
mln
::
point2d
{
1
,
1
}
+
p
)
=
ima
(
p
);
for
(
int
i
=
0
;
i
<
ima
.
width
();
i
++
)
{
border
.
push_back
(
ima
(
mln
::
point2d
{
i
,
0
}));
border
.
push_back
(
ima
(
mln
::
point2d
{
i
,
ima
.
height
()
-
1
}));
}
for
(
int
i
=
1
;
i
<
ima
.
height
()
-
1
;
i
++
)
{
border
.
push_back
(
ima
(
mln
::
point2d
{
0
,
i
}));
border
.
push_back
(
ima
(
mln
::
point2d
{
ima
.
width
()
-
1
,
i
}));
}
std
::
sort
(
border
.
begin
(),
border
.
end
(),
[](
const
mln
::
rgb8
&
a
,
const
mln
::
rgb8
&
b
)
{
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
if
(
a
[
i
]
<
b
[
i
])
return
true
;
else
if
(
b
[
i
]
<
a
[
i
])
return
false
;
}
return
false
;
});
mln
::
rgb8
med
=
border
[
border
.
size
()
/
2
];
for
(
int
i
=
0
;
i
<
res
.
width
();
i
++
)
{
res
(
mln
::
point2d
{
i
,
0
})
=
med
;
res
(
mln
::
point2d
{
i
,
res
.
height
()
-
1
})
=
med
;
}
for
(
int
i
=
1
;
i
<
res
.
height
()
-
1
;
i
++
)
{
res
(
mln
::
point2d
{
0
,
i
})
=
med
;
res
(
mln
::
point2d
{
res
.
width
()
-
1
,
i
})
=
med
;
}
return
res
;
}
std
::
uint16_t
max
(
mln
::
image2d
<
std
::
uint16_t
>
ima
)
{
std
::
uint16_t
res
=
0
;
mln_foreach
(
auto
p
,
ima
.
domain
())
res
=
std
::
max
(
res
,
ima
(
p
));
return
res
;
}
}
// namespace
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
3
)
{
std
::
cerr
<<
"Invalid number of arguments
\n
Usage: "
<<
argv
[
0
]
<<
" input_filename depth_map_filename
\n
"
;
return
1
;
}
mln
::
image2d
<
mln
::
rgb8
>
ima
;
mln
::
io
::
imread
(
argv
[
1
],
ima
);
ima
=
add_border
(
ima
);
mln
::
morpho
::
component_tree
<>
trees
[
3
];
mln
::
image2d
<
int
>
nodemaps
[
3
];
std
::
vector
<
int
>
depths
[
3
];
for
(
int
c
=
0
;
c
<
3
;
c
++
)
{
std
::
tie
(
trees
[
c
],
nodemaps
[
c
])
=
mln
::
morpho
::
tos
(
mln
::
view
::
channel
(
ima
,
c
),
{
0
,
0
});
depths
[
c
]
=
trees
[
c
].
compute_depth
();
}
const
auto
[
gos
,
tree_to_graph
]
=
mln
::
morpho
::
details
::
compute_inclusion_graph
(
trees
,
nodemaps
,
depths
,
3
);
auto
depth_map
=
mln
::
morpho
::
details
::
compute_depth_map
(
gos
,
tree_to_graph
,
nodemaps
);
std
::
uint16_t
max_depth
=
max
(
depth_map
);
auto
normalized_depth
=
mln
::
view
::
transform
(
depth_map
,
[
&
max_depth
](
std
::
uint16_t
a
)
->
float
{
return
(
float
)
a
/
(
float
)
max_depth
;});
auto
heat_depth
=
mln
::
view
::
transform
(
normalized_depth
,
heat_lut
);
mln
::
io
::
imsave
(
heat_depth
,
argv
[
2
]);
return
0
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment