📄 segment2.c
字号:
} /* ends is_close */
/*******************************************
*
* edge_region(..
*
* This function segments an image by
* growing regions inside of edges.
* The steps are:
* . detect edges
* . threshold edge output to a
* percent value
* . remove edges from consideration
* . grow regions
*
*******************************************/
edge_region(the_image, out_image,
edge_type, min_area,
max_area, diff, percent, set_value,
erode, rows, cols, bits_per_pixel)
float percent;
int edge_type;
long bits_per_pixel, cols, rows;
short diff, erode,
max_area, min_area,
set_value,
**the_image,
**out_image;
{
int a, b, count, i, j, k,
length, width;
short cutoff;
unsigned long histogram[GRAY_LEVELS+1];
/***************************
*
* Detect the edges. Do
* not threshold.
*
****************************/
if(edge_type == 1 ||
edge_type == 2 ||
edge_type == 3)
detect_edges(the_image, out_image,
edge_type, 0, 0,
rows, cols,
bits_per_pixel);
if(edge_type == 4){
quick_edge(the_image, out_image,
0, 0,
rows, cols,
bits_per_pixel);
} /* ends if 4 */
if(edge_type == 5){
homogeneity(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 5 */
if(edge_type == 6){
difference_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 6 */
if(edge_type == 7){
contrast_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 7 */
if(edge_type == 8){
gaussian_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
3, 0, 0);
} /* ends if 8 */
if(edge_type == 10){
range(the_image, out_image,
rows, cols,
bits_per_pixel,
3, 0, 0);
} /* ends if 10 */
if(edge_type == 11){
variance(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 11 */
/**write_array_into_tiff_image("f:e1.tif", out_image,
il, ie, ll, le);**/
/* copy out_image to the_image */
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
the_image[i][j] = out_image[i][j];
/******************************
*
* Threshold the edge detector
* output at a given percent.
* This eliminates the weak
* edges.
*
*******************************/
zero_histogram(histogram, GRAY_LEVELS+1);
calculate_histogram(the_image, histogram,
rows, cols);
find_cutoff_point(histogram, percent, &cutoff,
rows, cols);
threshold_image_array(the_image, out_image,
GRAY_LEVELS, cutoff,
set_value, rows, cols);
if(erode != 0){
/* copy out_image to the_image */
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
the_image[i][j] = out_image[i][j];
erode_image_array(the_image, out_image,
set_value, erode,
rows, cols);
} /* ends if erode */
/*******************************
*
* Set all the edge values to
* FORGET_IT so the region
* growing will not use those
* points.
*
*******************************/
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
if(out_image[i][j] == set_value)
out_image[i][j] = FORGET_IT;
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
the_image[i][j] = out_image[i][j];
pixel_grow(the_image, out_image, diff,
min_area, max_area,
rows, cols);
} /* ends edge_region */
/*******************************************
*
* gray_shade_region(...
*
* This function segments an image by
* growing regions based only on gray
* shade.
*
*******************************************/
gray_shade_region(the_image, out_image,
diff, min_area, max_area,
rows, cols)
long cols, rows;
short **the_image,
**out_image,
diff, min_area, max_area;
{
int a, b, big_count, count, i, j, k, l,
not_finished, length, width;
printf("\nDEBUG> GSR> before calling pixel grow");
pixel_grow(the_image, out_image, diff,
min_area, max_area,
rows, cols);
printf("\nDEBUG> GSR> after calling pixel grow");
} /* ends gray_shade_region */
/*******************************************
*
* edge_gray_shade_region(..
*
* This function segments an image by
* growing gray shade regions inside of
* edges. It combines the techniques
* of the edge_region and gray_shade_region
* functions.
*
* The steps are:
* . detect edges
* . threshold edge output to a
* percent value
* . lay the edges on top of the original
* image to eliminate them from
* consideration
* . grow regions
*
*******************************************/
edge_gray_shade_region(in_name, the_image,
out_image, edge_type,
min_area, max_area, diff, percent,
set_value, erode,
rows, cols, bits_per_pixel)
char in_name[];
float percent;
int edge_type;
long bits_per_pixel, cols, rows;
short diff, erode,
max_area, min_area,
set_value,
**the_image,
**out_image;
{
int a, b, count, i, j, k,
length, width;
short cutoff;
unsigned long histogram[GRAY_LEVELS+1];
/***************************
*
* Detect the edges. Do
* not threshold.
*
****************************/
if(edge_type == 1 ||
edge_type == 2 ||
edge_type == 3)
detect_edges(the_image, out_image,
edge_type, 0, 0,
rows, cols,
bits_per_pixel);
if(edge_type == 4){
quick_edge(the_image, out_image,
0, 0,
rows, cols,
bits_per_pixel);
} /* ends if 4 */
if(edge_type == 5){
homogeneity(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 5 */
if(edge_type == 6){
difference_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 6 */
if(edge_type == 7){
contrast_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 7 */
if(edge_type == 8){
gaussian_edge(the_image, out_image,
rows, cols,
bits_per_pixel,
3, 0, 0);
} /* ends if 8 */
if(edge_type == 10){
range(the_image, out_image,
rows, cols,
bits_per_pixel,
3, 0, 0);
} /* ends if 10 */
if(edge_type == 11){
variance(the_image, out_image,
rows, cols,
bits_per_pixel,
0, 0);
} /* ends if 11 */
/**write_array_into_tiff_image("f:e1.tif", out_image,
il, ie, ll, le);**/
/* copy out_image to the_image */
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
the_image[i][j] = out_image[i][j];
/******************************
*
* Threshold the edge detector
* output at a given percent.
* This eliminates the weak
* edges.
*
*******************************/
zero_histogram(histogram, GRAY_LEVELS+1);
calculate_histogram(the_image, histogram,
rows, cols);
find_cutoff_point(histogram, percent, &cutoff,
rows, cols);
threshold_image_array(the_image, out_image,
GRAY_LEVELS, cutoff,
set_value, rows, cols);
if(erode != 0){
/* copy out_image to the_image */
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
the_image[i][j] = out_image[i][j];
erode_image_array(the_image, out_image,
set_value, erode,
rows, cols);
} /* ends if erode */
/*******************************
*
* Read the original gray shade
* image back into the_image.
*
*******************************/
read_image_array(in_name, the_image);
/*******************************
*
* Overlay the edge values
* on top of the original
* image by setting them to
* FORGET_IT so the region
* growing will not use those
* points.
*
*******************************/
for(i=0; i<rows; i++)
for(j=0; j<cols; j++)
if(out_image[i][j] == set_value)
the_image[i][j] = FORGET_IT;
/**write_array_into_tiff_image("f:e4.tif", the_image,
il, ie, ll, le);**/
pixel_grow(the_image, out_image, diff,
min_area, max_area,
rows, cols);
} /* ends edge_gray_shade_region */
show_stackp()
{
char r[80];
struct stacksp *temp;
temp = stackp;
while(temp != NULL){
printf("\n\t\t\t\t%d %d %x %x",temp->x,temp->y, temp, temp->next);
temp = temp->next;
}
}
int is_not_emptyp(pointer)
struct stacksp *pointer;
{
int result = 0;
if(pointer != NULL)
result = 1;
return(result);
} /* ends is_empty */
pushp(x, y)
short x, y;
{
struct stacksp *new_one;
new_one = (struct stacksp *)
calloc(1, sizeof(struct stacksp ));
new_one->next = stackp;
new_one->x = x;
new_one->y = y;
stackp = new_one;
} /* ends push */
popp(x, y)
short *x, *y;
{
struct stacksp *temp;
temp = stackp;
*x = stackp->x;
*y = stackp->y;
stackp = stackp->next;
free(temp);
} /* ends pop */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -