Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Pi-sensors
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hb2n21
Pi-sensors
Commits
a1199a39
Unverified
Commit
a1199a39
authored
10 months ago
by
HanBrady
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #17 from HanBrady/beam_widths
Manual beam width measurement
parents
cb483066
8d9a080e
Branches
main
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Scripts/manual_comp.py
+40
-25
40 additions, 25 deletions
Scripts/manual_comp.py
with
40 additions
and
25 deletions
Scripts/manual_comp.py
+
40
−
25
View file @
a1199a39
...
@@ -9,10 +9,6 @@ import imageio.v3 as iio
...
@@ -9,10 +9,6 @@ import imageio.v3 as iio
import
laserbeamsize
as
lbs
import
laserbeamsize
as
lbs
from
PIL
import
Image
from
PIL
import
Image
## Read in image as numpy array
#im_in = Image.open('laser_sim.png') # read in laser data
#im = np.asarray(im_in) # Could do this in one line with cv2?
## Locate peak x and y
## Locate peak x and y
def
beam_width_manual
(
image
,
axis_in
):
def
beam_width_manual
(
image
,
axis_in
):
...
@@ -27,19 +23,35 @@ def beam_width_manual(image, axis_in):
...
@@ -27,19 +23,35 @@ def beam_width_manual(image, axis_in):
"""
"""
im_in
=
Image
.
open
(
image
)
# read in laser data
im_in
=
Image
.
open
(
image
)
# read in laser data
im
=
np
.
asarray
(
im_in
)
im
=
np
.
asarray
(
im_in
)
print
(
im
)
if
axis_in
==
'
x
'
:
if
axis_in
==
'
x
'
:
axis
=
0
axis
=
0
max_point
=
np
.
argmax
(
im
,
axis
)
# find coord at peak
peak
=
np
.
max
(
max_point
)
print
(
'
peak:
'
,
peak
)
plot
=
im
[
peak
,
:,
0
]
#Plot line of pixels with max
plt
.
plot
(
plot
)
#determine fwhm
max_val
=
plot
[
peak
]
hm
=
int
(
max_val
/
2
)
hmx
=
plt
.
axhline
(
hm
,
color
=
'
black
'
)
plt
.
show
()
index1
=
np
.
where
(
plot
>=
hm
)
index
=
index1
[
0
]
width
=
index
[
-
1
]
-
index
[
0
]
print
(
f
'
Beam width (manual) is
{
width
}
pixels
'
)
elif
axis_in
==
'
y
'
:
elif
axis_in
==
'
y
'
:
axis
=
1
axis
=
1
else
:
raise
ValueError
(
'
Please input either x or y for axis_in
'
)
max_point
=
np
.
argmax
(
im
,
axis
)
# find coord at peak
max_point
=
np
.
argmax
(
im
,
axis
)
# find coord at peak
peak
=
np
.
max
(
max_point
)
peak
=
np
.
max
(
max_point
)
print
(
'
peak:
'
,
peak
)
plot
=
im
[:,
peak
,
0
]
#Plot line of pixels with max
#Plot line of pixels with max
plot
=
im
[
peak
,
:,
0
]
plt
.
plot
(
plot
)
plt
.
plot
(
plot
)
#determine fwhm
#determine fwhm
...
@@ -47,10 +59,13 @@ def beam_width_manual(image, axis_in):
...
@@ -47,10 +59,13 @@ def beam_width_manual(image, axis_in):
hm
=
int
(
max_val
/
2
)
hm
=
int
(
max_val
/
2
)
hmx
=
plt
.
axhline
(
hm
,
color
=
'
black
'
)
hmx
=
plt
.
axhline
(
hm
,
color
=
'
black
'
)
plt
.
show
()
plt
.
show
()
index1
=
np
.
where
(
plot
>=
hm
)
index1
=
np
.
where
(
plot
>=
hm
)
index
=
index1
[
0
]
index
=
index1
[
0
]
width
=
index
[
-
1
]
-
index
[
0
]
width
=
index
[
-
1
]
-
index
[
0
]
print
(
width
)
print
(
f
'
Beam width (manual) is
{
width
}
pixels
'
)
else
:
raise
ValueError
(
'
Please input either x or y for axis_in
'
)
return
width
return
width
...
@@ -81,10 +96,10 @@ def beam_width(image):
...
@@ -81,10 +96,10 @@ def beam_width(image):
print
(
"
The ellipse diameter (closest to vertical) is %.0f pixels
"
%
dy
)
print
(
"
The ellipse diameter (closest to vertical) is %.0f pixels
"
%
dy
)
print
(
"
The ellipse is rotated %.0f degrees ccw from the horizontal
"
%
(
phi
*
180
/
3.1416
))
print
(
"
The ellipse is rotated %.0f degrees ccw from the horizontal
"
%
(
phi
*
180
/
3.1416
))
beam_width_manual
(
'
laser_
beam.jp
g
'
,
'
x
'
)
beam_width_manual
(
'
laser_
sim.pn
g
'
,
'
x
'
)
#
beam_width_manual('
22.07_
laser
pic3
.png', 'y')
beam_width_manual
(
'
laser
_sim
.png
'
,
'
y
'
)
## Compare with lbs
## Compare with lbs
image
=
dithered
(
'
laser_
beam.jp
g
'
)
image
=
dithered
(
'
laser_
sim.pn
g
'
)
beam_width
(
image
)
beam_width
(
image
)
\ No newline at end of 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