New attribute "deltax" to correct for horizontal distance differences in eye baseline between camera and human vision.#54
New attribute "deltax" to correct for horizontal distance differences in eye baseline between camera and human vision.#54isenberg wants to merge 11 commits into
Conversation
…d the right image from rightsrc * added support for any angle value
documented new type "pair" and optional any degree value for attribute "angle"
layout and typo fixed
* added error handling for type pair when src-right is missing * renamed rightsrc to src-right
…rection in percent of image width to match the convergence point between right and left image. Positive means the right image needs to be moved right to match the left image.
There was a problem hiding this comment.
Hello @isenberg, 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!
Summary of Changes
This pull request introduces a new deltax attribute to the stereo-img component, which allows for horizontal correction of the convergence point between the left and right images in a stereo pair. This is intended to address differences in eye baseline between the camera and human vision. The deltax attribute represents the horizontal correction as a percentage of the image width. The PR also modifies the stereo-parser.js file to apply this correction when parsing stereo pair images, and updates the README to document the new attribute.
Highlights
- New
deltaxattribute: Introduces adeltaxattribute to thestereo-imgcomponent for horizontal correction of stereo pair images. - Horizontal correction implementation: Modifies
stereo-parser.jsto apply thedeltaxcorrection during stereo pair image parsing. - Documentation update: Updates the README to document the new
deltaxattribute and its usage.
Changelog
Click here to see the changelog
- README.md
- Added documentation for the new
deltaxattribute, explaining its purpose and usage.
- Added documentation for the new
- parsers/stereo-parser/stereo-parser.js
- Calculates the horizontal shift
dxbased on thedeltaxoption. - Adjusts the
angleoption based on the absolute value ofdx. - Modifies the
getImageDatacalls for both left and right eyes to account for the horizontal shift, ensuring the correct portions of the images are extracted. - Ensured that the file ends with a newline character.
- Calculates the horizontal shift
- stereo-img.js
- Added a
deltaxgetter to retrieve the value of thedeltaxattribute. - Added a
baselinesetter that maps to thedeltaxattribute, allowing settingdeltaxviabaseline. - Modified the
parseStereoPaircall to include thedeltaxvalue as an option, defaulting to 0 if not provided.
- Added a
Using Gemini Code Assist
The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and 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 to provide feedback.
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.
A stereo pair's askew,
Deltax's here to see it through.
A shift to the left,
A right eye bereft,
Brings vision into view.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
The pull request introduces a new attribute deltax to correct for horizontal distance differences in eye baseline between camera and human vision. The changes seem reasonable, but there are a few areas that could be improved for clarity and maintainability.
Summary of Findings
- Clarity of
deltaxusage: The purpose and effect ofdeltaxcould be made clearer in the code and documentation. Consider adding comments to explain the calculations and adjustments made usingdeltax. - Naming consistency: The attribute is named
deltaxbut the setter usesbaseline. This inconsistency could be confusing. Consider renaming the setter todeltaxfor consistency. - Angle adjustment: The angle adjustment based on
deltaxmight not be intuitive. Adding a comment explaining the reasoning behind this adjustment would improve readability.
Merge Readiness
The pull request introduces a useful feature, but there are some areas that could be improved for clarity and consistency. Addressing the naming inconsistency and adding comments to explain the calculations would make the code more maintainable. I am unable to approve this pull request, and recommend that others review and approve this code before merging. I recommend addressing the comments before merging.
| set baseline(val) { | ||
| if (val) { | ||
| this.setAttribute('deltax', val); | ||
| } else { | ||
| this.removeAttribute('deltax'); | ||
| } |
There was a problem hiding this comment.
The setter is named baseline while the getter is named deltax. This is inconsistent and could be confusing. It would be better to name both deltax for consistency. Also, consider adding a comment explaining that this is horizontal correction in percent of image width.
| set baseline(val) { | |
| if (val) { | |
| this.setAttribute('deltax', val); | |
| } else { | |
| this.removeAttribute('deltax'); | |
| } | |
| set deltax(val) { | |
| if (val) { | |
| this.setAttribute('deltax', val); | |
| } else { | |
| this.removeAttribute('deltax'); | |
| } | |
| } |
There was a problem hiding this comment.
It seems indeed there is a copy paste error
| * `deltax`: (Optional) Horizontal correction in percent of image width to match the convergence point between right and left image for type `pair`. | ||
| - `PERCENT`: Any number between -100 and 100. 0 means no correction. Positive means the left image needs to be moved left and the right image needs to be moved right to match the convergence point in both images. |
| leftEye = ctx.getImageData(0, 0, width, height); | ||
| rightEye = secondaryCtx.getImageData(0, 0, secondaryWidth, secondaryHeight); | ||
| const dx = Math.round(width * (options.deltax ?? 0) / 100 / 2); | ||
| options.angle = options.angle * (100-Math.abs(dx))/100; |
There was a problem hiding this comment.
I agree with this suggestion, please explain formula
| const dx = Math.round(width * (options.deltax ?? 0) / 100 / 2); | ||
| options.angle = options.angle * (100-Math.abs(dx))/100; | ||
| leftEye = ctx.getImageData(Math.max(0, dx), 0, width-Math.abs(dx), height); | ||
| rightEye = secondaryCtx.getImageData(Math.max(0, -dx), 0, secondaryWidth-Math.abs(dx), secondaryHeight); |
There was a problem hiding this comment.
Consider adding comments to explain the purpose of dx and the Math.max(0, dx) calculation. For example:
// dx: horizontal shift in pixels
const dx = Math.round(width * (options.deltax ?? 0) / 100 / 2);
// Ensure the starting index is not negative
leftEye = ctx.getImageData(Math.max(0, dx), 0, width-Math.abs(dx), height);
rightEye = secondaryCtx.getImageData(Math.max(0, -dx), 0, secondaryWidth-Math.abs(dx), secondaryHeight);There was a problem hiding this comment.
I agree with this suggestion, please explain formula
steren
left a comment
There was a problem hiding this comment.
This repo doesn't have unit tests but relies on the developers testing via example images
We need test images to showcase this new feature. Can you find images that need deltax, add them to the examples folder and add this in the index.html dropdown list?
| const dx = Math.round(width * (options.deltax ?? 0) / 100 / 2); | ||
| options.angle = options.angle * (100-Math.abs(dx))/100; | ||
| leftEye = ctx.getImageData(Math.max(0, dx), 0, width-Math.abs(dx), height); | ||
| rightEye = secondaryCtx.getImageData(Math.max(0, -dx), 0, secondaryWidth-Math.abs(dx), secondaryHeight); |
There was a problem hiding this comment.
I agree with this suggestion, please explain formula
| leftEye = ctx.getImageData(0, 0, width, height); | ||
| rightEye = secondaryCtx.getImageData(0, 0, secondaryWidth, secondaryHeight); | ||
| const dx = Math.round(width * (options.deltax ?? 0) / 100 / 2); | ||
| options.angle = options.angle * (100-Math.abs(dx))/100; |
There was a problem hiding this comment.
I agree with this suggestion, please explain formula
| set baseline(val) { | ||
| if (val) { | ||
| this.setAttribute('deltax', val); | ||
| } else { | ||
| this.removeAttribute('deltax'); | ||
| } |
There was a problem hiding this comment.
It seems indeed there is a copy paste error
|
I added comments to explain the formula now and fixed the wrong accessor function name. |
|
BTW, for testing I currently use the Google Cardboard view on the Android phone with Chrome. The WebXR simulation extension for Edge I used before fails now, I guess a bug in the extension. |
The name deltax is currently more a testing attribute as later it would be better to use an attribute baseline in mm and disparityAdjustment in % which in combination then results in the technical deltax number. PR is for #53