void imProcessRegionalMaximum(const imImage* src_image, imImage* dst_image) { int i, x, y, offset, offsetA, offsetB, width = src_image->width, height = src_image->height; float* src_data = (float*)src_image->data[0]; imbyte* dst_data = (imbyte*)dst_image->data[0]; for (y = 1; y < height-1; y++) { offset = y * width + 1; offsetA = offset - width; offsetB = offset + width; for (x = 1; x < width-1; x++) { if (src_data[offset]) iCheckMaximum(offset, offsetA, offsetB, src_data, dst_data); offset++; offsetA++; offsetB++; } } // remove false maximum for (y = 2; y < height-2; y++) { offset = y * width + 2; offsetA = offset - 2*width; offsetB = offset + 2*width; for (x = 2; x < width-2; x++) { if (dst_data[offset] == 2) { if (iCheckFalseMaximum(offset, offsetA, offsetB, width, src_data)) iFillValue(dst_data, x, y, width, 0); } offset++; offsetA++; offsetB++; } } // update destiny with remaining maximum for (i = 0; i < src_image->count; i++) { if (dst_data[i] == 2) dst_data[i] = 1; } }
static void iFillValue(imbyte* img_data, int x, int y, int width, int value) { int r = y * width + x; int r1a = r - width; int r1b = r + width; int v; int old_value = img_data[r]; img_data[r] = (imbyte)value; v = img_data[r1a]; // (x,y-1) if (v == old_value) iFillValue(img_data, x, y-1, width, value); v = img_data[r - 1]; // (x-1,y) if (v == old_value) iFillValue(img_data, x-1, y, width, value); v = img_data[r1a - 1]; // (x-1,y-1) if (v == old_value) iFillValue(img_data, x-1, y-1, width, value); v = img_data[r1a + 1]; // (x+1,y-1) if (v == old_value) iFillValue(img_data, x+1, y-1, width, value); v = img_data[r + 1]; // (x+1,y) if (v == old_value) iFillValue(img_data, x+1, y, width, value); v = img_data[r1b]; // (x,y+1) if (v == old_value) iFillValue(img_data, x, y+1, width, value); v = img_data[r1b - 1]; // (x-1,y+1) if (v == old_value) iFillValue(img_data, x-1, y+1, width, value); v = img_data[r1b + 1]; // (x+1,y+1) if (v == old_value) iFillValue(img_data, x+1, y+1, width, value); }
void imProcessRegionalMaximum(const imImage* src_image, imImage* dst_image) { int width = src_image->width, height = src_image->height; float* src_data = (float*)src_image->data[0]; imbyte* dst_data = (imbyte*)dst_image->data[0]; #ifdef _OPENMP #pragma omp parallel for if (IM_OMP_MINHEIGHT(height)) #endif for (int y = 1; y < height-1; y++) { int offset = y * width + 1; int offsetA = offset - width; int offsetB = offset + width; for (int x = 1; x < width-1; x++) { if (src_data[offset]) iCheckMaximum(offset, offsetA, offsetB, src_data, dst_data); offset++; offsetA++; offsetB++; } } // remove false maximum #ifdef _OPENMP #pragma omp parallel for if (IM_OMP_MINHEIGHT(height)) #endif for (int y = 2; y < height-2; y++) { int offset = y * width + 2; int offsetA = offset - 2*width; int offsetB = offset + 2*width; for (int x = 2; x < width-2; x++) { if (dst_data[offset] == 2) { if (iCheckFalseMaximum(offset, offsetA, offsetB, width, src_data)) iFillValue(dst_data, x, y, width, 0); } offset++; offsetA++; offsetB++; } } // update destiny with remaining maximum #ifdef _OPENMP #pragma omp parallel for if (IM_OMP_MINCOUNT(src_image->count)) #endif for (int i = 0; i < src_image->count; i++) { if (dst_data[i] == 2) dst_data[i] = 1; } }