Skip to content

Conversation

@yannik131
Copy link

Resolves Issue #1232 by taking a screenshot of the map if the image is tiled.

@mzur mzur linked an issue Nov 19, 2025 that may be closed by this pull request
@yannik131
Copy link
Author

@mzur
kleines Problem: Ich hatte aus Versehen die .onnx-Datei mit auf remote gepusht. Ist nicht so leicht, die aus der History wieder rauszukriegen (man müsste die gesamte History mit git filter-repo o. ä. umschreiben). Also würde ich alles löschen und nur die Codeänderungen wieder reinkopieren mit

cp -r resources ~/backup/resources
git reset --hard <last commit before my changes>
git push --force
cp -r ~/backup/resources resources
git add .
git commit -m "Made labelbot work for tiled images"
git push

Dann geht zwar meine History (5 commits -> 1 commit) verloren, aber das ist nicht so schlimm denke ich. Passt das so? Dann mach ich das morgen und dann kann die PR auch reviewed werden.

@mzur
Copy link
Member

mzur commented Nov 20, 2025

Ja das passt so, kein Problem 👍

@mzur
Copy link
Member

mzur commented Nov 20, 2025

btw this is our commit message style guide in case you are interested: https://chris.beams.io/git-commit

Since tiled images are transmitted in parts, no underlying image can be
directly accessed. Instead, a screenshot of the map is taken and cropped
according to the selection.
@yannik131 yannik131 marked this pull request as ready for review November 20, 2025 13:11
@yannik131
Copy link
Author

@mzur I changed the PR to ready for review, but can't select a reviewer or request a review. It's ready though.

@mzur mzur self-requested a review November 20, 2025 13:28
@mzur
Copy link
Member

mzur commented Nov 20, 2025

Please resolve the linter errors. Run it locally with npm run lint.

@yannik131
Copy link
Author

I resolved them, but the pipeline doesn't seem to run automatically @mzur

Copy link
Member

@mzur mzur left a comment

Choose a reason for hiding this comment

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

This works great already! My comments are mostly about stylistic issues.

Removed unneeded constructs for the labelbot images (TILEDIMAGES state,
tempCanvas, etc.)
@yannik131
Copy link
Author

I made the changes as requested @mzur, ready for review again.

@mzur mzur self-requested a review December 1, 2025 10:23
Copy link
Member

@mzur mzur left a comment

Choose a reason for hiding this comment

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

I've merged the current master.

I noticed that there was a slight delay when the labelbotImage is generated. I suggested some optimizations below.

Comment on lines +172 to +175
if(!this.image.tiled)
return this.createLabelbotImageFromRegularImage(points);
else
return await this.createLabelbotImageFromTiledImage(points);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(!this.image.tiled)
return this.createLabelbotImageFromRegularImage(points);
else
return await this.createLabelbotImageFromTiledImage(points);
if (!this.image.tiled) {
return this.createLabelbotImageFromRegularImage(points);
} else {
return await this.createLabelbotImageFromTiledImage(points);
}

[0, 0, image.width, image.height]
);
if(width === 0 || height === 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(width === 0 || height === 0) {
if (width === 0 || height === 0) {

return [left, top, Math.max(0, right - left), Math.max(0, bottom - top)];
},
getScaledImageSelection(image, x, y, width, height) {
if(!this.tempCanvas) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(!this.tempCanvas) {
if (!this.tempCanvas) {

Comment on lines 577 to 587
if(this.labelbotIsActive)
{
try {
labelbotImage = await this.createLabelbotImage(points);
}
catch(error) {
this.annotationSource.removeFeature(e.feature);
Messages.danger(error.message);
return;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(this.labelbotIsActive)
{
try {
labelbotImage = await this.createLabelbotImage(points);
}
catch(error) {
this.annotationSource.removeFeature(e.feature);
Messages.danger(error.message);
return;
}
}
if (this.labelbotIsActive) {
try {
labelbotImage = await this.createLabelbotImage(points);
} catch(error) {
this.annotationSource.removeFeature(e.feature);
Messages.danger(error.message);
return;
}
}

.finally((annotation) => {
this.labelbotRequestsInFlight -= 1;
if(this.labelbotRequestsInFlight > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(this.labelbotRequestsInFlight > 0) {
if (this.labelbotRequestsInFlight > 0) {

Comment on lines +101 to +103
makeBlob(event.context.canvas).then(blob => {
resolve(createImageBitmap(blob));
});
Copy link
Member

Choose a reason for hiding this comment

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

makeBlob and createImageBitmap are quite slow (600-700 ms on my machine). We don't need a blob or an ImageBitmap object, though, and can use the trimmed canvas directly (200 ms on my machine):

Suggested change
makeBlob(event.context.canvas).then(blob => {
resolve(createImageBitmap(blob));
});
resolve(trimCanvas(event.context.canvas));

makeBlob can be moved back to the screenshotButton then.

Most of the remaining 200 ms was used by trimCanvas. This can be improved with an early return (see below).

}

function trimCanvas(canvas) {
let ctx = canvas.getContext('2d');
Copy link
Member

Choose a reason for hiding this comment

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

Early return:

Suggested change
let ctx = canvas.getContext('2d');
let ctx = canvas.getContext('2d');
let topLeft = ctx.getImageData(0, 0, 1, 1);
let bottomRight = ctx.getImageData(canvas.width - 1, canvas.height - 1, 1, 1);
if (topLeft.data[3] !== 0 && bottomRight.data[3] !== 0) {
return canvas;
}

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.

LabelBOT for tiled images

2 participants