Skip to content

New attribute "deltax" to correct for horizontal distance differences in eye baseline between camera and human vision.#54

Open
isenberg wants to merge 11 commits into
steren:mainfrom
isenberg:main
Open

New attribute "deltax" to correct for horizontal distance differences in eye baseline between camera and human vision.#54
isenberg wants to merge 11 commits into
steren:mainfrom
isenberg:main

Conversation

@isenberg
Copy link
Copy Markdown
Contributor

@isenberg isenberg commented Apr 6, 2025

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

isenberg and others added 8 commits March 25, 2025 18:18
…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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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 deltax attribute: Introduces a deltax attribute to the stereo-img component for horizontal correction of stereo pair images.
  • Horizontal correction implementation: Modifies stereo-parser.js to apply the deltax correction during stereo pair image parsing.
  • Documentation update: Updates the README to document the new deltax attribute and its usage.

Changelog

Click here to see the changelog
  • README.md
    • Added documentation for the new deltax attribute, explaining its purpose and usage.
  • parsers/stereo-parser/stereo-parser.js
    • Calculates the horizontal shift dx based on the deltax option.
    • Adjusts the angle option based on the absolute value of dx.
    • Modifies the getImageData calls 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.
  • stereo-img.js
    • Added a deltax getter to retrieve the value of the deltax attribute.
    • Added a baseline setter that maps to the deltax attribute, allowing setting deltax via baseline.
    • Modified the parseStereoPair call to include the deltax value as an option, defaulting to 0 if not provided.
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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

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 deltax usage: The purpose and effect of deltax could be made clearer in the code and documentation. Consider adding comments to explain the calculations and adjustments made using deltax.
  • Naming consistency: The attribute is named deltax but the setter uses baseline. This inconsistency could be confusing. Consider renaming the setter to deltax for consistency.
  • Angle adjustment: The angle adjustment based on deltax might 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.

Comment thread stereo-img.js Outdated
Comment on lines +86 to +91
set baseline(val) {
if (val) {
this.setAttribute('deltax', val);
} else {
this.removeAttribute('deltax');
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
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');
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It seems indeed there is a copy paste error

Comment thread README.md
Comment on lines +42 to +43
* `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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Consider rephrasing to clarify the effect of positive and negative values. For example: "Positive values shift the left image left and the right image right to simulate a closer convergence point."

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

It would be helpful to add a comment explaining why the angle is being adjusted based on dx. What is the reasoning behind options.angle = options.angle * (100-Math.abs(dx))/100;?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I agree with this suggestion, please explain formula

Comment on lines +198 to +201
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I agree with this suggestion, please explain formula

Copy link
Copy Markdown
Owner

@steren steren left a comment

Choose a reason for hiding this comment

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

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?

Comment on lines +198 to +201
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);
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I agree with this suggestion, please explain formula

Comment thread stereo-img.js Outdated
Comment on lines +86 to +91
set baseline(val) {
if (val) {
this.setAttribute('deltax', val);
} else {
this.removeAttribute('deltax');
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

It seems indeed there is a copy paste error

@isenberg
Copy link
Copy Markdown
Contributor Author

isenberg commented Apr 8, 2025

I added comments to explain the formula now and fixed the wrong accessor function name.

@isenberg
Copy link
Copy Markdown
Contributor Author

isenberg commented Apr 8, 2025

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.

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.

3 participants