Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MaxChe · Dec 12, 2016 at 04:12 PM · texture2dalgorithmpaintinggetpixelsgetpixel

The non-trivial problem with image processing.

I need to create an application on the similarity of this: alt text

This mobile app for kids. There is an image that you want to draw a finger across the control points. During drawing validation occurs on the intermediate points. If the user deviates from the route, it is considered an error. Here, a small amount of images and simple drawings. I think that point is set manually, but I will be more complex images and much more. I would like to automate this process and do not put points manually. All images in PNG format. With GetPixel() I can get all the non-transparent pixels ie the same black outline of image. But the point is too much, because I take each pixel. How to reduce the number of points(pixels), so that the line width is equal to 1? Please help me find an algorithm to solve this problem? I would be grateful for any help. Its my code:

   public class PixelsGetter : MonoBehaviour {
         public List<Vector2> points = new List<Vector2>();
         public Transform container;
         public GameObject sphereObj;
         void Start()
         {
             sphereObj = Resources.Load<GameObject>("Sphere");
             Renderer rend = GetComponent<Renderer>();
             Texture2D texture = rend.material.mainTexture as Texture2D;
     
             for (int i = 0; i < texture.width; ++i)
             {
                 for (int j = 0; j < texture.height; ++j)
                 {
                    Color color = texture.GetPixel(i, j);
                     if (color.a!=0)
                     {
                         points.Add(new Vector2(i,j));
                     }
                 }
             }
         var obj = Resources.Load<GameObject>("Sphere");
             foreach (var item in points)
             {
                 CreateSphere(item);
             }
         }
        void CreateSphere(Vector2 point)
         {
             var newObj = Instantiate<GameObject>(sphereObj);
             newObj.transform.SetParent(container);
             newObj.transform.localPosition = new Vector3(point.x, point.y, 0);
         }
     }

Here is the result (left original image, to the right - the result created by the 29903 spheres): alt text

kid-app.jpg (34.9 kB)
example.jpg (373.5 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glurth · Dec 12, 2016 at 08:54 PM 2
Share

After you generate you list of all non transparent points, group together any points that are touching. Once all your groupings are complete, and there are no more points touching, (that are not in a group): compute the center (or average position) of each group. Use only the center/average position for each group, as your final point list.

avatar image MaxChe Glurth · Dec 13, 2016 at 10:25 PM 0
Share

thanks for your reply!

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by Oscaruzzo · Dec 12, 2016 at 10:23 PM

What you need is a "thinning" algorithm, which you can use to go from this

alt text

to this

alt text

You can find several different algorithms around. This algorithm is often implemented in some form in image processing libraries.

See here or here for example


guo-hall-thinning-src-img.jpg (10.8 kB)
guo-hall-thinning-dst-img.jpg (9.8 kB)
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MaxChe · Dec 13, 2016 at 10:26 PM 0
Share

$$anonymous$$any thanks!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why is my terrain so dark? 1 Answer

Can't seem to use GetPixels on a square texture in Unity 3.0 Iphone 0 Answers

Unity crashes trying to get pixels and using Debug.Log 0 Answers

Painting stencil on a surface. 6 Answers

GetPixel in c# 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges