I'm writing a webapp to draw a segmentation map which will then be used as input into a neural network to generate a realistic looking image. For a better picture, I use a mapping from the 150 segmentation classes (labeled 1 through 150, single channel) to RGB so that they aren't drawing in hard-to-distinguish black and white colors. I use a few dictionaries for the forward and backward mappings.
My problem is that when I use the following code to draw lines, the canvas seems to add/multiply colors instead of use the exact stroke color I'm using, causing a keyerror in my python backend.
ctx.beginPath();
ctx.lineWidth = size;
ctx.lineJoin = "round";
ctx.lineCap = "round";
ctx.moveTo(lastx, lasty);
ctx.lineTo(x, y);
ctx.closePath();
ctx.stroke();
Here is an image of my tool, and an example of my drawing a single line (the green trail on the olive background). The starting image is drawn with fill rect, by the way.
Example image:
I've verified that there is no issues if I just draw rectangles with ctx.fillRect(Math.round(x-size/2), Math.round(y-size/2), size, size)
, but of course it's not as pretty.
Both the fill and stroke color are the same. I've tried all combinations of lineJoin and lineCap for the line drawing. https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Applying_styles_and_colors has helpful information, but doesn't offer a solution to never draw the "half" pixels. Is there a setting I'm overlooking?