processing / processing/p5.js

[p5.js 2.0 Bug Report]: Comparison algorithms may not work as expected

Open
#7,851 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

p5.js 2.0+
Dominant language
JavaScript
Stars
24k
Forks
3.8k
Avg merge
3d 16h
Merged PRs (30d)
25

Description

Most appropriate sub-area of p5.js?
  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)
p5.js version

No response

Web browser and version

No response

Operating system

No response

Steps to reproduce this

I read through the code and believe that the visual comparison algorithm has three main parts:

  • Use pixelmatch to compare pixel-by-pixel and highlight diffs in red
  • Use BFS to find all diff clusters
  • If 80% of a cluster has ≤2 neighbors, this cluster is considered a line shift and should be ignored.

I'm not sure if
(1) the args in pixelmatch are set properly to ignore diffs by aliasing (currently I saw that threshold is set at 0.5 and AA is set to false)
(2) the line shift criteria works well for curved shapes

Thus I modified the code a bit to print the diff images, with red as pixels caught by pixelmatch, green as pixels flagged as line shifts. Below is the code I used to test horizontal shifts (1px to 3px) and their diff outputs:


visualTest("with the default font", function (p5, screenshot) {
      p5.createCanvas(50, 50);
      p5.textSize(20);
      p5.textAlign(p5.LEFT, p5.TOP);
      p5.text("test", 0, 0);
      screenshot();
    });

visualTest("with the default font shifted 1", function (p5, screenshot) {
      p5.createCanvas(50, 50);
      p5.textSize(20);
      p5.textAlign(p5.LEFT, p5.TOP);
      p5.text("test", 1, 0); // shifted by 1px horizontally
      screenshot();
    });

visualTest("with the default font shifted 2", function (p5, screenshot) {
      p5.createCanvas(50, 50);
      p5.textSize(20);
      p5.textAlign(p5.LEFT, p5.TOP);
      p5.text("test", 2, 0); // shifted by 2px horizontally
      screenshot();
    });

visualTest("with the default font shifted 3", function (p5, screenshot) {
      p5.createCanvas(50, 50);
      p5.textSize(20);
      p5.textAlign(p5.LEFT, p5.TOP);
      p5.text("test", 3, 0); // shifted by 3px horizontally
      screenshot();
    });

Image
when text shifts by 1px, pixelmatch can't catch that. I suspect the reason is that the threshold is set too high (at 0.5 out of 1), which increased the color tolerance. Although 1px shift is acceptable to us, I'm not sure this is what we are looking for out of pixelmatch (?) I'm assuming we want pixelmatch to catch all the diffs except AA ones and then let the line shift logic decide whether to ignore the diff clusters or not.

Image
when text shifts by 2px, pixelmatch managed to catch most of the pixel diffs, however, the line shift detection didn't work for one cluster

Image
when text shifts by 3px, pixelmatch managed to catch even more of the pixel diffs. However when I looked carefully, the lines don't actually "widen" (I expected the lines at 3px shift should look twice as thick compared to the 2px shift), instead the lines just connect more vertically, and still look like 1px strokes. If that's the case, I think the “t” shift should be flagged as a line shift, but it isn’t. Although I do believe a 3px shift should fail, but in this case it fails not because the diffs widen, but because the line shift logic didn’t catch and ignore them.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the visualTest comparison path, the pixelmatch configuration, and the BFS line-shift logic. Reproduce the reported 1–3px horizontal text-shift cases and compare their diff outputs; done should include a decided and validated treatment of anti-aliasing and line shifts, including curved or connected shapes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.