Skip to content

Speed updates #1126

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

Merged
merged 14 commits into from
Aug 15, 2025
Merged

Speed updates #1126

merged 14 commits into from
Aug 15, 2025

Conversation

AdvancedImagingUTSW
Copy link
Collaborator

The time to display_image has improved.

On my computer, it is taking 21.57 ms, with a std dev of 3.8 ms.

Develop is currently 31.64 ms, with a std. dev. of 5.68 ms.

Updated image scaling and LUT application methods to consistently use 8-bit (uint8) image data, removing unnecessary dtype conversions. Crosshair drawing now sets pixel values to 255 instead of 1 for proper visibility. This improves performance and ensures compatibility with OpenCV color mapping functions.
Refactored camera view controller to optimize LUT application using numpy for faster image processing and added debounced min/max updates. Improved VariableWithLock in common_functions.py with type annotations and enhanced docstrings for better thread safety and clarity.
Introduces a single-slot queue and persistent worker thread for image display, dropping stale frames. Refactors image processing logic into a new render() method, separating processing from display and updating usage in CameraViewController to avoid direct Tkinter calls outside the main loop.
Replaced time.time() with time.perf_counter() for more accurate timing. Improved max intensity history recording by using cached frame max if available, reducing redundant calculations.
@AdvancedImagingUTSW AdvancedImagingUTSW requested review from Copilot and annie-xd-wang and removed request for Copilot August 9, 2025 03:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements performance optimizations for the image display functionality, reducing display time from ~31.64ms to ~21.57ms. The changes focus on improving the colormap lookup table (LUT) application and introducing a dedicated display worker thread to handle frame rendering more efficiently.

Key changes include:

  • Replaced cv2.applyColorMap with direct numpy indexing for faster LUT application
  • Introduced a single-threaded display worker with frame dropping to maintain UI responsiveness
  • Added debouncing for min/max control updates to reduce unnecessary recomputations

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
src/navigate/tools/common_functions.py Added type hints and documentation to improve code maintainability
src/navigate/controller/sub_controllers/camera_view.py Implemented performance optimizations for image display including LUT buffer reuse, display worker thread, and debounced UI updates

Introduces max_fps and frame interval logic to limit the rate at which frames are enqueued for display, improving UI responsiveness and preventing overload. Also ensures dropped frames are replaced with the most recent frame, and fixes flat image generation to return a white image instead of black.
@AdvancedImagingUTSW
Copy link
Collaborator Author

Most recent commit...
Mean (ms): 17.690825688073396,
max (ms): 52.0,
min (ms): 3.6,
std. dev. (ms): 6.57829682567923

Last night's commit...
Mean (ms): 24.597590361445786,
max (ms): 40.599999999999994,
min (ms): 16.2,
std. dev. (ms): 3.847171146459418

clipboard5

@AdvancedImagingUTSW
Copy link
Collaborator Author

One issue that I just remembered to post. I definitely broke the ability to overlay a mask. We will have to discuss this.

Copy link

codecov bot commented Aug 11, 2025

Codecov Report

❌ Patch coverage is 82.73381% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 53.91%. Comparing base (2646712) to head (82956d7).
⚠️ Report is 27 commits behind head on develop.

Files with missing lines Patch % Lines
...navigate/controller/sub_controllers/camera_view.py 81.67% 24 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1126      +/-   ##
===========================================
- Coverage    54.00%   53.91%   -0.09%     
===========================================
  Files          191      191              
  Lines        21785    21953     +168     
===========================================
+ Hits         11765    11837      +72     
- Misses       10020    10116      +96     
Flag Coverage Δ
unittests 53.91% <82.73%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@AdvancedImagingUTSW AdvancedImagingUTSW merged commit 5fb486e into develop Aug 15, 2025
1 check passed
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