Beispiel #1
0
RBNode* SearchMin(RBNode* Tree)
{
	if(Tree == &Nil)
		return &Nil;

	if(Tree->Left == &Nil)
		return Tree;
	else
		return SearchMin(Tree->Left);
}
Beispiel #2
0
RBNode* Delete(RBNode** Root, int Data)
{
	RBNode* Deleted = NULL;
	RBNode* Successor = NULL;
	RBNode* Target = Search((*Root), Data);

	if(Target == NULL)
		return NULL;

	if(Target->Left == &Nil || Target->Right == &Nil)
		Deleted = Target;
	else
	{
		Deleted = SearchMin(Target->Right);
		Target->Data = Deleted->Data;
	}

	if(Deleted->Left != &Nil)
		Successor = Deleted->Left;
	else

		Successor = Deleted->Right;

	Successor->Parent = Deleted->Parent;

	if(Deleted->Parent ==NULL)
		(*Root) = Successor;
	else
	{
		if(Deleted == Deleted->Parent->Left)
			Deleted->Parent->Left = Successor;
		else
			Deleted->Parent->Right = Successor;
	}

	if(Deleted->Color == Black)
		DeleteAfter(Root,Successor);

	return Deleted;
}
void edge_prefiltering(int imageHeight,int imageWidth, short **buf, short **edg_Bbuf, int a )
{

    int i,j;


//prefiltering A
    //int a = 5 ;
    unsigned char *b_buf;
    unsigned char *c_buf;
    unsigned char unchar_delta;
    int m,n;
    m=n=0;

    char charMiddleFunction=0;
    char charNonlinearFunction=0;
    int intCenterRow,intCenterColumn;
    int	intNeighborRow,intNeighborColumn;
    intCenterRow=intCenterColumn=intNeighborRow=intNeighborColumn=0;

    int intRGBco;
    int intCount;
    int iSgm;
    for(intCount = 1 ; intCount < 3 ; intCount++)
    {
        for(intRGBco=0 ; intRGBco<3 ; intRGBco++)
        {
            for( intCenterRow = 0; intCenterRow < imageHeight; intCenterRow++ )
            {
                for( intCenterColumn = intRGBco; intCenterColumn < (imageWidth * 3); intCenterColumn += 3 ) {
                    for(  i = -1; i < 2 ; i++ )
                    {
                        for(  j = -3  ; j < 6 ; j += 3 )
                        {

                            intNeighborRow=intCenterRow+i;
                            intNeighborColumn=intCenterColumn+j;


                            if(intNeighborRow < 0)
                            {
                                intNeighborRow = 0;
                                i = intNeighborRow - intCenterRow;
                            }

                            if(intNeighborColumn < 0)
                            {
                                intNeighborColumn = 0;
                                j = intNeighborColumn - intCenterColumn;
                            }

                            if(( intNeighborRow == intCenterRow ) && ( intNeighborColumn == intCenterColumn))
                                continue;

                            if((intNeighborRow > (imageHeight-1)) || (intNeighborColumn > (imageWidth-1) * 3))
                                continue;
                            if(intNeighborRow >= 0 && intNeighborColumn >= 0 && intNeighborRow <= imageHeight && intNeighborColumn <= imageWidth * 3) {
                                if(fabs(buf[intNeighborRow][intNeighborColumn]-buf[intCenterRow][intCenterColumn])<=a)
                                    charMiddleFunction=(buf[intNeighborRow][intNeighborColumn]-buf[intCenterRow][intCenterColumn]);
                                else if(fabs(buf[intNeighborRow][intNeighborColumn]-buf[intCenterRow][intCenterColumn])>(3*a))
                                    charMiddleFunction = 0 ;
                                else {
                                    if((buf[intNeighborRow][intNeighborColumn]-buf[intCenterRow][intCenterColumn])<0)
                                        iSgm=(-1);
                                    else
                                        iSgm=1;
                                    charMiddleFunction = (((3*a-buf[intNeighborRow][intNeighborColumn]+buf[intCenterRow][intCenterColumn] )/2)*iSgm);
                                }
                            }
                            charNonlinearFunction+=charMiddleFunction;



                        }
                    }
                    edg_Abuf[intCenterRow][intCenterColumn]=buf[intCenterRow][intCenterColumn]+ charNonlinearFunction/8 ;
                    charNonlinearFunction=0;

                }
            }

        }
    }





//prefiltering B



    c_buf = (unsigned char *) calloc(imageHeight, sizeof(unsigned char ));
    b_buf = (unsigned char *) calloc(imageHeight, sizeof(unsigned char ));


    for(intRGBco=0 ; intRGBco<3 ; intRGBco++)
    {
        for( intCenterRow = 0; intCenterRow < imageHeight; intCenterRow++ )
        {
            for( intCenterColumn = intRGBco; intCenterColumn < (imageWidth * 3); intCenterColumn += 3 )
            {
                for(  i = -1; i < 2 ; i++ )
                {
                    for(  j = -3  ; j < 6 ; j += 3 )
                    {

                        intNeighborRow=intCenterRow+i;
                        intNeighborColumn=intCenterColumn+j;


                        if(intNeighborRow < 0)
                        {
                            intNeighborRow = 0;
                            i = intNeighborRow - intCenterRow;
                        }

                        if(intNeighborColumn < 0)
                        {
                            intNeighborColumn = 0;
                            j = intNeighborColumn - intCenterColumn;
                        }

                        if(( intNeighborRow == intCenterRow ) && ( intNeighborColumn == intCenterColumn))
                            continue;

                        if((intNeighborRow > (imageHeight-1)) || (intNeighborColumn > (imageWidth-1) * 3))
                            continue;


                        if(intNeighborRow >= 0 && intNeighborColumn >= 0 && intNeighborRow <= imageHeight && intNeighborColumn <= imageWidth * 3)
                        {
                            if((edg_Abuf[intNeighborRow][intNeighborColumn]-edg_Abuf[intCenterRow][intCenterColumn]) <= 0 )
                            {
                                b_buf[m]=0;
                                m+=1;
                            }

                            else {
                                b_buf[m]=(edg_Abuf[intNeighborRow][intNeighborColumn]-edg_Abuf[intCenterRow][intCenterColumn])/255;
                                m+=1;
                            }

                            if((edg_Abuf[intCenterRow][intCenterColumn]-edg_Abuf[intNeighborRow][intNeighborColumn]) <= 0 )
                            {
                                c_buf[n]=0;
                                n+=1;
                            }
                            else
                            {
                                c_buf[n]=(edg_Abuf[intCenterRow][intCenterColumn]-edg_Abuf[intNeighborRow][intNeighborColumn])/255;
                                n+=1;
                            }
                        }
                    }
                }

                m=n=0;
                unchar_delta = SearchMin(c_buf, 8) - SearchMin(b_buf, 8);
                edg_Bbuf[intCenterRow][intCenterColumn] = edg_Abuf[intCenterRow][intCenterColumn] - 255 * unchar_delta;

            }
        }
    }

}