首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >图像处理误差

图像处理误差
EN

Stack Overflow用户
提问于 2014-06-02 20:07:30
回答 1查看 110关注 0票数 0

我必须在C++中使用diblok 实现基于Adams和Bischof的种子区域生长算法,在这里可以找到http://bit.ly/1nIxphj。这是图2的伪码。

使用鼠标选择种子点后,它将在:0xC0000005: diblook.exe: 0x3d2f6e68.中的0x00416ca0处抛出以下消息:未处理的异常。

这是函数的代码:

代码语言:javascript
复制
void CDibView::OnLButtonDblClk(UINT nFlags, CPoint point)

{ BEGIN_SOURCE_PROCESSING;

代码语言:javascript
复制
int** labels = new int* [dwHeight];
for(int k = 0;k < dwHeight; k++)
    labels[k] = new int[dwWidth];
int noOfRegions = 2;
double meanRegion[2];
double noOfPointsInRegion[2];
for(int i = 0; i < dwHeight ; i++)
    for(int j = 0; j < dwWidth ; j++)
    {
        labels[i][j] = -1;
    }




if(noOfPoints < 6)
{
    CPoint p = GetScrollPosition() + point;
    pos[noOfPoints].x = p.x;
    pos[noOfPoints].y = p.y;
    int regionLabel = 0;
    if(noOfPoints <= noOfPoints / 2)
        labels[p.x][p.y] = regionLabel;
    else 
        labels[p.x][p.y] = regionLabel + 1;
    noOfPoints++;
}
else
{
    // Calculate the mean of each region

    for(int i = 0; i < noOfRegions; i++)
    {
        for(int j = 0 ; j < noOfPoints; j++)
        {
            if(labels[pos[j].x][pos[j].y] == i)
            {
                meanRegion[i] += lpSrc[pos[j].x * w + pos[j].y];
            }
        }
        meanRegion[i] /= 3;
        noOfPointsInRegion[i] = 3;
    }

    for(int seedPoint = 0; seedPoint < noOfPoints; seedPoint++)
    {

        // define list
        node *start, *temp;
        start = (node *) malloc (sizeof(node));
        temp = start;
        temp -> next = NULL;


        for(int i = -1; i <= 1; i++)
            for(int j = -1; j<= 1; j++)
            {
                if(i == 0 && j == 0) continue;
                int gamma = lpSrc[(pos[seedPoint].x + i) *  + pos[seedPoint].y + j] - lpSrc[pos[seedPoint].x * w + pos[seedPoint].y];
                push(start, pos[seedPoint].x + i, pos[seedPoint].y + j, gamma);


            }

        sort(start);

        if(start != NULL)
        {
            node *y = start; 
            pop(start);
            int sameNeighbour = 1;
            int neighValue = -1;
            for(int k = -1; k <= 1; k++)
                for(int l = -1; l <= 1;l++)
                {
                    if(k ==0 && l==0) continue;
                    if(labels[y -> x + k][y -> y + l] != -1)
                    {
                        neighValue = labels[y -> x + k][y -> y + l];
                        break;
                    }
                }
                for(int k = -1; k <= 1; k++)
                    for(int l = -1; l <= 1;l++)
                    {
                        if(k == 0 && l==0) continue;
                        if(labels[y -> x + k][y -> y = 1] != -1 && labels[y -> x + k][y -> y + l] != neighValue)
                            sameNeighbour = 0;
                    }
                    if(sameNeighbour == 1)
                    {
                        labels[y -> x][y -> y] = neighValue;
                        meanRegion[neighValue] = meanRegion[neighValue] * noOfPointsInRegion[neighValue] / noOfPointsInRegion[neighValue] + 1;
                        noOfPointsInRegion[neighValue]++;

                        for(int k = -1; k <= 1; k++)
                            for(int l = -1; l <= 1;l++)
                            {
                                if(k == 0 && l == 0) continue;
                                if(labels[y -> x + k][y -> y + l] == -1 && find(start, y->x + k, y->y + l) == 0)
                                {
                                    int gammak = meanRegion[neighValue] - lpSrc[(y->x +k) * w + (y->y + l)];
                                    push(start, y->x + k, y->y + l, gammak);
                                    sort(start);
                                }
                            }

                    }
                    else
                    {
                        labels[y->x][y->y] = -1;
                    }
        }

    }


    int noOfRegionOne = 0;
    int noOfRegionTwo = 0;
    int noOfBoundary = 0;

    for(int i = 0; i< dwHeight; i++)
        for(int j = 0;j<dwWidth; j++)
        {
            if(labels[i][j] == -1)
                noOfBoundary++;
            else if(labels[i][j] == 0)
                noOfRegionOne++;
            else if(labels[i][j] == 1)
                noOfRegionTwo++;
        }

        CString info;
        info.Format("Boundary %d, One %d, Two %d", noOfBoundary, noOfRegionOne, noOfRegionTwo);
        AfxMessageBox(info);

    noOfPoints = 0;
}

CScrollView::OnLButtonDblClk(nFlags, point);


END_SOURCE_PROCESSING;

}

在选择中断运行后,如下所示:http://postimg.org/image/j2sh9k0a1/

有人能说出什么不对劲吗?为什么不起作用?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-02 20:16:01

您的屏幕截图显示,您的节点(顺便说一句,Y是一个糟糕的名称)中有垃圾值。无意中,我怀疑“排序”正在覆盖您的节点值,从而导致垃圾。我将创建当前节点的静态副本,以防止其在处理过程中更改:

变化

代码语言:javascript
复制
    node *y = start; 
    pop(start);

代码语言:javascript
复制
    node y = *start; 
    pop(start);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24002391

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档