Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

reduce the edges width by one pixel wide by thinning using morphology concept

9 views
Skip to first unread message

rabia fyz

unread,
Jun 5, 2011, 7:55:37 AM6/5/11
to
Hi all,

Statement: Thinning algorithms, reducing the edge width to one pixel.

as i know thinning algorithm can be applied after 1st order derivation
convolution operator. so that edges width will get reduce to one
pixel.

Test: http://imm.io/6bNo

first image is original image , second ine is from Prewitt 1st
derivative operator and the last one is from Thinning algorithm using
morphology concept..

so My code in MFC c++ :

void CImageToolDoc::OnMorphologyThinning()
{
CDib dib = m_Dib;
DibErosion(dib);
DibDilation(dib);
DibErosion(dib);
AfxNewImage(dib);
}

void DibDilation(CDib& dib)
{
int i,j;

int w = dib.GetWidth();

int h=dib.GetHeight();

CDib cpy =dib;

BYTE** ptr1 = dib.GetPtr();
BYTE** ptr2 = cpy.GetPtr();

for(j=1;j<h-1;j++)
{
for(i=1;i<w-1;i++)
{
if(ptr2[j][i] !=0)
{

if(ptr2[j-1][i-1] == 0 || ptr2[j-1][i] ==0 || ptr2[j-1][i+1] ==0
||
ptr2[j][i-1] ==0 || ptr2[j][i+1] ==0 ||
ptr2[j+1][i-1] == 0 || ptr2[j+1][i] == 0 || ptr2[j+1][i+1] ==0)

{

ptr1[j][i] = 0;
}
}

}
}

}

void DibErosion(CDib& dib)
{
int i,j;

int w = dib.GetWidth();
int h=dib.GetHeight();

CDib cpy =dib;

BYTE** ptr1 = dib.GetPtr();
BYTE** ptr2 = cpy.GetPtr();

for(j=1;j<h-1;j++)
{
for(i=1;i<w-1;i++)
{
if(ptr2[j][i] ==0)
{
if(ptr2[j-1][i-1] !=0 || ptr2[j-1][i] !=0 || ptr2[j-1][i+1] !=0
||
ptr2[j][i-1] !=0 ||ptr2[j][i] !=0 || ptr2[j][i+1] !=0 ||
ptr2[j+1][i-1] != 0 || ptr2[j+1][i] != 0 || ptr2[j+1][i+1] !=0)

{
ptr1[j][i] =1;
}
}
}
}
}

as you can see my last image result after applying the thinning
algorithm on prewitt result ..but my edges are still wide,, not reduce
by 1 pixel..

TO be verry frank, i did not clear Thinning algorithm perfectly..
Can any one guide me,,Its urgent,,Thanks

0 new messages