PDA

View Full Version : Sample of ISE3MorphoThinning1Bit



Chris
01-15-2003, 12:01 AM
http://www.smalleranimals.com/images/morpho.avi

this is an animated sample of the new ISEffects function ISE3MorphoThinning1Bit in action. it's 30 frames of one thinning pass each. (135K, AVI)

-c

--
chris losinger
smallest@smalleranimals.com

Chris
01-15-2003, 12:19 AM
// load a one bit image
RGBQUAD pal[256];
UINT32 w1, h1;
HISSRC hSrc = IS3OpenFileSource(DPIX"bwliz.tif");
HGLOBAL hImg1 = IS3ReadTIFF(hSrc, &w1, &h1, 1, pal, 0, 0);

CWaitCursor bob;

// define 8 foreground masks
int m0[9] =
{
0, 0, 0,
1, 1, 1,
1, 1, 1,
};

int m1[9] =
{
1, 1, 1,
1, 1, 1,
0, 0, 0,
};

int m2[9] =
{
0, 1, 1,
0, 1, 1,
0, 1, 1,
};

int m3[9] =
{
1, 1, 0,
1, 1, 0,
1, 1, 0,
};

int m4[9] =
{
1, 1, 1,
0, 1, 1,
0, 0, 1,
};

int m5[9] =
{
0, 0, 1,
0, 1, 1,
1, 1, 1,
};

int m6[9] =
{
1, 1, 1,
1, 1, 0,
1, 0, 0,
};

int m7[9] =
{
1, 0, 0,
1, 1, 0,
1, 1, 1,
};

// assign those masks to our A mask array
int *ma[8];
ma[0] = m0;
ma[1] = m1;
ma[2] = m2;
ma[3] = m3;
ma[4] = m4;
ma[5] = m5;
ma[6] = m6;
ma[7] = m7;

// our B (background) masks
int mb0[9], mb1[9], mb2[9], mb3[9], mb4[9], mb5[9], mb6[9], mb7[9];

// assign those to our B mask array
int *mb[8];
mb[0] = mb0;
mb[1] = mb1;
mb[2] = mb2;
mb[3] = mb3;
mb[4] = mb4;
mb[5] = mb5;
mb[6] = mb6;
mb[7] = mb7;

// now, fill the background masks with the compliment of the A masks
// (swap 1 for 0 and 0 for 1)
for (i=0;i<8;i++)
{
for (int j=0;j<9;j++)
{
int *pIn = ma[i];
int *pOut = mb[i];

if (pIn[j] == 0)
pOut[j] = 1;
else
pOut[j] = 0;
}
}

// we'll need a temp 1-bit output buffer
UINT32 rs1 = (w1 + 7) / 8;
BYTE *pOut1 = new BYTE[rs1 * h1];

// get a DC to draw on
CClientDC dc(this);

// loop

// the 30 was determined experimentally. each image is different and will require
// a different number of passes to acheive total thinning.
for (i=0;i<30;i++)
{
int len = rs1 * h1;

// do a single thinning iteration.

/*
normal, non-animated use would be to give a high maximum iteration
count (second to last parameter) in ISE3MorphoThinning1Bit. the function
will quit iterating when there are no changes from one iteration to the
next - meaning no further thinning is possible. things run slightly faster
if you let ISE3MorphoThinning1Bit do all the iterations (because of temp
buffer allocations, setup, etc inside ISE3MorphoThinning1Bit).

but here we use a 1 for max iterations because we want to see the results
after each iteration before continuing to the next.
*/
ISE3MorphoThinning1Bit((BYTE *)hImg1, w1, h1, rs1, pOut1, ma, 3, mb, 3, 8, 1, 0);

// copy the output to the input, for the next iteration
memcpy(hImg1, pOut1, len);

// draw it
IS3Draw1Bit(dc.m_hDC, (BYTE *)pOut1, w1, h1, pal, w1, 0, w1, h1, NULL);
}

// done
delete [] pOut1;
ISFree(hImg1);

--
chris losinger
smallest@smalleranimals.com