mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
Fixed dilate.
This was bugged. Tested and now works.
This commit is contained in:
parent
fe36dd8ff4
commit
bb9d79d744
@ -610,7 +610,7 @@ static void imlib_erode_dilate(image_t *img, int ksize, int threshold, int e_or_
|
|||||||
if ((!!buffer[buffer_idx]) == e_or_d) {
|
if ((!!buffer[buffer_idx]) == e_or_d) {
|
||||||
continue; // short circuit (makes this very fast - usually)
|
continue; // short circuit (makes this very fast - usually)
|
||||||
}
|
}
|
||||||
int acc = -1; // don't count center pixel...
|
int acc = e_or_d ? 0 : -1; // don't count center pixel...
|
||||||
for (int j=-ksize; j<=ksize; j++) {
|
for (int j=-ksize; j<=ksize; j++) {
|
||||||
for (int k=-ksize; k<=ksize; k++) {
|
for (int k=-ksize; k<=ksize; k++) {
|
||||||
if (IM_X_INSIDE(img, x+k) && IM_Y_INSIDE(img, y+j)) {
|
if (IM_X_INSIDE(img, x+k) && IM_Y_INSIDE(img, y+j)) {
|
||||||
@ -622,8 +622,13 @@ static void imlib_erode_dilate(image_t *img, int ksize, int threshold, int e_or_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!e_or_d) {
|
||||||
// Preserve original pixel value...
|
// Preserve original pixel value...
|
||||||
if (acc < threshold) buffer[buffer_idx] = 0;
|
if (acc < threshold) buffer[buffer_idx] = 0; // clear
|
||||||
|
} else {
|
||||||
|
// Preserve original pixel value...
|
||||||
|
if (acc > threshold) buffer[buffer_idx] = -1; // set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (y>=ksize) {
|
if (y>=ksize) {
|
||||||
memcpy(img->pixels+((y-ksize)*img->w),
|
memcpy(img->pixels+((y-ksize)*img->w),
|
||||||
@ -645,7 +650,7 @@ static void imlib_erode_dilate(image_t *img, int ksize, int threshold, int e_or_
|
|||||||
if ((!!((uint16_t *) buffer)[buffer_idx]) == e_or_d) {
|
if ((!!((uint16_t *) buffer)[buffer_idx]) == e_or_d) {
|
||||||
continue; // short circuit (makes this very fast - usually)
|
continue; // short circuit (makes this very fast - usually)
|
||||||
}
|
}
|
||||||
int acc = -1; // don't count center pixel...
|
int acc = e_or_d ? 0 : -1; // don't count center pixel...
|
||||||
for (int j=-ksize; j<=ksize; j++) {
|
for (int j=-ksize; j<=ksize; j++) {
|
||||||
for (int k=-ksize; k<=ksize; k++) {
|
for (int k=-ksize; k<=ksize; k++) {
|
||||||
if (IM_X_INSIDE(img, x+k) && IM_Y_INSIDE(img, y+j)) {
|
if (IM_X_INSIDE(img, x+k) && IM_Y_INSIDE(img, y+j)) {
|
||||||
@ -657,8 +662,13 @@ static void imlib_erode_dilate(image_t *img, int ksize, int threshold, int e_or_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!e_or_d) {
|
||||||
// Preserve original pixel value...
|
// Preserve original pixel value...
|
||||||
if (acc < threshold) ((uint16_t *) buffer)[buffer_idx] = 0;
|
if (acc < threshold) ((uint16_t *) buffer)[buffer_idx] = 0; // clear
|
||||||
|
} else {
|
||||||
|
// Preserve original pixel value...
|
||||||
|
if (acc > threshold) ((uint16_t *) buffer)[buffer_idx] = -1; // set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (y>=ksize) {
|
if (y>=ksize) {
|
||||||
memcpy(((uint16_t *) img->pixels)+((y-ksize)*img->w),
|
memcpy(((uint16_t *) img->pixels)+((y-ksize)*img->w),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user