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. ):
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)
{
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;
}
}
}
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