Sign in to follow this  
AhmedElyamani

Color Bucket Tool?

Recommended Posts

Hello

I was wondering how does the Color Bucket tool Works? Like if i want my plugin to include some kind of filling the area of the same color.

like this maybe:

img-1.png

Thanks A lot ! if you can't help just please tell me an idea or anything , i greatly appreciate it

Ahmed

Share this post


Link to post
Share on other sites

If you're working utilizing layers that have 3 complete circles, when you use the paint bucket, it will fill the entire circle. The layers will need to be merged together so that the lines of the circles act as a sort of "barrier" for the paint and in this way it won't flood over into the "football" shaped (for lack of a better term) intersecting areas (as in your example).

Also, the paint bucket works with the primary selected color. So, since you already drew the circles with black, simply select the paintbucket tool and then click inside the area you want filled and it will fill with the black. To fill the other areas with other colors, simply change the primary color and click on your next area.

Share this post


Link to post
Share on other sites

I believe that Ahmed is asking how the Fill tool works programmatically.

I'm guessing that the pixels neighboring the 'location' are recursively checked for similarity to the 'location' pixel (remember there is a tolerance slider to consider). If neighboring pixels are within tolerance, they are added to a list and also recursively checked for neighboring pixels.

I'm sure those with more in depth knowledge will be able to provide a more accurate description.

Share this post


Link to post
Share on other sites

Thanks for help Nitenurse39 and jim100361 ,But like EER said , i need it programmatically.

I believe that Ahmed is asking how the Fill tool works programmatically.

I'm guessing that the pixels neighboring the 'location' are recursively checked for similarity to the 'location' pixel (remember there is a tolerance slider to consider). If neighboring pixels are within tolerance, they are added to a list and also recursively checked for neighboring pixels.

I'm sure those with more in depth knowledge will be able to provide a more accurate description.

Thanks a lot EER , i understand this point , but how would the loop look like ? i first tried to use for loops but it was very slow , I need to know how to do the loop

Share this post


Link to post
Share on other sites

Just search for "flood fill algorithm".

Thanks.

okay i've been able to write a somewhat method for my Flood Fill Algorithm , however , i still only need to understand the Tolerance Part.

This line of Pseudo code that needs edits :

// this checks for the exact same color
if (color!=pcolor) {exit;}

Okay, How is the Tolerance probably done ?

Kinda tried to use google but failed..

Thanks again.

Share this post


Link to post
Share on other sites

The algorithm looks at a pixel and determines whether to fill it and keep going, or to stop. The tolerance values determines the cut-off point for that.

Share this post


Link to post
Share on other sites

The algorithm looks at a pixel and determines whether to fill it and keep going, or to stop. The tolerance values determines the cut-off point for that.

sorry, but probably i don't understand .

okay this is my pseudo code:

{
//pseudo code
//argument0 = x
//argument1 = y
//argument2 is the color to fill with 
// old color is the color  of the mouse pixel when click , it's set before
// exit;  means  stop executing
for (i = 0; i < room_width; i+=1) 
   for (h = 0; h < room_height; h+=1) 
       {floodChecked[i,h] = false;}
/*this line is what needs edit*/ if (getpixel(argument0,argument1) !=/*as said above , old color is the color of the first
pixel when mouse clicking...i want to reaplace that with tolerance*/ oldColor) exit;
if (argument0<0)||(argument0>rect.Width)||(argument1<0)||(argument1>rect.Height) exit;
if (floodChecked[argument0,argument1]== true ) exit;
/*color*/setColor(argument2);
/*drawing*/drawPixel(argument0,argument1);
floodChecked[argument0,argument1]=true
// this recalls the script
DrawFlood(argument0-1,argument1,argument2)
DrawFlood(argument0+1,argument1,argument2)
DrawFlood(argument0,argument1+1,argument2)
DrawFlood(argument0,argument1-1,argument2)
}

i just want to replace that line or that variable "oldcolor" , with a somewhat lines that applies tolerance . How ?

I mean , what is the relationship between the original color and the other color ,say like tolerance 50% .

Thanks .

Ahmed.

Share this post


Link to post
Share on other sites

Right now your similarity function is just simple equality, e.g. (A == B ) ? proceed : stop.

I think Paint.NET uses Euclidean distance between the pixels. If you imagine R, G, B as being X, Y, Z values then you want the length of the line between the two pixels in 3-dimensional space, e.g. sqrt((r1-r0)^2 + (g1-g0)^2 + (b1-b0)^2). The maximum distance between any two points (colors) will be the distance between white and black, or sqrt((255-0)^2 + (255-0)^2 + (255-0)^2), or ~441.67. If you then take this distance and divide by ~441.67 you'll end up with a value between 0 and 1. If your tolerance is 0 to 100, then multiply by 100 to get a value from 0-100. Then, compare this value to tolerance and if it's less than that you proceed, else you stop. Smaller numbers mean more similarity, larger numbers mean less similarity.

(A == B ) ? proceed : stop

turns into

((Distance(A, B ) / Distance(White, Black) * 100) < Tolerance ? proceed : stop

That's the gist of it, in pseudo code anyway. You'll have to experiment to find what exactly works well. Maybe something other than Euclidean distance is what you actually want, but the key is to transform the problem into one that uses a similarity function.

  • Upvote 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this