|
So, if you are able to get all the colors of the image, you could easily sum up their occurence. The one color with the highest sum is then your main color. You might also want to threshold the colors a bit so that you evaluate {255,0,0} and e.g. {255,15,15} as being Red and {0,255,0} as well as e.g. {47,255,47} as being green.
|
|
|
|
|
i tried averaging the colors however it only gave me the color red but not red and green in the example of the image given above.
THe range for RGB is very wide meaning i have to use if statements?
how to you sum up occurence?
modified on Tuesday, November 23, 2010 1:34 AM
|
|
|
|
|
While JF2015 suggest to predefine colors and their RGB ranges, I think the main color(s) could be anywhere in the RGB range - hence predefined ranges do not help.
Beyond counting the occurrences of every color, I would add a weighted amount for pixels whose color is "similar" to the color in question.
My suggestion for getting the main colors is hence a very slow one - you will need a specialist for fast algorithms to get it optimized!
- define how far the second (third etc.) color must be away from the main color
- create an array of doubles for all RGB values (oh yes, some 16 million)....
- iterate through all the pixels of the image:
- - add 1.0 at the array position of the pixel's color
- - for the array positions of "similar" colors, add the weighted amount, e.g. 1.0/(1.0+delta R)/(1.0+delta G)/(1.0+delta B) (ehm, that's another nested loop(s)...)
- now iterate through your array of RGB values, and select the highest value (you may sort the array): this is the main color.
- take the RGB value with the next highest value
- - if it is "close" to the main color, repeat the step above
- - otherwise, it is the second color.
- with third (forth etc) color, do as outlined for the second color, but do not forget that it must be sufficiently away from all previously selected colors.
When you test this "naive" algorithm with your example image, bear in mind that it is not at all optimized, and surely terribly slow! Better test with a very small image first.
|
|
|
|
|
hi all
please can someone tell me how to hack the password of yahoo ID?
|
|
|
|
|
inayathussaintoori wrote: please can someone tell me how to hack the password of yahoo ID?
sure, if you post your e-mail address, all 7+ million of us will send you password candidates for you to try.
|
|
|
|
|
And here I thought you were just another troll, you know account created less than 1 month, 1st post and you ask a question designed to irritate the development community. But no you've been here some months so what does that make you - ????
If it is your account then reset it, if not your an idiot.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
That's a very dangerous question. It made me laugh so much that I almost fell from my chair!
|
|
|
|
|
I had to read that a couple times to make sure I wasn't missing part of the question. Truly amusing that some people assume that all developers are a bunch of hackers.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
Nobody is going to tell you how to do this you little scriptkiddy. Now run along and go play with your marbles.
|
|
|
|
|
Your own password?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Errr, send me your yahoo ID and password and I'll see what I can do...
|
|
|
|
|
Sorry, I don't think any one help you for this question.
|
|
|
|
|
|
|
Thanks for that, much much better than generating code in real-time !
|
|
|
|
|
you have been an active member for over a year and should know by now about Google, and CodeProject articles. The solutions can be found everywhere, all it takes is a one-minute search.
|
|
|
|
|
I did search, just didn't know the search criteria,for example "String parsing with maths to int" to me sounded right but google didnt like it.
In the end "String with formula to number" worked but I never usually use the word "formula"
|
|
|
|
|
you are trying to evaluate an expression.
|
|
|
|
|
Hello.
I use VS 2010 C# and try to change Label text (Label is visually created in form editor and has monitoringFile name)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private void Form1_Load(object sender, EventArgs e)
{
monitoringFile.Text = @"xxx";
}
This works perfectly, BUT.
If i later decide to change it again as a result of some event (in same Form1 class), the program just exits.
public void CreateFileWatcher(String file)
{
monitoringFile.Text = @"zzz";
}
VS recognizes monitoringFile in both cases and doesnt give error on compile;
Thank you for any help.
|
|
|
|
|
Difficult to tell - it shouldn't "just exit" for any reason - it should give an exception of some form.
Try wrapping your line in a try...catch block and see if any message comes up:
public void CreateFileWatcher(String file)
{
try
{
monitoringFile.Text = @"zzz";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
Then tell us what the exception says.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
Hi thank you for your help.
I didn`t look close enough it does output error. (My first day of c#)
<br />
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll<br />
The program '[1844] WindowsFormsApplication1.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).<br />
The program '[1844] WindowsFormsApplication1.vshost.exe: Program Trace' has exited with code 0 (0x0).<br />
|
|
|
|
|
Are you attempting to update the label from the primary thread or a background thread? I suspect you are running this on the background thread, which is a big no-no and should only be done by marshalling the change back to the primary (UI) thread.
|
|
|
|
|
That was pretty much my original thought, but if so then he's playing with some pretty advanced stuff for a first day in C#!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
public void CreateFileWatcher(String file)
Is called as event handler for FileSystemWatcher.
Its my first day of c#, but few years of PHP,javascript,flash so its not entirely new to me.
|
|
|
|