Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Vasudevan, Rama K
pycroscopy
Commits
323a942f
Commit
323a942f
authored
Nov 21, 2017
by
Unknown
Browse files
Image Cleaning notebook update
parent
3e8f0ff2
Changes
1
Show whitespace changes
Inline
Side-by-side
jupyter_notebooks/Image_Cleaning_Atom_Finding.ipynb
View file @
323a942f
...
...
@@ -516,11 +516,11 @@
We want a large enough number of clusters so that K-means identifies fine nuances in the data. At the same time, we want to minimize computational time by reducing the number of clusters. We recommend 32 - 64 clusters.
%% Cell type:code id: tags:
```
python
clean_components
=
1
2
clean_components
=
3
2
num_clusters
=
32
# Check for existing Clustering results
estimator
=
px
.
Cluster
(
h5_U
,
'KMeans'
,
num_comps
=
clean_components
,
n_clusters
=
num_clusters
)
do_cluster
=
False
...
...
@@ -543,11 +543,11 @@
if
new_clean
.
step
is
None
:
new_clean
=
range
(
new_clean
.
start
,
new_clean
.
stop
)
else
:
new_clean
=
range
(
new_clean
.
start
,
new_clean
.
stop
,
new_clean
.
step
)
if
a
l
l
(
h5_kmeans
.
attrs
[
'components_used'
]
==
new_clean
):
if
np
.
array_equ
al
(
h5_kmeans
.
attrs
[
'components_used'
]
,
new_clean
):
print
(
'Clustering results used the same components as those requested.'
)
else
:
do_cluster
=
True
print
(
'Clustering results used the different components from those requested.'
)
...
...
@@ -615,16 +615,10 @@
fig
.
axes
[
0
].
set_xlabel
(
'Cluster number'
,
fontsize
=
20
)
fig
.
axes
[
0
].
set_ylabel
(
'Cluster separation'
,
fontsize
=
20
)
px
.
plot_utils
.
set_tick_font_size
(
fig
.
axes
[
0
],
12
)
```
%% Cell type:code id: tags:
```
python
vert_line
.
get_xdata
()
```
%% Cell type:markdown id: tags:
## Identifiying the principal patterns
Here, we will interactively identify N windows, each centered on a distinct class / kind of atom.
...
...
@@ -742,25 +736,25 @@
for
window_center
,
ax_row
in
zip
(
motif_win_centers
,
np
.
atleast_2d
(
axes
)):
indices
=
(
slice
(
window_center
[
0
]
-
half_wind
,
window_center
[
0
]
+
half_wind
),
slice
(
window_center
[
1
]
-
half_wind
,
window_center
[
1
]
+
half_wind
))
motifs
.
append
(
labels_mat
[
indices
])
ax_row
[
0
].
hold
(
True
)
#
ax_row[0].hold(True)
ax_row
[
0
].
imshow
(
cropped_clean_image
,
interpolation
=
'none'
,
cmap
=
px
.
plot_utils
.
cmap_jet_white_center
(),
origin
=
'lower'
)
ax_row
[
0
].
add_patch
(
patches
.
Rectangle
((
window_center
[
1
]
-
int
(
0.5
*
motif_win_size
),
window_center
[
0
]
-
int
(
0.5
*
motif_win_size
)),
motif_win_size
,
motif_win_size
,
fill
=
False
,
color
=
'black'
,
linewidth
=
2
))
ax_row
[
0
].
hold
(
False
)
ax_row
[
1
].
hold
(
True
)
#
ax_row[0].hold(False)
#
ax_row[1].hold(True)
ax_row
[
1
].
imshow
(
cropped_clean_image
[
indices
],
interpolation
=
'none'
,
cmap
=
px
.
plot_utils
.
cmap_jet_white_center
(),
vmax
=
np
.
max
(
cropped_clean_image
),
vmin
=
np
.
min
(
cropped_clean_image
),
origin
=
'lower'
)
ax_row
[
1
].
plot
([
0
,
motif_win_size
-
2
],[
int
(
0.5
*
motif_win_size
),
int
(
0.5
*
motif_win_size
)],
'k--'
)
ax_row
[
1
].
plot
([
int
(
0.5
*
motif_win_size
),
int
(
0.5
*
motif_win_size
)],
[
0
,
motif_win_size
-
2
],
'k--'
)
# ax_row[1].axis('tight')
ax_row
[
1
].
set_title
(
'Selected window for motif around (row {}, col {})'
.
format
(
window_center
[
0
],
window_center
[
1
]))
ax_row
[
1
].
hold
(
False
)
#
ax_row[1].hold(False)
ax_row
[
2
].
imshow
(
labels_mat
[
indices
],
interpolation
=
'none'
,
cmap
=
px
.
plot_utils
.
cmap_jet_white_center
(),
vmax
=
num_clusters
-
1
,
vmin
=
0
,
origin
=
'lower'
)
ax_row
[
2
].
set_title
(
'Motif from K-means labels'
);
```
...
...
@@ -801,20 +795,20 @@
```
python
show_legend
=
True
base_color_map
=
plt
.
cm
.
get_cmap
(
'jet'
)
fig
=
plt
.
figure
(
figsize
=
(
8
,
8
))
im
=
plt
.
imshow
(
double_cropped_image
,
cmap
=
"gray"
,
origin
=
'lower'
)
plt
.
imshow
(
double_cropped_image
,
cmap
=
"gray"
,
origin
=
'lower'
)
if
num_motifs
>
1
:
motif_colors
=
[
base_color_map
(
int
(
255
*
motif_ind
/
(
num_motifs
-
1
)))
for
motif_ind
in
range
(
num_motifs
)]
else
:
motif_colors
=
[
base_color_map
(
0
)]
handles
=
list
()
for
motif_ind
,
current_solid_color
,
match_mat
in
zip
(
range
(
num_motifs
),
motif_colors
,
motif_match_coeffs
):
my_cmap
=
px
.
plot_utils
.
make_linear_alpha_cmap
(
'fdfd'
,
current_solid_color
,
1
)
im
=
plt
.
imshow
(
match_mat
,
cmap
=
my_cmap
,
origin
=
'lower'
);
plt
.
imshow
(
match_mat
,
cmap
=
my_cmap
,
origin
=
'lower'
);
current_solid_color
=
list
(
current_solid_color
)
current_solid_color
[
3
]
=
0.5
# maximum alpha value
handles
.
append
(
patches
.
Patch
(
color
=
current_solid_color
,
label
=
'Motif {}'
.
format
(
motif_ind
)))
if
show_legend
:
plt
.
legend
(
handles
=
handles
,
bbox_to_anchor
=
(
1.01
,
1
),
loc
=
2
,
borderaxespad
=
0.
,
fontsize
=
14
)
...
...
@@ -842,14 +836,15 @@
thresholds
=
[
0.25
for
x
in
range
(
num_motifs
)]
thresholded_maps
=
list
()
motif_imgs
=
list
()
base_color_map
=
plt
.
cm
.
jet
fig
,
axis
=
plt
.
subplots
(
figsize
=
(
10
,
10
))
plt
.
hold
(
True
);
fig
=
plt
.
figure
(
figsize
=
(
10
,
10
))
plt
.
imshow
(
double_cropped_image
,
cmap
=
"gray"
)
axis
=
plt
.
gca
()
handles
=
list
()
if
num_motifs
>
1
:
motif_colors
=
[
base_color_map
(
int
(
255
*
motif_ind
/
(
num_motifs
-
1
)))
for
motif_ind
in
range
(
num_motifs
)]
else
:
motif_colors
=
[
base_color_map
(
0
)]
...
...
@@ -868,11 +863,10 @@
axis
.
set_xticklabels
([])
axis
.
set_yticklabels
([])
axis
.
get_xaxis
().
set_visible
(
False
)
axis
.
get_yaxis
().
set_visible
(
False
)
plt
.
legend
(
handles
=
handles
,
bbox_to_anchor
=
(
1.01
,
1
),
loc
=
2
,
borderaxespad
=
0.
)
plt
.
hold
(
False
);
def
threshold_images
(
thresholds
):
# thresholded_maps = list()
# empty the thresholded maps:
del
thresholded_maps
[:]
...
...
@@ -925,11 +919,11 @@
%% Cell type:code id: tags:
```
python
# overlay atom positions on original image
fig
,
axis
=
plt
.
subplots
(
figsize
=
(
8
,
8
))
axis
.
hold
(
True
)
col_map
=
plt
.
cm
.
jet
axis
.
imshow
(
double_cropped_image
,
interpolation
=
'none'
,
cmap
=
"gray"
)
legend_handles
=
list
()
for
atom_type_ind
,
atom_centroids
in
enumerate
(
atom_labels
):
axis
.
scatter
(
atom_centroids
[:,
1
],
atom_centroids
[:,
0
],
color
=
col_map
(
int
(
255
*
atom_type_ind
/
(
num_motifs
-
1
))),
...
...
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