|
Search the articles for "Image processing for dummies". Christian Graus put together a nice set of articles on the subject.
|
|
|
|
|
You're actually thinking the wrong way, you should not compare the pixels to the ones of their neighbours because the stars can be bigger then x pixels.
The easiest way to do this is to convert the image to a binary image first. What you should do is calculate the average pixel value of the image and then creating a bool array of the same size of the image, anything higher then the average becomes true, anything lower becomes false. Then you'll want to do something like labelling to differentiate between different stars so you can cut them out or do whatever you need to do with them.
A tip in advance:
Don't use the getPixel and setPixel methods of the Bitmap, use the LockBits and UnlockBits functions, they are a lot faster..
|
|
|
|
|
Dear terradtc,
thanks for suggesting about lockBits and UnlockBits,basically this is an assignment which our teacher has assigned to do in python using OpenCV library,but unfortunately i don't have any idea about python so i thought i should do it in C#,so kindly if you can give me a code example it would be appreciating,
thanks in Advance
|
|
|
|
|
You should talk to your teacher before changing languages, learning python may be what he wants from you.
If the images are from a specific set he provided, a more simplistic approach may well work.
Christian Graus
Driven to the arms of OSX by Vista.
"I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )
|
|
|
|
|
You'll want to do some filtering and maybe change the average a bit since this is very sensitive to minor color differences on space images but the basic idea here works. It also doesn't deserve a beauty prize but for 10 minutes of work, I wasn't expecting it to. Furthermore this code will fail on any image that's not 24 bits per pixel.
class StarGazer
{
// this function works on pictures of up to 1.3 billion pixels in width
public bool[,] toBool(Bitmap bitmap)
{
Rectangle rect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData bmpData =
bitmap.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
PixelFormat.Format24bppRgb);
bool[,] boolBitmap = new bool[ bitmap.Height,bitmap.Width];
unsafe
{//first we calculate the average value of a pixel
byte* ptr = (byte*)(bmpData.Scan0);
ptr--;
ulong overallAvg = 0UL;
for(int y = 0;y<bitmap.Height;y++)
{
ulong lineAvg = 0UL;
for (int x = 0; x < bitmap.Width; x++)
{
lineAvg+= *(++ptr);
lineAvg+= *(++ptr);
lineAvg+= *(++ptr);
}
overallAvg += lineAvg /(ulong) bitmap.Width;
}
overallAvg /= (ulong)bitmap.Height;
int average = (int)overallAvg;
//we've got the average value a collection of three pixels needs to have to become an object
ptr = (byte*)(bmpData.Scan0);
ptr--;
for (int y = 0; y < bitmap.Height; y++)
{
for (int x = 0; x < bitmap.Width; x++)
{
boolBitmap[y, x] = (*(++ptr) + *(++ptr) + *(++ptr) > average);
}
}
}
bitmap.UnlockBits(bmpData);
return boolBitmap;
}
public Bitmap boolBitmap(bool[,] boolBitmap)
{
Bitmap temp = new Bitmap(boolBitmap.GetLength(1),boolBitmap.GetLength(0));
System.Drawing.Imaging.BitmapData bmpData = temp.LockBits(new Rectangle(0, 0, boolBitmap.GetLength(1), boolBitmap.GetLength(0)), System.Drawing.Imaging.ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
int bytes = (temp.Width * temp.Height) * 3;
unsafe
{
byte* ptr = (byte*)bmpData.Scan0;
ptr--;
int x = 0;
while (x < temp.Width * temp.Height)
{
*(++ptr) = *(++ptr) = *(++ptr) = (byte)(boolBitmap[ x /temp.Width,x % temp.Width] ? 255 : 0);
x++;
}
}
temp.UnlockBits(bmpData);
return temp;
}
}
modified on Saturday, May 9, 2009 6:54 AM
|
|
|
|
|
Hello,
Is it possible to show a message box (while the macro is running, importing external data) without buttons, but only with a message and while macro is running and when macro stops running it closes itself.
Thanks.
|
|
|
|
|
No. The MessageBox does not support this. When you show it, your code is blocked until the user clicks OK. You'll have to create your own messagebox form that supports this.
|
|
|
|
|
See this[^] article.
/ravi
|
|
|
|
|
No it is not possible with this MessageBox.Show(). you need to design your own message box type form to accomplish this task.
|
|
|
|
|
Hey Sokka!
Yes, it is obviously possible to show a message box for a limited period of time without any buttons. Create another form and design it like a Message box without any buttons in the same project. Now, in the main form's Button_Click event handler, create an object for that new MessageBox form and assign a timer value to it. You are done.
Hope this helps,
Rajdeep.NET
|
|
|
|
|
|
Hello friends,
how can I search for a file say 'filename.txt' randomly in the C: drive? The drive contains many folders and sub-directories, and thus I want to have a thorough search into all the folders and subdirectories present in the drive for the particular file. Please tell me how.
NOTE: I dont know the names of the directories that are present in the drive.
Hope to recieve help from you guys soon,
Rajdeep.NET
|
|
|
|
|
You obviously have an internet conenction because you're posting here, so I suggest you navigate to http://www.google.com/[^] and search 'c# file search'.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Can you show sample code please. Thank you very much.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
public Answer GoogleSearch(string question)
{
try
{
User.EngageBrain();
User.NavigateToGoogle();
return User.SearchForAnswer(question);
}
catch (StupidityException fail)
{
return (Answer)fail.Message;
}
}
Hope that helps.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
|
Meh, no matter what people try, it always returns null in the end.
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
hahaha
foreach( inch on Jason )
{
Girlfriend.IsHappier();
}
|
|
|
|
|
fileNotFound = true;
while (fileNotFound)
{
pathToTest = GetRandomPath();
fileNotFound = (FileIsInDirectory(pathToTest,fileName);
}
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Be aware that most examples available through a search on google can and probably will result in an PathTooLongException, be sure to use the FindFirstFile function in kernel32.dll
|
|
|
|
|
Hi all,
I have a web application from which i am calling a windows application and while calling the windows application(that has been deployed using click once) i want to send some values in query string, is there any way that i can get that query string in my windows application.
Thanxx
|
|
|
|
|
Dear sir,
i have a json response string like this:
{"trends":{"2009-05-07 18:44:11":[
{"query":"\"Star Trek\"","name":"Star Trek"},
{"query":"\"Manny Ramirez\" OR Ramirez","name":"Manny Ramirez"}, {"query":"KFC","name":"KFC"},
{"query":"\"Swine Flu\"","name":"Swine Flu"},
{"query":"#jonaslive","name":"#jonaslive"}, {"query":"AT&T","name":"AT&T"}, {"query":"#Dollhouse","name":"#Dollhouse"}, {"query":"Dodgers","name":"Dodgers"},
{"query":"\"National Day\" OR \"Mothers Day\"","name":"National Day"}, {"query":"A-Rod","name":"A-Rod"}
]},"as_of":1241721851}
i want to fetch values like:
Star Trek
Manny Ramirez
KFC
..
..
how can i do this?
could u give me some idea??
Thank you!
yogesh
|
|
|
|
|
Unless you identify what it is about the values you want to fetch, that makes them 'fetchable' it will be very difficult for anyone to help you.
Until you do so, we can only guess. People will not waste their time.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi,
i've got a problem when i tried to INSERT details to OLEDB Access.
this is my code:
<pre>
public class registrationClass
{
static string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\WebSites\DB\users.mdb;Persist Security Info=True";
public static string details(string username, string pass, string email)
{
string input;
//bool Enter = true;
OleDbConnection conn = new OleDbConnection(connStr);
conn.Open();
input = String.Format(@"INSERT INTO userAuth (user,password,Email) VALUES ('{0}','{1}','{2}')", username, pass, email);
OleDbCommand cmd = new OleDbCommand(input, conn);
cmd.ExecuteNonQuery();
conn.Close();
return String.Format("Done");
}
</pre>
now, when i searched on the web, i saw that my query is well.
when i did debug to this action, the input looks like:
"INSERT INTO userAuth (user,password,Email) VALUES ('Igor','pass123','igor@email.com')"
whats wrong????????
thank u!!!
|
|
|
|
|
Ido Shahar wrote: i've got a problem
Do you? which problem? what are the symptoms? does it compile? does it run? does it throw an exception?
which exception? at what line? does your SQL statement work for you when entered in Access itself?
|
|
|
|