Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I would like to know any algorithm which will allow me to write the edge pixels(edges of the object in the image) from an image into a text file. I want this algorithm for my stego application.

ie, i want to extract the objects edge from the background.

try this link: i dont knw how to tel the exact requirement
http://www.cogs.susx.ac.uk/users/davidy/teachvision/vision3_include/fig17.gif
Posted
Updated 13-Sep-11 5:07am
v3
Comments
Herman<T>.Instance 12-Sep-11 6:28am    
for c or c# (looking a your tags)?
Thiagarajan Duraisamy 13-Sep-11 11:15am    
i need the algorithm alone or to say the idea, i want to work on myself to achieve the solution, wil try to code myself. so ideas will be gr8.
C_Johnson 14-Sep-11 17:26pm    
Mainly for others if you did want to approach writing the algorithm yourself then you will need to read J Cannys paper A computational approach to edge detection available here as it is one of the most effective:

http://www.limsi.fr/Individu/vezien/PAPIERS_ACS/canny1986.pdf

Effectively what the algorithm does is examine each pixel with a set of 3x3 masks (i.e 1 pixel and the surrounding pixels) Each area is examined for edge cues at 0,90 and 45 degree angles. Effectively looking for a change in gradient. If there is a significant change in gradient (this is the thresholds you adjust) then an edge pixels is recorded as a 1 in a blank image. What you end up with is a binary map of edges. The code is not as easy as you would expect to write. On top of this you need to include a gaussian filter to remove noise and histogram analysis to further account for noise variation in pixel intensity's. As I said using existing libraries such as EMGU and openCV are far more efficient else you will be writing code again. Alternatively there is the AForge libraries that are simpler to work with but are not as advanced or powerful. See this article

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

Take Care
Thiagarajan Duraisamy 16-Sep-11 9:12am    
k thanks, tc

Hi,

In c# your looking at something like bellow, personally I would write a Xaml file as then you could use tags for Red Green Blue. Looping through the image is the only option do not write as you get the pixel data as this will slow your program down since writing to your disc is relatively slow.

You could always use 4 lists one for top, bottom, left and right if you wish to keep the points separate. Alternatively positions [0 to (myImage.Width-1)] will be the top. [(myImage.Width-1) to (myImage.Width-1)+(myImage.Width-1)] will be the bottom and so on...

C#
Bitmap my_new_image = new Bitmap(original_image.Width,  original_image.Height);

List<color> my_colour_list = new List<colour>(); //somewhere to store the info as writing the information will take a long time programmatically speaking as your accessing hard drive 

//Top
for (int x = 0; x < myImage.Width; x++)
{
   my_colour_list.Add(output_data.GetPixel(x, 0))    
}

//bottom
for (int x = 0; x < myImage.Width; x++)
{
   my_colour_list.Add(output_data.GetPixel(x, myImage.Height))
}

//Left
for (int y = 0; y < myImage.Height; y++)
{
   my_colour_list.Add(output_data.GetPixel(0, y))
}

//Right
for (int y = 0; y < myImage.Height; y++)
{
   my_colour_list.Add(output_data.GetPixel(myImage.Width, y))
}

//Write the info to a text file (You will have Red, Green, Blue for colour image)
//It's up to you how you make the format

System.IO.StreamWriter file_to_write = new System.IO.StreamWriter("c:\\test.txt");

foreach(Color var in my_colour_list)
{
    //To save R/G/B and Alpha
    file_to_write.WriteLine(var.toString());
    //or just R G B
    file_to_write.WriteLine(var.R.toString());
    file_to_write.WriteLine(var.R.toString());
    file_to_write.WriteLine(var.R.toString());
}</colour></color>


Hope this helps,
Cheers,

Chris
 
Share this answer
 
Comments
BobJanova 13-Sep-11 7:59am    
Good but GetPixel is slow so for large images you should use LockBits and access the bytes directly.
C_Johnson 13-Sep-11 8:22am    
Yes your right and this method would speed up the system http://www.bobpowell.net/lockingbits.htm shows how to do this if anyone's interested. You could speed up the process further by using .NET parallel architecture using System.Threading.Tasks; and implementing a Parallel.For loop and addressing to data to a specific array location. You could also use EMGU a c# wrapper for opencv image processing library which is far more optimised than approaching this in c#. All valid solutions but I provided the simplest. Optimisation of the code can only be applied once you have code that works and I wasn't sure what code base was being worked with so please forgive the simpler answer.
Thiagarajan Duraisamy 13-Sep-11 11:05am    
thanks this works fine for getting the corner points of the image, wat i want is the edge pixels of an object inside the image.
try this link: i dont knw how to tel the exact requirement
http://www.cogs.susx.ac.uk/users/davidy/teachvision/vision3_include/fig17.gif

getting this edge pixels wil help me in hiding the data in a better
C_Johnson 13-Sep-11 11:42am    
Ok the process evolved here is "edge detection" its well document however writing the algorithm out your self us unlikely to be as efficient as well used ones such as canny, prewit, roberts and sobel. Download EMGU and use there inbuilt ones:

http://www.emgu.com/wiki/index.php/Main_Page

Look at the Camera Capture and the shape example provide in the examples folder and a few of the others here's an example:

http://www.emgu.com/wiki/index.php/Shape_%28Triangle,_Rectangle,_Circle,_Line%29_Detection_in_CSharp

This is the important line:

Image<gray, byte=""> cannyEdges = gray.Canny(cannyThreshold, cannyThresholdLinking);

It's very easy to use and will be exactly what you need if you need more help please feel free to ask

Cheers
Chris
Thiagarajan Duraisamy 13-Sep-11 14:50pm    
hmmm, k wil try using this, thanks chris... wil update the result if it works.
The edge pixels of any image should be
(0, 0)
(image.width - 1, 0)
(0, image.height - 1)
(image.width - 1, image.height - 1)


My fault, this gives corners, not edges.
 
Share this answer
 
v2
you can use CImage object

#include <atlimage.h>

CImage TempObj;
TemObj.Load("Image File name");

//you can get Dimesion from
TempObj.GetHeight();
TempObj.GetWidth();

//To GetPixel Data
TempObj.GetPixel(X,Y);
 
Share this answer
 
Comments
abhishek.biradar 13-Sep-11 7:57am    
Sorry its in c++

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900