Click here to Skip to main content
15,499,702 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,

I'd like to make a Simple Skeletonization algorythm by myself without using Aforge.Net, OpenCV, EmguCV in C#.
Can anybody help me, to understand how the skeletonization works.
I need some example algorythm for it.
I searched for it, but i didn't find any example.

My idea is the following:

1. step: I make a thresholded image - Ready (CPU & CUDA)
2. step: I have to use Erosion on tresholded image - Ready (CPU & CUDA)
3. step: I take the inverse image of step 3 - Ready (CPU & CUDA)
4. step: Skeletonization

With Aforge.Net it works fine, but i want to write it by myself.

If I will ready, I will it comply to CUDA.

Here is my Code (It has some problem: Access violation exception was unhandled. ):

C#
class Skeletonization
	{
		private byte fg = byte.MaxValue;
		private byte bg;
 
		public Skeletonization()
		{ }
 
		public Skeletonization(byte bg, byte fg)
		{
			this.bg = bg;
			this.fg = fg;
		}
 
		public byte Background
		{
			get
			{ return this.bg; }
			set
			{ this.bg = value; }
		}
 
		public byte Foreground
		{
			get
			{ return this.fg; }
			set
			{ this.fg = value; }
		}
 
		public unsafe void SkeletonizationFunction(BitmapData sourceData, BitmapData destinationData)
		{
			int width = destinationData.Width;
			int height = destinationData.Height;
			int stride = destinationData.Stride;
			int padding = stride - width;
			byte* sourceDataPtr = (byte*)sourceData.Scan0.ToPointer();
			byte* destinationDataPtr = (byte*)destinationData.Scan0.ToPointer();
 
			for (int i = 0; i < height; i++)
			{
				int minus = -1;
				int zero = 0;
				while (zero < width)
				{
					if (minus == -1)
					{
						if ((int)*sourceDataPtr == (int)this.fg)
							minus = zero;
					}
					else if ((int)*sourceDataPtr != (int)this.fg)
					{
						destinationDataPtr[minus + (zero - minus >> 1)] = this.fg;
						minus = -1;
					}
					++zero;
					++sourceDataPtr;
				}
				if (minus != -1)
					destinationDataPtr[minus + (width - minus >> 1)] = this.fg;
				sourceDataPtr += padding;
				destinationDataPtr += stride;
			}
			for (int i = 0; i < width; i++)
			{
				byte* sourceDataPtr2 = sourceDataPtr + i;
				byte* destinationDataPtr2 = destinationDataPtr + i;
				int minus = -1;
				int zero = 0;
				while (zero < height)
				{
					if (minus == -1)
					{
//Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
						if ((int) *sourceDataPtr2 == (int)this.fg)
							minus = zero;
					}
					else if ((int) *sourceDataPtr2 != (int)this.fg)
					{
						destinationDataPtr2[((IntPtr)(stride * (minus + (zero - minus >> 1)))).ToInt64()] = this.fg;
						minus = -1;
					}
					zero++;
					sourceDataPtr2 += stride;
				}
				if (minus!=-1)
					destinationDataPtr2[((IntPtr)(stride * (minus + (height - minus >> 1)))).ToInt64()] = this.fg;
			}
		}	
	}


C#
private void button1_Click(object sender, EventArgs e)
		{
			Bitmap bmpS = new Bitmap("x.jpg");
			Bitmap bmpD = new Bitmap(bmpS.Width, bmpS.Height);
			BitmapData bmpSourceD = bmpS.LockBits(new Rectangle(0, 0, bmpS.Width, bmpS.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
			BitmapData bmpDestinationD = bmpD.LockBits(new Rectangle(0, 0, bmpS.Width, bmpS.Height), ImageLockMode.ReadOnly, PixelFormat.Format8bppIndexed);
 
			Skeletonization sk = new Skeletonization();
			sk.SkeletonizationFunction(bmpSourceD, bmpDestinationD);
 
			bmpS.UnlockBits(bmpSourceD);
			bmpD.UnlockBits(bmpDestinationD);
 
			bmpD.Save("a.jpg");
		}


I would like to see more examples for it...

/Sorry for my bad English/
Thank You!

Zollie
HUN
Posted
Updated 24-Sep-12 22:32pm
v3
Comments
fjdiewornncalwe 21-Sep-12 10:13am     CRLF
How do you propose to write software to accomplish something when you have no idea of how the logic of the process works? You have to understand how skeletonization works first and then break the process down into its components. Then you have to figure out how to make those components work in code and how they will relate and tie back into each other to come up with a complete solution. If you want to write it yourself, then you need to do these things. When you have tried something come back and ask questions related to the sticky points in your code. Good Luck and cheers.
thezollie 25-Sep-12 3:16am     CRLF
You always know how the algorithms work? It is for me fist research work, and after I finished, I write it myself. I am concerded with it since last week. Just i thought, that here are some people, who give me the right way... Thanks!
Steve Maier 21-Sep-12 12:02pm    
Are you sure that you want to use CUDA and be tied to nVidia chips? OpenCL is very much like CUDA since nVidia was on that comittee, and it can run on other GPUs even the third gen Intel chips with embedded GPUs.
thezollie 25-Sep-12 2:49am    
Yes I am sure. I know it's architecture, I am a researcher of it. I am going to write my theses from it. I work with nVidia graphics cards since Januar.
Sergey Alexandrovich Kryukov 21-Sep-12 12:15pm     CRLF
If it works with AForge.NET, why it does not serve as the example you are looking for? Why do you think that you can get better example if you ask this question. Keep using AForge.NET, just look at the code thoroughly. -- That's the answer. That's it -- this is not a question. --SA

1 solution

Please delete my question.

Thank you!
Zollie
 
Share this answer
 

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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