Exemplo n.º 1
0
static void
generate_states(void)
{
    allocate_storage();
    itemset = NEW2(nitems, short);
    ruleset = NEW2(WORDSIZE(nrules), unsigned);
    set_first_derives();
    initialize_states();

    while (this_state)
    {
	closure(this_state->items, this_state->nitems);
	save_reductions();
	new_itemsets();
	append_states();

	if (nshifts > 0)
	    save_shifts();

	this_state = this_state->next;
    }

    finalize_closure();
    free_storage();
}
Exemplo n.º 2
0
tImage *mean_filter(tImage *image, int iter)
/*
this function performs linear mean filtering with window size
3x3. winrow and wincol should be odd integer.
The output is returned.
*/
{
	int rowmin, rowmax, colmin, colmax;
	int i, j, k, l , m;
	int sum, avg;
	tImage *output;

	/* allocate storage for output image */
	output = allocate_storage(image->row,image->col);
	printf("succeed allocating storage row = %d col = %d \n",
	output->row,output->col);

	/* calculate window's size */
	rowmin = (3 - 1 )/ 2;  /* base index for array = 0 */
	rowmax = image->row - rowmin;
	colmin = (3 - 1)/ 2;
	colmax = image->col -colmin;

	k = 9; /* window size */
	for (m=0; m<iter; m++) {
		for (i=rowmin; i<rowmax; i++) {
			for (j=colmin; j<colmax; j++) {
				sum = image->content[i-1][j-1] + image->content[i-1][j] + image->content[i-1][j+1] +
				image->content[i][j-1] + image->content[i][j] + image->content[i][j+1] +
				image->content[i+1][j-1] + image->content[i+1][j] + image->content[i+1][j+1];
				output->content[i][j] = (int) (sum/k);
			}
		}
	}

	/* copy the rest (frame) of the image */
	for (i=0; i<rowmin; i++)
	for (j=0; j<image->col; j++)
	output->content[i][j] = image->content[i][j];
	for (i=rowmin; i<rowmax; i++) {
		for (j=0; j<colmin; j++)
		output->content[i][j] = image->content[i][j];
		for (j=colmax; j<image->col; j++)
		output->content[i][j] = image->content[i][j];
	}
	for (i=rowmax; i<image->row; i++)
	for (j=0; j<image->col; j++)
	output->content[i][j] = image->content[i][j];

	return output;
}
Exemplo n.º 3
0
tImage *nn_filter(tImage *image, int iter)
/*
this function performs nearest neighbor mean filtering with window size
3x3.    The output is returned.
*/
{
	int rowmin, rowmax, colmin, colmax;
	int i, j, k, l , m;
	double sum;
	tImage *output;

	/* allocate storage for output image */
	output = allocate_storage(image->row,image->col);
	printf("succeed allocating storage row = %d col = %d \n",
	output->row,output->col);

	/* calculate window's size */
	rowmin = 1; 
	rowmax = image->row - 1; 
	colmin = 1; 
	colmax = image->col - 1; 

	for (m=0; m<iter; m++) {
		for (i=rowmin; i<rowmax; i++) {
			for (j=colmin; j<colmax; j++) {
				sum = image->content[i][j] + image->content[i][j-1] + image->content[i][j+1] +
				image->content[i-1][j] + image->content[i+1][j];
				output->content[i][j] = (int) (sum/5.0);
			}
		}
	}

	/* copy the rest (frame) of the image */
	for (i=0; i<rowmin; i++)
	for (j=0; j<image->col; j++)
	output->content[i][j] = image->content[i][j];
	for (i=rowmin; i<rowmax; i++) {
		for (j=0; j<colmin; j++)
		output->content[i][j] = image->content[i][j];
		for (j=colmax; j<image->col; j++)
		output->content[i][j] = image->content[i][j];
	}
	for (i=rowmax; i<image->row; i++)
	for (j=0; j<image->col; j++)
	output->content[i][j] = image->content[i][j];

	return output;
}
Exemplo n.º 4
0
void
generate_states (void)
{
  item_number initial_core = 0;
  state_list *list = NULL;
  allocate_storage ();
  new_closure (nritems);

  /* Create the initial state.  The 0 at the lhs is the index of the
     item of this initial rule.  */
  state_list_append (0, 1, &initial_core);

  /* States are queued when they are created; process them all.  */
  for (list = first_state; list; list = list->next)
    {
      state *s = list->state;
      if (trace_flag & trace_automaton)
	fprintf (stderr, "Processing state %d (reached by %s)\n",
		 s->number,
		 symbols[s->accessing_symbol]->tag);
      /* Set up itemset for the transitions out of this state.  itemset gets a
         vector of all the items that could be accepted next.  */
      closure (s->items, s->nitems);
      /* Record the reductions allowed out of this state.  */
      save_reductions (s);
      /* Find the itemsets of the states that shifts can reach.  */
      new_itemsets (s);
      /* Find or create the core structures for those states.  */
      append_states (s);

      /* Create the shifts structures for the shifts to those states,
	 now that the state numbers transitioning to are known.  */
      state_transitions_set (s, nshifts, shiftset);
    }

  /* discard various storage */
  free_closure ();
  free_storage ();

  /* Set up STATES. */
  set_states ();
}
Exemplo n.º 5
0
/* compute the nondeterministic finite state machine (see state.h for details)
from the grammar.  */
void
generate_states()
{
  allocate_storage();
  initialize_closure(nitems);
  initialize_states();

  while (this_state)
    {
      /* Set up ruleset and itemset for the transitions out of this state.
         ruleset gets a 1 bit for each rule that could reduce now.
	 itemset gets a vector of all the items that could be accepted next.  */
      closure(this_state->items, this_state->nitems);
      /* record the reductions allowed out of this state */
      save_reductions();
      /* find the itemsets of the states that shifts can reach */
      new_itemsets();
      /* find or create the core structures for those states */
      append_states();

      /* create the shifts structures for the shifts to those states,
         now that the state numbers transitioning to are known */
      if (nshifts > 0)
        save_shifts();

      /* states are queued when they are created; process them all */
      this_state = this_state->next;
    }

  /* discard various storage */
  finalize_closure();
  free_storage();

  /* set up initial and final states as parser wants them */
  augment_automaton();
}
Exemplo n.º 6
0
tImage *dupl_image(tImage *image, int row, int col)
/*
this function increases the image size by row times and col times
*/
{
	int i, j, r, c; 
	tImage *output;

	/* allocate storage for output image */
	output = allocate_storage(row*image->row, col*image->col);
	printf("succeed allocating storage row = %d col = %d \n", row, col);

	/* start duplicating image by row and col times */
	for (r=0; r<row; r++) {
		for (c=0; c<col; c++) {
			for (i=0; i<image->row; i++) {
				for (j=0; j<image->col; j++) {
					output->content[r*image->row+i][c*image->col+j] = image->content[i][j];
				}
			}
		}
	}
	return output;
}