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

"fix" jpg segmentations #5406

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

"fix" jpg segmentations #5406

wants to merge 1 commit into from

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented Jan 17, 2025

What changes are proposed in this pull request?

"fixes" jpg segmentations. It's fixed in a sense that something is rendered now as opposed to nothing; it's not fixed in a sense that using jpgs for segmentations might not be the wisest choice.

There are two possibilities of JPG masks:

  1. JPG segmentation mask + int mask targets: more of a valid real use case when customer is willing to trade off specificity offered by PNG for size and speed of JPG. The pixel values are usually slightly altered along contrast lines because of banding, so they will be rendered as background in the app. The intensity of the artifacts depends on JPG compression levels.

  2. JPG segmentation mask + RGB mask targets: while this will be technically supported, customers should expect major artifacts here. This is because JPG compression often involves some sort of color space conversion and it's impossible to map RGB mask targets to pixel values after color space conversion. These masks often might appear as mostly dark (background color).

2025-01-19 23 05 05

How is this patch tested? If it is not, please explain why.

(Details)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features

    • Enhanced segmentation processing capabilities
    • Added support for more detailed image decoding with additional context parameters
  • Bug Fixes

    • Improved handling of different mask target types during image decoding
  • Refactor

    • Updated function signatures to support more flexible image processing
    • Streamlined import statements and decoding logic

@sashankaryal sashankaryal requested a review from a team January 17, 2025 21:05
@sashankaryal sashankaryal self-assigned this Jan 17, 2025
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Walkthrough

The pull request enhances the decodeWithCanvas function in the canvas-decoder module to support more advanced segmentation processing. The changes introduce new parameters field and coloring to provide more context when decoding image overlays. The function now handles different mask target types, including special processing for segmentation cases, with improved flexibility for handling various image decoding scenarios across different overlay types.

Changes

File Change Summary
app/packages/looker/src/worker/canvas-decoder.ts - Updated function signature to include field and coloring parameters
- Added logic for segmentation-specific mask target processing
- Implemented handling for different mask target types
app/packages/looker/src/worker/disk-overlay-decoder.test.ts - Updated test cases to match new decodeWithCanvas function signature
- Added field and COLORING parameters to function calls
app/packages/looker/src/worker/disk-overlay-decoder.ts - Modified imports related to overlay decoding
- Updated decodeOverlayOnDisk function to pass new parameters to decodeWithCanvas

Sequence Diagram

sequenceDiagram
    participant Caller
    participant decodeWithCanvas
    participant Canvas
    Caller->>decodeWithCanvas: blob, cls, field, coloring
    decodeWithCanvas->>Canvas: Create canvas context
    alt Segmentation Case
        decodeWithCanvas->>decodeWithCanvas: Retrieve mask targets
        decodeWithCanvas->>Canvas: Process mask targets
    end
    Canvas-->>decodeWithCanvas: Decoded image data
    decodeWithCanvas-->>Caller: Return processed image
Loading

Possibly related PRs

Suggested reviewers

  • benjaminpkane

Poem

🐰 In the realm of pixels and decode,
A canvas rabbit hops with new mode,
Segmentation's magic unfurled,
Where masks and colors are swirled,
A transformation, clean and bold! 🎨

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sashankaryal sashankaryal added the app Issues related to App features label Jan 17, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
requirements/test.txt (1)

1-1: Consider using a version range for open3d.

While pinning to version 0.18.0 ensures consistency, it might miss important security updates. Consider using a version range (e.g., open3d>=0.18.0,<0.19.0) to allow patch updates while maintaining compatibility.

-open3d==0.18.0
+open3d>=0.18.0,<0.19.0
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd326e0 and 0b2b292.

📒 Files selected for processing (4)
  • app/packages/looker/src/worker/canvas-decoder.ts (3 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.test.ts (2 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (2 hunks)
  • requirements/test.txt (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
app/packages/looker/src/worker/disk-overlay-decoder.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/disk-overlay-decoder.test.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/canvas-decoder.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: e2e / test-e2e
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.11)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: lint / eslint
  • GitHub Check: build / build
  • GitHub Check: test / test-app
  • GitHub Check: build
🔇 Additional comments (5)
app/packages/looker/src/worker/disk-overlay-decoder.ts (1)

117-122: LGTM! The function call has been correctly updated.

The decodeWithCanvas function call has been properly updated to include the new parameters field and coloring, maintaining consistency with the function's new signature.

app/packages/looker/src/worker/canvas-decoder.ts (2)

72-77: LGTM! Function signature has been properly updated.

The function signature has been enhanced to include the necessary parameters for handling segmentation cases.


131-154: Consider handling JPG artifacts more robustly.

While the implementation correctly handles RGB mask targets for segmentation, the comment about JPG artifacts suggests a potential issue where slight color changes can cause masks to be rendered as transparent. This could affect the reliability of the segmentation rendering.

Let's verify if there are any JPG segmentation files in the codebase that might be affected:

Consider adding a color tolerance threshold for JPG segmentations to handle compression artifacts more gracefully. For example:

 if (cls === SEGMENTATION) {
   let maskTargets = coloring.maskTargets[field];
   if (!maskTargets) {
     maskTargets = coloring.defaultMaskTargets;
   }
   const isRgbMaskTargets_ = isRgbMaskTargets(maskTargets);

+  // Add color tolerance for JPG compression artifacts
+  const colorTolerance = blob.type.includes('jpg') ? 5 : 0;
+
   if (!isRgbMaskTargets_ && channels > 1) {
     // recast to mono channel because we don't need the other channels
     targetsBuffer = recastBufferToMonoChannel(
✅ Verification successful

The JPG artifact handling suggestion is valid but not critical.

The codebase supports JPG images and acknowledges compression artifacts in comments, but lacks any mitigation strategy. The suggested color tolerance threshold would indeed improve the robustness of segmentation mask rendering for JPG images.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for JPG segmentation files
rg -l --type-add 'seg:*.{jpg,jpeg}' --type seg 'segmentation|mask' .

Length of output: 70


Script:

#!/bin/bash
# Search for JPG/JPEG handling in segmentation context
rg -A 5 -B 5 "jpg|jpeg" app/packages/looker/src/
# Look for blob type handling
ast-grep --pattern 'blob.type'
# Search for any existing color tolerance or artifact handling
rg -A 3 "tolerance|artifact|threshold" app/packages/looker/src/

Length of output: 1866

app/packages/looker/src/worker/disk-overlay-decoder.test.ts (2)

95-100: LGTM! Test expectations properly updated.

The test expectations have been correctly updated to match the new function signature, including the additional parameters field and COLORING.


136-141: LGTM! HEATMAP test case properly updated.

The test expectations for the HEATMAP case have been correctly updated to include the new parameters, maintaining consistency with the function signature changes.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/packages/looker/src/worker/canvas-decoder.ts (1)

150-154: Consider propagating JPG artifact warning to caller.

The comment about potential JPG artifacts with RGB mask targets is important information that should be propagated to the caller, possibly through a warning flag in the return object.

   return {
     buffer: targetsBuffer,
     channels,
     arrayType: "Uint8ClampedArray",
-    shape: [height, width],
+    shape: [height, width],
+    warnings: isRgbMaskTargets_ && blob.type === "image/jpeg" 
+      ? ["Potential artifacts in JPG segmentation with RGB mask targets"]
+      : [],
   } as OverlayMask;
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b2b292 and 21da464.

📒 Files selected for processing (3)
  • app/packages/looker/src/worker/canvas-decoder.ts (3 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.test.ts (2 hunks)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/packages/looker/src/worker/disk-overlay-decoder.ts
  • app/packages/looker/src/worker/disk-overlay-decoder.test.ts
🧰 Additional context used
📓 Path-based instructions (1)
app/packages/looker/src/worker/canvas-decoder.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: lint / eslint
  • GitHub Check: test / test-app
  • GitHub Check: e2e / test-e2e
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: build / build
🔇 Additional comments (3)
app/packages/looker/src/worker/canvas-decoder.ts (3)

1-2: LGTM! Necessary imports added for segmentation support.

The new imports for SEGMENTATION and Coloring are correctly added to support the enhanced functionality.


72-77: LGTM! Function signature updated appropriately.

The addition of field and coloring parameters provides the necessary context for handling different types of mask targets in segmentation processing.


137-148: Add validation for maskTargets structure.

The code should validate the structure of maskTargets before using it with isRgbMaskTargets to prevent runtime errors.

Comment on lines +133 to +136
let maskTargets = coloring.maskTargets[field];
if (!maskTargets) {
maskTargets = coloring.defaultMaskTargets;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add type checking for maskTargets access.

The access to coloring.maskTargets[field] should include type checking to ensure maskTargets exists before accessing it.

-    let maskTargets = coloring.maskTargets[field];
-    if (!maskTargets) {
+    let maskTargets = coloring.maskTargets?.[field];
+    if (maskTargets === undefined) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let maskTargets = coloring.maskTargets[field];
if (!maskTargets) {
maskTargets = coloring.defaultMaskTargets;
}
let maskTargets = coloring.maskTargets?.[field];
if (maskTargets === undefined) {
maskTargets = coloring.defaultMaskTargets;
}

@sashankaryal sashankaryal changed the title fix jpg segmentations "fix" jpg segmentations Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant