我将 Quad 实现为 BST,但我尝试以这种方式拆分它,但效果不佳
I implemented Quad as BST, but I try to split it this way, but it's not working well
如果wsplit = 1
我想根据宽度分割,否则根据高度分割。
threshold
将定义是否拆分。
tx, ty
将是四边形的左上角坐标。
sx
= 原始图像的宽度
它将像
一样工作
(tx:ty = 0:0 w = 512, h = 512, wsplit = 1) ---> A
拆分后
(tx:ty = 0 :0 w = 256, h = 512, wsplit = 0) ---> B
(tx:ty = 256:0 w = 256, h = 512, wsplit = 0) ---> C
将在 BST(四叉树)
我也是
Quad *split(Image *im, Quad *root, int threshold) {
if (root == NULL)
return NULL;
if (similar(im, root, threshold) == 0){ //this will define should split or not
int tx = root->tx;;
int ty = root->ty;
int w = root->w;
int h = root->h;
int wsplit = root->wsplit;
int sx = root->sx;
int tx2,ty2,w1,w2,h1,h2;
if(wsplit==0){
h1 = (int)floor(h/2);
h2 = h-h1;
ty2 = ty+h1;
wsplit = 1;
}
else{
w1 = (int)floor(w/2);
w2 = w-w1;
tx2 = tx+w1;
wsplit = 0;
}
Quad *first = NULL;
Quad *second = NULL;
first = new_Quad(tx, ty, w1, h1, wsplit, sx);
second = new_Quad(tx2, ty2, w2, h2, wsplit, sx);
root = quad_delete(root, tx, ty);
root = insert(root, first);
root = insert(root, second);
}
split(im, root->left, threshold);
split(im, root->right, threshold);
return root;
}
想一分为二,不知道为什么不行
看来问题是您忘记了初始化所有变量。您应该确保初始化 if
和 else
部分中的所有变量:
if (wsplit == 0) {
w1 = w; // was missing
w2 = w; // was missing
h1 = h / 2;
h2 = h - h1;
tx1 = tx; // was missing
tx2 = tx; // was missing
ty1 = ty; // was missing
ty2 = ty + h1;
wsplit = 1;
} else {
// same issues here
...
}
请注意,您的编译器应该警告您可能未初始化的变量。如果您还没有这样做,请启用编译器警告。然后还要修复编译器产生的所有警告。
如果wsplit = 1
我想根据宽度分割,否则根据高度分割。
threshold
将定义是否拆分。
tx, ty
将是四边形的左上角坐标。
sx
= 原始图像的宽度
它将像
一样工作(tx:ty = 0:0 w = 512, h = 512, wsplit = 1) ---> A
拆分后
(tx:ty = 0 :0 w = 256, h = 512, wsplit = 0) ---> B
(tx:ty = 256:0 w = 256, h = 512, wsplit = 0) ---> C
将在 BST(四叉树)
我也是
Quad *split(Image *im, Quad *root, int threshold) {
if (root == NULL)
return NULL;
if (similar(im, root, threshold) == 0){ //this will define should split or not
int tx = root->tx;;
int ty = root->ty;
int w = root->w;
int h = root->h;
int wsplit = root->wsplit;
int sx = root->sx;
int tx2,ty2,w1,w2,h1,h2;
if(wsplit==0){
h1 = (int)floor(h/2);
h2 = h-h1;
ty2 = ty+h1;
wsplit = 1;
}
else{
w1 = (int)floor(w/2);
w2 = w-w1;
tx2 = tx+w1;
wsplit = 0;
}
Quad *first = NULL;
Quad *second = NULL;
first = new_Quad(tx, ty, w1, h1, wsplit, sx);
second = new_Quad(tx2, ty2, w2, h2, wsplit, sx);
root = quad_delete(root, tx, ty);
root = insert(root, first);
root = insert(root, second);
}
split(im, root->left, threshold);
split(im, root->right, threshold);
return root;
}
想一分为二,不知道为什么不行
看来问题是您忘记了初始化所有变量。您应该确保初始化 if
和 else
部分中的所有变量:
if (wsplit == 0) {
w1 = w; // was missing
w2 = w; // was missing
h1 = h / 2;
h2 = h - h1;
tx1 = tx; // was missing
tx2 = tx; // was missing
ty1 = ty; // was missing
ty2 = ty + h1;
wsplit = 1;
} else {
// same issues here
...
}
请注意,您的编译器应该警告您可能未初始化的变量。如果您还没有这样做,请启用编译器警告。然后还要修复编译器产生的所有警告。