I made a project to detect the edge of skin cancer lesions.
My goal is to make the dividing line between cancerous lesions and healthy skin.
Input: pictures of skin cancer lesions.
output: images of lesions with the dividing line.
I use the following algorithm
1. check the value of a pixel (already greyscale)
2. if it meets the boundary, mark by giving a value of 1.
3. if not, the mark by giving the value 0.
4. check back for a pixel, 8 neighbors check
5. if all neighbors together, meaning he is not the edge.
6. if the eight neighboring pixels are different means edge, change the pixel value to 255.
My problem, I created this code can not separate the lesion and healthy skin.
maybe there is something wrong with my code or algorithms.
thank you
private void button4_Click(object sender, EventArgs e)
{
minq = 120;
maxq = 240;
BitmapData bmData = RImage.LockBits(new Rectangle(0, 0, RImage.Width, RImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - RImage.Width * 3;
for (int y = 0; y < RImage.Height; ++y)
{
for (int x = 0; x < RImage.Width; ++x)
{
if (p[x] <= maxq && p[x] >= minq)
{
arraynilai[x, y] = 1;
}
else
{
arraynilai[x, y] = 0;
}
p += 3;
}
p += nOffset;
}
}
RImage.UnlockBits(bmData);
}
private void button6_Click(object sender, EventArgs e)
{
BitmapData bmData = RImage.LockBits(new Rectangle(0, 0, RImage.Width, RImage.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
int stride = bmData.Stride;
System.IntPtr Scan0 = bmData.Scan0;
unsafe
{
byte* p = (byte*)(void*)Scan0;
int nOffset = stride - RImage.Width * 3;
for (int y = 1; y < RImage.Height; ++y)
{
for (int x = 1; x < RImage.Width; ++x)
{
rc1 = arraynilai[x - 1, y - 1];
rc2 = arraynilai[x , y - 1];
rc3 = arraynilai[x + 1, y - 1];
rc4 = arraynilai[x + 1, y];
rc5 = arraynilai[x + 1, y + 1];
rc6 = arraynilai[x , y + 1];
rc7 = arraynilai[x - 1, y + 1];
rc8 = arraynilai[x - 1, y];
if (rc1 + rc2 + rc3 + rc4 + rc5 + rc6 + rc7 + rc8 < 8)
{
p[0] = p[1] = p[2] = 255;
}
p += 3;
}
p += nOffset;
}
}
RImage.UnlockBits(bmData);
}