Anti-aliasing problem (overlapping lines)

Post questions on how to use or achieve an effect in Inkscape.
littlegrassfolks
Posts: 23
Joined: Tue Mar 12, 2013 2:16 am

Anti-aliasing problem (overlapping lines)

Postby littlegrassfolks » Fri Mar 15, 2013 12:50 am

Hi,
I am starting this topic after the discussion in another topic ( viewtopic.php?f=5&t=13668&p=52987#p52987 ) with an unrelated name drifted towards the topic of this thread. My question is this:

All my work involves line work. When I draw out things on inkscape, on occasion, I have overlapping lines. This sometimes happens inadvertently. The two lines would be of exact same color, same stroke width and same length and right on top of one another. Now when this happens, these lines appear slightly darker/thicker or something but I can notice it when I export a bitmap from inkscape. Is there any way to avoid this? Can I somehow set an option which will say: if you have two lines exactly on top of one another, just treat it just like a single line? Not sure if this is a valid question but I can see how one might want this!!!
About the overlapping lines: for something I am doing, I have a repetition of shapes and during it, its almost impossible to avoid partial overlap. If I think about it, this is what I feel. If I draw a line of some width and black in color, and then I draw another line of the same width on top of that, (both snapped to same gridpoints for their start and end) then technically, in 2-D, why should anything look visibly different between a single line and double line? I feel like my expectation is valid!! What does inkscape do when treating these cases? Does it nudge one of the lines a tiny-bit so that the overall width seems larger and hence the line appearing bolder in a bitmap export? I feel like two lines on top of one another should be same as one line if both are opaque! right?

Also, every single line that I have, is aligned with the grid. It snaps to grid and is parallel to grid lines. I was asked to post a sample and so I am attaching a file with a few straight lines and a corresponding bitmap export. You can see that the lines are aligned with the grid.

Thank you all very much for your help.

lineOverlapExport.png
This is the bitmap export
lineOverlapExport.png (510 Bytes) Viewed 7946 times

lineOverlap.svg
This is the original svg file
(6.37 KiB) Downloaded 348 times

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Fri Mar 15, 2013 1:21 am

Your grid dimensions are in mm, while you want to export things into a raster image, which uses a pixel-grid.
You should use integer pixel dimensions everywhere and an exporting resolution of a multiple value of 90 dpi to avoid any problems from anti-aliasing.


This image was created with exporting the attached svg with 180 dpi -90 dpi exporting still had the mentioned problem.
The point coordinates, the line widths are all integer pixel sized.
Image
Attachments
hlp8.svg
(6.55 KiB) Downloaded 266 times

User avatar
druban
Posts: 1867
Joined: Fri Nov 20, 2009 10:48 pm

Re: Anti-aliasing problem (overlapping lines)

Postby druban » Fri Mar 15, 2013 3:08 am

The effect you are having trouble with is not going to be completely fixed by any one solution, but looking at your file I notice that you have a 0.5 px stroke width. Exporting a screen resolution bitmap means that Inkscape is going to have to figure out a 1 pixel wide approximation for a half pixel wide stroke that begins and ends on a 0.25 pixel division ... and then overlap them. It's logical that the overlapped area will be darker - you are effectively asking for two overlapping blurs. Re-read Xav's eloquent explanation of this in the original thread that you asked your question in ...

The problem is partially fixed by exporting at a resolution much higher than screen and then sampling down outside Inkscape. But this will still be unsatisfactory unless you pay attention to pixel locations.
Snapping to a one-pixel grid helps with strokes that are absolutely vertical or horizontal and also have a width that is an even number of pixels, but will not solve the problem for odd-pixel wide strokes, which should be snapped to a 0.5 pixel grid, or oblique lines.
The problem with the hlp8.svg solution above is that it has 1-pixel wide strokes aligned with a 1-pixel grid, which puts the edges of the strokes at 0.5 pixel locations so the problem persists in 90 dpi exports. This is why you need a 0.5 pixel grid.

Here is a 90 DPI export from the attached SVG, which is much the same as yours except that I made my drawing while observing the warnings above. You can see that a higher resolution export is not necessary if you are careful in placing your object.

rect4028.png
rect4028.png (503 Bytes) Viewed 7914 times


This file also includes my grid system. If you want to make it your default grid system, select everything, delete, change the pagesize in document setup (,if you don't want US Letter) zoom to page, and save it as default.svg in your username/appdata/Inkscape/templates folder. Zoom in and out to see 0.5px, 1px, 10px, 50px, 100px and 500px grids! The finer grids vanish when zoomed out.
Attachments
lineOverlapcorrect.svg
(7.72 KiB) Downloaded 296 times
Your mind is what you think it is.

littlegrassfolks
Posts: 23
Joined: Tue Mar 12, 2013 2:16 am

Re: Anti-aliasing problem (overlapping lines)

Postby littlegrassfolks » Tue Mar 19, 2013 6:02 am

Thank you Lazur URH and druban. I thought there was another reply but I dont see it anymore. I hope I didnt accidentally delete it (I hope that I can not delete responses in general).

@druban
I am using the file that you provided as my new default template. However, there was one modification that had to make to make it useful for my use. In document properties, I changed the following settings.
Snap to objects: snap only when closer than: snap distance: 20
Snap to grids: Always snap
Snap to guides: snap only when closer than: snap distance: 20
The way you had it, it would snap on the grid line itself as well. I wanted it to snap only on a grid point (intersection of two grid lines) and not on the line itself. For that, I had to make these changes. Also, on a linux machine, this default template should be saved in /home/username/.config/inkscape/templates/default.svg.
I understand the explanations regarding pixels. Now I have another followup question. I will be using inkscape to draw my artwork, then export it to a bitmap and then take print outs at a regular printing service like Fedex Kinkos, frame the prints and display them. Now, say I have a square shape that I want to be of size say 1inch by 1inch. Now to have this printout look sharp and nice, what should be approximately the size of this square in inkscape drawing in terms of pixels? and how does this relate to the dpi of the file? (I know that under preferences - import/export, I can change the dpi for the document). On top of this, I would also like to know about what the printer does when it reads in a file, how does it print a file of given size? But I will likely ask more about this in the followup.
Thank you again

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Tue Mar 19, 2013 7:52 am

If you want to print such line drawings, I would say it is unnecessary to export the final image. High resolution raster images can melt your machine, but you can print straight from a vector pdf.
Also, anti-aliasing is not a problem at printing vectors, as printers can handle 1200/2400 dpi-s , which is more that you could see normally -common book printing resolution is about 300 dpi, common photo printing resolution is about 600 dpi.
Anti-aliasing is more of a problem when producing screen accurate graphics.

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 1:13 am

Hello guys!
I am having the same problem, only I am not exporting to a bitmap, I am saving a pdf file. I tried using druban's template, but it didn't make any difference.. I am making two straight lines of 1mm line width overlap, and I can see it in the final pdf :( Have I understood incorrectly the instructions?

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Mon Oct 07, 2013 2:24 am

Hi.

We cannot tell, show us an example.

In case you have problems at end nodes, you may change the stroke style from rounded to others.
Attachments
lineOverlapcorrectII.svg
(5.49 KiB) Downloaded 235 times

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 3:10 am

Here it is!
It only shows in specific zoom levels (but it also shows on printed paper (in a professional printer), so it's not a problem of the pdf viewer)
any ideas?
Attachments
overlap.pdf
(1.05 KiB) Downloaded 225 times

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 3:11 am

and the respective svg..
Attachments
overlap.svg
(6.79 KiB) Downloaded 214 times

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Mon Oct 07, 2013 4:38 am

Pixel fitting would show up if you zoom in 100% if done right.
However, the non diagonal or vertical parts would get blurred too.

Do you wish to use that on screen anyway?
If not, it's all the printers resolution and the grid it uses that would make parts uneven.
Have no idea how could be that a problem as you can print in 1200/2400 dpi resolution too,
which means 0,021 mm that compared even to that 0,3 mm stroke width won't be legible.

But, there are some small parts that could be cleaned in your image.
You use 0,3 and 0,282 mm wide strokes too.

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 4:54 am

thanks very much for your help!

I don't understand exactly what you're saying though :(
About the last part, you're right, they weren't same size after all, but I corrected that and I still get the same problem.
I don't care about the screen display, it's the print that I worry about. It's just that, last time, the problem occurred on both the display and on paper. Are you saying what I'm seeing on pdf is not necessarily what will be shown on paper after these corrections?
100% zoom, do you mean in inkscape? that makes everything tiny !
I don't care about the diagonal parts, I only care about the aligned horizontal and vertical lines.

Could it be that I am not using the proposed template correctly?? Am I supposed to do something specific with it, other than align the lines on the same gridlines?

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Mon Oct 07, 2013 5:14 am

Yes, I meant the exact size, thought that was the size you wanted to print the design in.

The template is for aligning a drawing on the pixel grid right, but that has not musc use in printing on paper -it shouldn't at least.
Maybe it's a printer setting -if you want to print in such small size, you will have to use high resolution.
That should be automatic, so it's then the printing paper. Maybe you wanted to print on a regular paper, where ink spots just doesn't come out as sharp as the printer puts them.

Is the design tiny? Thought that was intentional, what else size would you use it?
And, with the size comes the different page border settings.
With resizing your page to a random content, the grid template became off to the paper.
Firs decide what the size should be, then set borders right, then create new grid(s).

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 5:23 am

The last two lines have me buffled !!
The design is supposed to be around 8cm x 5 cm, but it varies each time according to the contents. It's figures for an electronics book. I always start with a fixed page size around that, but I always end up resizing to fit contents !!
But what does the border and the grid have to do with it, if I use the align functionality for those two lines? (and I have everything on a ruler at the same time !!)

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Mon Oct 07, 2013 5:33 am

Hmm I guess pixel fitting -placing all graphical elements on exact positions of the pixel grid- is just a screen display problem.

But for a book, is it a good idea to scale the drawing to the space available?
In architecture there are fixed scales to work in, all which have standardised marks, pen sizes and such.
Isn't there such a restriction in the field?
In my opinion a technical book would be more clear with the same element marked with the exact same symbol, not varying them in size.

Personally I would create a page template and use a mm grid for such technical drawings, but that shouldn't be really necessary.

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 5:40 am

Technically I do not belong to the field, this is the problem..
I *have* a template with electrical components, it's just that there was no such thing as a grid :D
So, what do I do, I make a 1mm grid, and use the same 0.3mm line width for all components and I should be fine, it's just that I won't be able to see it on screen? Is this what you mean?

Lazur
Posts: 4706
Joined: Tue Jun 14, 2016 10:38 am

Re: Anti-aliasing problem (overlapping lines)

Postby Lazur » Mon Oct 07, 2013 5:56 am

Yes, that's it.

Attached how it would look "better pixel fitted" for onscreen use, with corrected grid origos.
Attachments
hlp84.svg
(3.98 KiB) Downloaded 265 times
hlp84II.pdf
(1023 Bytes) Downloaded 251 times

sfranky
Posts: 12
Joined: Tue Sep 14, 2010 6:21 am

Re: Anti-aliasing problem (overlapping lines)

Postby sfranky » Mon Oct 07, 2013 6:02 am

all right, I ll try it!
Many thanks for your help!


Return to “Help with using Inkscape”

Who is online

Users browsing this forum: Baidu [Spider] and 5 guests