Conversation
…lations - Implemented `get_morphology` method in `RectangleAnnotation` to calculate and return various shape metrics. - Enhanced `PolygonAnnotation` to include orientation and bounding box dimensions in its morphology metrics. - Introduced `ExportSpatialMetrics` dialog for exporting spatial metrics of annotations to CSV, allowing users to select images, labels, annotation types, and metrics. - Updated `ConfidenceWindow` to display additional morphology metrics including orientation, compactness, elongation, rectangularity, and eccentricity. - Modified `MainWindow` to integrate the new spatial metrics export functionality into the UI. - Ensured compatibility with existing annotation types and metrics, providing a comprehensive export feature for spatial analysis.
Summary of ChangesHello @Jordan-Pierce, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the application's annotation analysis and data export capabilities. It introduces a richer set of morphology metrics for various annotation types, improving the descriptive power of annotations. Furthermore, it bolsters the robustness of polygon operations and expands the range of available transformer models for advanced image processing. The most notable addition is a new, dedicated CSV export feature for spatial metrics, allowing users to extract detailed quantitative data about their annotations with flexible filtering options. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new spatial metrics export feature and enhances morphology calculations. The changes are well-structured, especially the new ExportSpatialMetrics dialog. I've found a few critical issues in the new export logic related to unit conversions for volume and surface area calculations that will lead to incorrect results. I've also identified an incorrect calculation for pixel-based metrics. Additionally, there's an opportunity to refactor some new methods in QtAnnotation.py to improve maintainability by reducing code duplication.
| # 3D Metrics | ||
| elif metric == 'volume': | ||
| if z_channel is not None and has_scale: | ||
| volume = annotation.get_scaled_volume(z_channel, scale_x, scale_y, z_unit) |
There was a problem hiding this comment.
There's a unit mismatch when calling get_scaled_volume. This method expects the scale factors (scale_x, scale_y) to be in meters per pixel, as per its docstring. However, the code passes annotation.scale_x and annotation.scale_y directly, which are in scale_units per pixel (e.g., cm/pixel). This will lead to incorrect volume calculations if the scale units are not meters.
You should convert scale_x and scale_y to meters/pixel before passing them to this function. You've already calculated to_meters_factor which can be used for this conversion.
| volume = annotation.get_scaled_volume(z_channel, scale_x, scale_y, z_unit) | |
| volume = annotation.get_scaled_volume(z_channel, scale_x * to_meters_factor, scale_y * to_meters_factor, z_unit) |
| pixel_value = volume / (scale_x * scale_y * (to_meters_factor ** 2)) | ||
| elif metric == 'surface_area': | ||
| if z_channel is not None and has_scale: | ||
| surf_area = annotation.get_scaled_surface_area(z_channel, scale_x, scale_y, z_unit) |
There was a problem hiding this comment.
Similar to the volume calculation, there's a unit mismatch when calling get_scaled_surface_area. This method expects scale factors in meters per pixel, but is being passed values in scale_units per pixel. This will result in incorrect surface area values. Please convert the scales to meters/pixel before the call.
| surf_area = annotation.get_scaled_surface_area(z_channel, scale_x, scale_y, z_unit) | |
| surf_area = annotation.get_scaled_surface_area(z_channel, scale_x * to_meters_factor, scale_y * to_meters_factor, z_unit) |
| # Volume is already in the correct units | ||
| meter_value = volume | ||
| # Calculate pixel equivalent (approximation) | ||
| pixel_value = volume / (scale_x * scale_y * (to_meters_factor ** 2)) |
There was a problem hiding this comment.
The calculation for the "pixel equivalent" of volume is dimensionally incorrect. The expression volume / (scale_x * scale_y * (to_meters_factor ** 2)) results in units of m * px^2, not a pixel-based volume. A more direct pixel-based volume would be the sum of z-values in pixels over the annotation area. You can get the pixel z-values from annotation._get_raster_slice_and_mask(z_channel) and sum them.
The same issue exists for surface_area on line 650.
…hape camera imports
…p in deployment dialog
…spinbox range in deployment dialog
…proximations in spatial metrics export
This pull request introduces several enhancements and fixes across annotation morphology metrics, polygon operations, transformer model selection, and IO exports. The main changes expand the set of computed morphology metrics for annotations, improve polygon merging robustness, add new transformer models (including conditional support for DINOv3), and introduce a new export option for spatial metrics.
Morphology Metrics Enhancements:
QtAnnotation.pyto include orientation, bounding box width/height, elongation, eccentricity, rectangularity, and compactness. These are now calculated and stored for all applicable annotation types. [1] [2] [3] [4]QtPolygonAnnotation.pyandQtRectangleAnnotation.pyto provide these new raw metrics for use in the base morphology calculation, ensuring rectangles and polygons both report the expanded set of metrics. [1] [2] [3] [4]Polygon Annotation Robustness:
Transformer Model Selection:
Spatial Metrics Export:
ExportSpatialMetrics, in the IO module to enable exporting of spatial metrics. [1] [2]Other Improvements:
get_min_zandget_max_zmethods toQtAnnotation.pyfor retrieving minimum and maximum z-values within an annotation, supporting conversion to real-world units.to_dictandto_coralnetmethods inQtAnnotation.pyby removing redundant area and perimeter fields, relying on morphology for these values. [1] [2]