chsh2 / nijiGPen

An add-on of Blender focusing on Grease Pencil
GNU General Public License v3.0
241 stars 12 forks source link

Automatically clean-up Grease Pencil strokes from rough sketches #4

Open b4zz4 opened 1 year ago

b4zz4 commented 1 year ago

I don't know why I think these add-ons can also solve this.

https://blender.community/c/rightclickselect/WQyE/

A simpler tool could be made. Take two or more lines and join them by averaging their closest points: associating proximity. When the points exceed a threshold they are "joined" Creating a new line and deleting the old ones.

https://cdn.masto.host/mographsocial/media_attachments/files/109/218/203/715/850/201/small/b95c64d42ee46797.png

This can be done sequentially and in iterations so that the result is more organic and mimics the results of neural networks.

Fast example:

https://cdn.masto.host/mographsocial/media_attachments/files/109/219/323/481/838/949/original/73ce9140b1ac3c42.mp4

(Quickly modifying the magnet stroke)

chsh2 commented 1 year ago

Yes the sketch cleanup is also a function that I want to implement.

I read the StrokeAggregator paper and tried its program before. However, it was quite slow and took ~10min to process a single drawing in my computer. I do not know if I misconfigured something or the time complexity is indeed high. Maybe we can start from a simpler version of clustering algorithm.

I am also investigating machine learning methods. Though I am not an expert of it, the current popular models such as Transformer look like a good fit to process vector strokes. Now I am generating a dataset, by adding noise to GP strokes and letting the neural network to reverse it. I have not got enough results to show though.

b4zz4 commented 1 year ago

Only firstly chosen lines could be joined similar to shapes. Grouping is a really complex problem. For that, you can use the skicit classification.

chsh2 commented 1 year ago

I have to make several fixes to current functions before developing new ones, so I am not sure when I can start working on this issue. But I did some experiments and would like to share some results here.

The last approach works in some cases like the following ones: emst

I think it is a good sign and I will continue. But it is not finished since there are also some failure cases.

tugok commented 1 year ago

yooo thats me who suggested on blender community. So nice to see you actually implementing this! Cant wait!

chsh2 commented 1 year ago

I will release this function in several days, and it is also in the current source code if you want to test it now.

Currently, strokes need to be selected manually. The next step is the implementation of a clustering algorithm. I reread the StrokeAggregator paper and found its clustering algorithm having a very high time complexity. On the other hand, most common clustering algorithms will not work well on curves if simply calculating the pairwise point distance. Therefore, I tend to develop a new method.

b4zz4 commented 1 year ago

Work perfect:

a

chsh2 commented 1 year ago

Work perfect:

Thank you for your test case. Here one another possible issue is the difference between curves and straight lines. The algorithm tends to create rounded corners, therefore does not work well on straight lines with sharp corners, unless we set a small smoothness value manually. This issue is not mentioned in the research papers. Maybe some additional optimization methods are needed.

b4zz4 commented 1 year ago

Maybe you could use a smooth Savitzky-Golay, but it has some problems at the beginning and the end

https://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter https://scipy-cookbook.readthedocs.io/items/SavitzkyGolay.html

b4zz4 commented 1 year ago

Will there be a way to detect that points are the originals and take the stroke pressure?. To imitate the original pressure

chsh2 commented 1 year ago

https://user-images.githubusercontent.com/110356534/215008048-5657f004-f97b-462e-9067-6c574f4f6796.mp4

Made a first implementation of identifying multiple strokes. Maybe some post-processing methods are needed, such as pinching the ends of strokes. Also, I have no confidence for it to work perfectly when the drawing is very complicated. I am thinking of adding another interactive way in the Draw mode.

Will there be a way to detect that points are the originals and take the stroke pressure?. To imitate the original pressure

Yes that should be possible. I will try to add some options inheriting the point attributes after finishing the main function.

b4zz4 commented 6 months ago

https://github.com/squidrice21/StripMaker

chsh2 commented 6 months ago

https://github.com/squidrice21/StripMaker

Thank you for the information. It looks interesting and I will see if any techniques can be used here. Hopefully I can get more time to work on this project the next month...