Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SofastFixed point light #66

Merged
merged 17 commits into from
Apr 4, 2024

Conversation

braden6521
Copy link
Collaborator

  • Updated the SofastFixed unit test data to use data captured with a point light near the center origin dot when using a printed, fixed pattern.
  • Added more unit tests to the sofast/lib/image_processing library that contains the blob detection functions.
  • Added an example that creates a measurement object from an image, finds the origin blob, and saves to HDF5 file.

@braden6521 braden6521 self-assigned this Apr 2, 2024
@braden6521 braden6521 requested a review from bbean23 April 2, 2024 17:44
@braden6521 braden6521 force-pushed the sofast_fixed_point_light branch from 13177e7 to f4a7ed1 Compare April 3, 2024 00:30
bbean23
bbean23 previously approved these changes Apr 3, 2024
Copy link
Collaborator

@bbean23 bbean23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a few comments. Feel free to take them or leave them.

@@ -422,8 +424,8 @@ def rectangle_loop_from_two_points(p1: Vxy, p2: Vxy, d_ax: float, d_perp: float)
# Calculate axial and perpendicular directions
v_axial = (p2 - p1).normalize()

R = np.array([[0, 1], [-1, 0]])
v_perp = v_axial.rotate(R)
rot_mat_90 = np.array([[0, 1], [-1, 0]])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥳

Parameters
----------
image : np.ndarray
Input image, uint8
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably this should be a 2d image with a single color channel? AKA:

2D input image, single color channel, NxM or NxMx1, uint8

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Changed!

@@ -228,6 +235,50 @@ def test_calculate_active_pixel_pointing_vectors(self):
# Test
np.testing.assert_allclose(data['u_pixel_pointing_facet'], u_pixel_pointing_optic)

def test_detect_blobs(self):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit tests! 🥳

lt.logger(join(dir_save, 'log.txt'), lt.log.INFO)

# 1. Load image
# =============
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't considered also including this style of visual separator. Makes this really easy to read!

# =============
file_meas = join(opencsp_code_dir(), 'test/data/sofast_fixed/data_measurement/measurement_facet.h5')
measurement_old = MeasurementSofastFixed.load_from_hdf(file_meas)
image = measurement_old.image
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's silly, but it might make this more useful as an example if there were some commented out code for loading the image using opencv or pillow, as if you have an image jpg file instead of a measurement h5 file.

# image = cv2.imread(file_jpg, cv2.IMREAD_GRAYSCALE)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it! Added!

# ================================

# Find point light
params = cv.SimpleBlobDetector_Params()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea time! It would be nice if you could retrieve these parameters from image_processing with some values such as filterByCircularity set for you:

params = ip.dot_target_blob_params(minDistBetweenBlobs=2, minArea=3, maxArea=30)

def dot_target_blob_params(
    minDistBetweenBlobs=2,
    filterByArea=True,
    minArea=3,
    maxArea=30,
    filterByCircularity=True,
    minCircularity=0.8,
    filterByConvexity=False,
    filterByInertia=False,
):
    params = cv.SimpleBlobDetector_Params()
    params.minDistBetweenBlobs = minDistBetweenBlobs
    params.filterByArea = filterByArea
    params.minArea = minArea
    params.maxArea = maxArea
    params.filterByCircularity = filterByCircularity
    params.minCircularity = minCircularity
    params.filterByConvexity = filterByConvexity
    params.filterByInertia = filterByInertia
    return params

To be clear, not necessary for this PR, and not necessary generally. Just an idea.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an interesting idea! There are other inputs that SimpleBlobDetector_Params takes that I haven't typically used. Perhaps have a default_blob_detector_params() function or something? I'll have to think about how best to implement it, but I do really like it. Will probably wait until a future PR.

# =======================================
image_annotated = ip.detect_blobs_inverse_annotate(image, params)

figure_control = rcfg.RenderControlFigure(tile_array=(1, 1), tile_square=True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unified render control style! 👍

@braden6521
Copy link
Collaborator Author

@bbean23, thanks for the review! I implemented some of your suggestions, ready for re-review!

Copy link
Collaborator

@bbean23 bbean23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved!

@braden6521 braden6521 merged commit c3128f0 into sandialabs:develop Apr 4, 2024
4 checks passed
@braden6521 braden6521 deleted the sofast_fixed_point_light branch April 15, 2024 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants