reading pixel's value in an image
-
i have an image of space from which i have to detect objects like stars,so i have to read each pixel's value in image and compare its each pixel's value with its neighbor pixels,if those pixels have same value then those pixels can be one star in space
-
i have an image of space from which i have to detect objects like stars,so i have to read each pixel's value in image and compare its each pixel's value with its neighbor pixels,if those pixels have same value then those pixels can be one star in space
It may not be as simple as that. A lot will depend on the quality of your images, and what was used to produce them, and a star will generally not be a simple area of pixels of the same value. If you want to start writing astronomical image processing software, you should take a close look at a good selection of images from different sources and devices.
There are three kinds of people in the world - those who can count and those who can't...
-
i have an image of space from which i have to detect objects like stars,so i have to read each pixel's value in image and compare its each pixel's value with its neighbor pixels,if those pixels have same value then those pixels can be one star in space
Search the articles for "Image processing for dummies". Christian Graus put together a nice set of articles on the subject.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
It may not be as simple as that. A lot will depend on the quality of your images, and what was used to produce them, and a star will generally not be a simple area of pixels of the same value. If you want to start writing astronomical image processing software, you should take a close look at a good selection of images from different sources and devices.
There are three kinds of people in the world - those who can count and those who can't...
molesworth wrote:
It may not be as simple as that. A lot will depend on the quality of your images, and what was used to produce them, and a star will generally not be a simple area of pixels of the same value.
Unless the image is in single bit depth, or heavily processed it won't be. Raw images in prosumer astronomy cameras are 12/16bit color depth, and since typical pixels are sized to have a capacity of between 40-100k electrons sampling noise is a factor in addition to the quantum noise of the chip itself. Even ignoring noise, unless a star is perfectly centered on the corner between 4 pixels; and the pixels are large enough that all of the diffraction rings are completely on those 4 pixels; and the camera is anti-bloom* or the pixels aren't saturated; or the camera is non anti-bloom and you're only interested in IDing the middle of stars that have bloomed. * normal daylight use cameras have a gap between each pixel on the sensor to keep them from blooming, this results in roughly 50% of the light falling on dead parts of the chip. For taking images of bright objects this doesn't matter (daylight, moon, planets), but doubles your exposure time for everything else. As a result most astrocams use chips that can bloom and require the user to combine multiple short exposures in post-processing. For most purposes this works better, the only exceptions being trying to image a very faint object next to a very bright one (eg the flame nebula (background for the horsehead)).
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
-
i have an image of space from which i have to detect objects like stars,so i have to read each pixel's value in image and compare its each pixel's value with its neighbor pixels,if those pixels have same value then those pixels can be one star in space
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..
-
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
-
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 )
-
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'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);