问题描述
我想自己制作一个简单的骨架算法,而无需在C#中使用Aforge.Net,OpenCV,EmguCV.
谁能帮助我,了解骨架化的工作原理.
我需要一些示例算法.
我进行了搜索,但未找到任何示例.
我的想法如下:
1.步骤:我制作了阈值图像-就绪(CPU& CUDA)
2.步骤:我必须在贴图图像上使用侵蚀-就绪(CPU和CUDA)
3.步骤:我拍摄了第3步的反像-就绪(CPU和CUDA)
4.步骤:骨骼化
使用Aforge.Net可以正常工作,但是我想自己写.
如果我准备好了,我将遵守CUDA.
这是我的代码(存在一些问题:未处理访问冲突异常.):
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)
{
//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;
}
}
}
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");
}
我希望看到更多示例...
/对不起我的英语不好/
谢谢!
佐利
HUN
I would like to see more examples for it...
/Sorry for my bad English/
Thank You!
Zollie
HUN
推荐答案
这篇关于数字图像处理-骨架化/CPU或CUDA/的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!