Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Fadi · Aug 01, 2015 at 02:35 PM · imagepixelselect

select all pixels with same color ?

Hi ... Are there any way to make something like the this image ( select all the pixels that around the selected one and the with same color )

Thank you

alt text

Note :

Magic wand tool ( found it in Photoshop )

image.jpg (80.2 kB)
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by OrbitGames · Aug 01, 2015 at 02:46 PM

Make a 2 dimensional bool array, with the same width and height as your image. Then get the color at the pressed pixel. Then go through all pixels of the image, and compare the color to the desired one. If it is the same, or just slightly different, set the bool to true, else false. after that you can check in your for example brush code, if the pixel is "selected"(true in the array) and only set the color if it is so.

Note: however, this checks for all the pixels, not just the connected ones. If you want that, I would use some pathfinding methods, to check with open and closed list, if the selected pixels are connected.(Hope this makes sense)

Comment
Add comment · Show 3 · 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 Fadi · Aug 01, 2015 at 05:21 PM 0
Share

thank you for answering me....

I like your idea , but I want to check just for the closed area , as in image up , just the brown color below the eye selected but the brown up the eye didn't

so how can i check if closed or not , and i don't wanna check all the image ( to make it faster ) ,just start checking from the selected pixel until didn't find same color around it so will stop checking

avatar image OrbitGames · Aug 01, 2015 at 05:42 PM 0
Share

I was thinking about something like in a* pathfinding (only the open and closed list are of importance).

First, you get the coordinates of your initial click, and put it in the open list.

now while there are items on the open list, get the pixels around it, and put them on the openlist, if they share the color. After all of the pixels around are tested, you put the item on the closed list. So something like this:

 List<Vector2> openList;
 List<Vector2> closedLit;
 while (openList.Count > 0)
 {
 if (isTheSameColor(openList(0)+Vector2.up) && !onOpenOrClosedList(openList(0)+Vector2.up))
 {
 openList.Add(openList(0)+Vector2.up);
 }
 //repeat for other sides
 closedList.Add(openList(0));
 openList.Remove(0);
 }

In the end you are left with the closed list. It contains the coordinates of all the pixels you have selected.

This Code is completly unable to compile, and might have some logical gaps in it, but i hope it makes my point a bit clearer. For Example when trying to add a pixel at the edge of the image, this code might not work.

avatar image fahd · Oct 01, 2015 at 03:37 PM 0
Share

hey did u manage to do it cuz ill want to do the samething with no luck

avatar image
0

Answer by maccabbe · Aug 01, 2015 at 02:49 PM

Magic wand tool is made basically the same way as flood fill.

http://www.codeproject.com/KB/GDI-plus/floodfillincsharp.aspx

http://www.codeproject.com/KB/GDI-plus/queuelinearfloodfill.aspx

http://en.wikipedia.org/wiki/Flood_fill

Comment
Add comment · 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

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

25 People are following this question.

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

Related Questions

how can i get pixel color from one image then fill one mesh with that color? 0 Answers

I am trying to spawn coloured cubes that match a pixel image. At the moment the cubes spawn but i do not know how to match up the colours. 0 Answers

Load image file into pixel data array? 0 Answers

How to stop unity from smoothing pixels? 1 Answer

Screen selector image ratio 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