Beispiel #1
0
void robot_mt_cell (FILTER_DESC *filter_desc)
{
	NEURON_LAYER_LIST *n_list;
	NEURON_LAYER *nl_complex_left, *nl_complex_right, *nl_complex_binocular;
	PARAM_LIST *p_list;
	int i;
        //int j;
	int num_neurons, numNL, nNumParam;
	float fltComplexBinocular, fltComplexLeft, fltComplexRight, k;

	for (numNL = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, numNL++)
		;

	if (numNL != 3) 
	{
		Erro ("Wrong number of neuron layers. The robot_mt_cell must be applied on three neuron layers.", "", "");
		return;
	}

	for (i = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, i++)
	{
		if (n_list->next != NULL)
		{
			if (n_list->neuron_layer->output_type != n_list->next->neuron_layer->output_type)
			{
				Erro ("The robot_mt_cell must be applied on neuron layers with the same output_type.", "", "");
				return;
			}
		}
	}

	// Achar o numero de parametros
	for (nNumParam = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, nNumParam++);
	nNumParam--;

	// Numero de neuron layers deve ser igual a tres
	if (nNumParam != 1)
	{
		Erro ("The robot_sum_filter_normalized must have one parameter: Selectivity.", "", "");
		return;
	}

	// Seletividade
	k = filter_desc->filter_params->next->param.fval;

	nl_complex_left = filter_desc->neuron_layer_list->neuron_layer;
	nl_complex_right = filter_desc->neuron_layer_list->next->neuron_layer;
	nl_complex_binocular = filter_desc->neuron_layer_list->next->next->neuron_layer;

	num_neurons = get_num_neurons (filter_desc->output->dimentions);

	for (i = 0; i < num_neurons; i++)
	{
		fltComplexLeft = nl_complex_left->neuron_vector[i].output.fval;
		fltComplexRight = nl_complex_right->neuron_vector[i].output.fval;
		fltComplexBinocular = nl_complex_binocular->neuron_vector[i].output.fval;
		
		filter_desc->output->neuron_vector[i].output.fval = fltComplexBinocular / (fltComplexLeft + fltComplexRight + k);
	}
}
Beispiel #2
0
void ComandoCall::Interpreta( Contexto& C )
{
	if ( (!identificador) || (!param_reais) )
		throw Erro("\nUnexpected NULL pointer.");

	/* Obtém Procedimento */
	Procedimento * P = C.obtemProcedimento(*identificador);
	
	/* Checa número de Parâmetros */
	ListaVariaveis * params = P->obtemParametros();
	if ( params->tamanho() != param_reais->tamanho() )
		throw Erro("\nProcedimento inválido: número de parâmetros errado");
	
	/* Atribui parâmetros e adiciona as variáveis no RA */
	int i;
	std::vector<double> p_reais = param_reais->Avalia(C);
	
	/* Adiciona novo Registro de Ativação */
	C.adicionaRA();
	for (i = 0; i < params->tamanho() ; i++)
	{
		C.adicionaVariavel((*params)[i], p_reais[i]);
	}

	/* Executa Procedimento */
	Comando * comandoLocal = P->obtemLocal();
	comandoLocal->Interpreta(C);
	ListaComandos * cmds = P->obtemComandos();
	cmds->Interpreta(C);

	/* Remove Registro de Ativação */
	C.removeRA();
}
//---------------------------------------------------------------------------
bool __fastcall TRawPrint::FechaDispositivo(void)
{
 bool Retorno = true;

 try
  {
   if (DispAberto)
    {
     if (PaginaAberta)
      {
       if(!EndPagePrinter(hPrinter))
        Erro("Erro ao Finalizar Página");

       if(!EndDocPrinter(hPrinter))
        Erro("Erro ao Finalizar Documento");
       else
        {
         if(!ClosePrinter(hPrinter))
          {
           Erro("Erro ao Fechar a Impressora");
           Retorno = false;
          }
          DispAberto = false;
        }
      }
    }
  }
 catch(Exception & E)
  {
   Erro("Erro ao Fechar a Impressora.\r\n\r\n" + E.Message + "\r\n");
  }
 return Retorno;
};
void 
hsv_v_filter(FILTER_DESC *filter_desc)
{
	// http://en.wikipedia.org/wiki/HSL_and_HSV
	// http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	int r, g, b;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			
			nl_output->neuron_vector[xo + yo * wo].output.ival = max_value(r, g, b);
		}
	}
}
Beispiel #5
0
void robot_complex_cell (FILTER_DESC *filter_desc)
{
	NEURON_LAYER_LIST *n_list;
	NEURON_LAYER **nl;
	int i, j;
	int num_neurons, numNL;
	double dif_accumulator, a, b;

	for (numNL = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, numNL++)
		;

	if (filter_desc->private_state == NULL)
	{
		if ((numNL % 2) != 0) 
		{
			Erro ("Wrong number of neuron layers. The robot_complex_cell must be applied on a even number of neuron layers.", "", "");
			return;
		}
	
		for (i = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, i++)
		{
			if (n_list->next != NULL)
			{
				if (n_list->neuron_layer->output_type != n_list->next->neuron_layer->output_type)
				{
					Erro ("The robot_complex_cell must be applied on neuron layers with the same output_type.", "", "");
					return;
				}
			}
		}

		nl = (NEURON_LAYER**)malloc(sizeof(NEURON_LAYER*)*numNL);
		for (i = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, i++)
			nl[i] = n_list->neuron_layer;

		filter_desc->private_state = (void*)nl;
	}
	else
	{
		nl = (NEURON_LAYER**)filter_desc->private_state;
	}

	num_neurons = get_num_neurons (filter_desc->output->dimentions);

	for (i = 0; i < num_neurons; i++)
	{
		dif_accumulator = 0.0;
		for (j = 0; j < (numNL / 2); j++)
		{
			a = nl[j]->neuron_vector[i].output.fval;
			b = nl[j + (numNL / 2)]->neuron_vector[i].output.fval;
			dif_accumulator += (a*a + b*b);
		}
		filter_desc->output->neuron_vector[i].output.fval = dif_accumulator;
	}
}
void 
Cr_filter(FILTER_DESC *filter_desc)
{
	// http://www.equasys.de/colorconversion.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	double r, g, b;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = (double) RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = (double) GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = (double) BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			nl_output->neuron_vector[xo + yo * wo].output.ival = (int) (0.500 * r - 0.419 * g - 0.081 * b + 128.0);
		}
	}
}
void calculate_error_function_from_trained_output_filter(FILTER_DESC *filter_desc) {
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    int wi, hi, xo, yo, wo, ho;

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 1) {
        Erro("Error: Wrong number of parameters. The calculate_error_function_from_trained_output_filter must have no parameters.", "", "");
        return;
    }

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    // Input Layer Dimensions
    wi = nl_input->dimentions.x;
    hi = nl_input->dimentions.y;

    // Output Layer Dimensions
    wo = nl_output->dimentions.x;
    ho = nl_output->dimentions.y;

    // Layer size verification
    if (wo != wi || ho != hi) {
        Erro("Error: calculate_error_function_from_trained_output_filter input and output layers must have te Same Size.", "", "");
        return;
    }

    // Checks whether the neuron layer has been trained
    if (!gaussian_filtered_training_pattern) {
        return;
    }

    for (yo = 0; yo < ho; yo++) {
        for (xo = 0; xo < wo; xo++) {
            // Error = Reference - Output

            // Simple Difference calculate (other error functions could be also applied)
            nl_output->neuron_vector[xo + yo * wo].output.fval = gaussian_filtered_training_pattern[xo + yo * wo] - nl_input->neuron_vector[xo + yo * wo].output.fval;
            //nl_output->neuron_vector[xo + yo * wo].output = nl_input->neuron_vector[xi + yi * wi].output;
        }
    }
}
void make_input_image_class_cnae (INPUT_DESC *input, int w, int h)
{
	char message[256];

	input->tfw = nearest_power_of_2 (w);
	input->tfh = nearest_power_of_2 (h);

	input->ww = w;
	input->wh = h;

	switch(TYPE_SHOW)
	{
		case SHOW_FRAME:
			input->vpw = input->neuron_layer->dimentions.x;
			input->vph = input->neuron_layer->dimentions.y;
			break;
		case SHOW_WINDOW:
			input->vph = h;
			input->vpw = w;
			break;
		default:
			sprintf(message,"%d. It can be SHOW_FRAME or SHOW_WINDOW.",TYPE_SHOW);
			Erro ("Invalid Type Show ", message, " Error in update_input_image.");
			return;
	}
	
	input->vpxo = 0;
	input->vpyo = h - input->vph;

	if(input->image == NULL)
		input->image = (GLubyte *) alloc_mem (input->tfw * input->tfh * 3 * sizeof (GLubyte));
}
Beispiel #9
0
void ordena(linha_t **lin, unsigned int num){

  if(!num)
    Erro("Nao existe campo 0");

  *lin = ordena_linha(lin, NULL, num);
}
//---------------------------------------------------------------------------
bool __fastcall TRawPrint::ValidaComando(AnsiString Comando)
{
 bool Retorno;
 AnsiString Parametro;
 int Indice = 1;
 int Valor;
 try
  {
   for(int i = 0; i < Comando.Length() / 3; i++)//Percorre o Comando
   {
    Parametro = Comando.SubString(Indice, 3);

    if(Indice < 4)
     Indice = Indice + 3 + i;
    else
     Indice = Indice + 3;//Índice de Início do Último Parâmetro (7)

    Valor = StrToIntDef(Parametro, -1); //Verifica se é Inteiro

    if(Valor >= 0 && Valor < 256) //Verifica se o Valor do Parâmetro está de acordo com Manual da Epson
     {
      Retorno = true;
     }
    else
     {
      Retorno = false;
     }
   }
  }
 catch(Exception & E)
  {
   Erro("Erro ao validar Comando informado no Texto.\r\n\r\n" + E.Message + "\r\n");
  }
 return Retorno;
};
void blue_mask_filter (FILTER_DESC *filter_desc)
{
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xi, yi, wi, hi, wo, ho;
	//int color_channel;
	//unsigned int (*mask_func)(unsigned int);

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if(wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yi = 0; yi < hi; yi++)
		for(xi = 0; xi < wi; xi++)
			nl_output->neuron_vector[xi + yi * wi].output.ival =  BLUE(nl_input->neuron_vector[xi + yi * wi].output.ival);
}
void scale_nl_filter(FILTER_DESC *filter_desc) {
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    float scale_factor, k;
    int xi, yi, wi, hi, xo, yo, wo, ho;
    //int delta_xo,delta_yo,corrected_xo,corrected_yo;	//Center offset for image scale

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 4) {
        Erro("Error: Wrong number of parameters. The scale_nl_filter must have only three parameter <scale_factor> <delta_xo> <delta_yo>.", "", "");
        return;
    }

    // Gets the Filter Parameters
    scale_factor = filter_desc->filter_params->next->param.fval;
    //delta_xo = filter_desc->filter_params->next->next->param.ival;
    //delta_yo = filter_desc->filter_params->next->next->next->param.ival;

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    wi = nl_input->dimentions.x;
    hi = nl_input->dimentions.y;

    wo = nl_output->dimentions.x;
    ho = nl_output->dimentions.y;

    // Calculates the scaling constant
    k = 1.0 / scale_factor;

    //#ifdef	_OPENMP
    //	#pragma omp parallel for private(yo,yi,xo,xi)
    //#endif
    for (yo = 0; yo < ho; yo++) {
        yi = (int) (k * (float) yo + .5f); //+ (int)(scale_factor*delta_yo);

        for (xo = 0; xo < wo; xo++) {
            xi = (int) (k * (float) xo + .5f); //+ (int)(scale_factor*delta_xo);

            if ((xi >= 0) && (xi < wi) && (yi >= 0) && (yi < hi))
                nl_output->neuron_vector[xo + yo * wo].output = nl_input->neuron_vector[xi + yi * wi].output;
            else
                nl_output->neuron_vector[xo + yo * wo].output.ival = 0;
        }
    }
}
void rotate_nl_filter(FILTER_DESC *filter_desc) {
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    float angle, cos_angle, sin_angle;
    int xi, yi, wi, hi, xo, yo, wo, ho;

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 2) {
        Erro("Error: Wrong number of parameters. The rotate_nl_filter must have only one parameter <angle>.", "", "");
        return;
    }

    // Gets the Filter Parameters
    angle = filter_desc->filter_params->next->param.fval;

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    wi = nl_input->dimentions.x;
    hi = nl_input->dimentions.y;

    wo = nl_output->dimentions.x;
    ho = nl_output->dimentions.y;

    angle *= pi / 180.0f;
    cos_angle = cos(angle);
    sin_angle = sin(angle);

    //#ifdef	_OPENMP
    //	#pragma omp parallel for private(yo,yi,xo,xi)
    //#endif
    for (yo = 0; yo < ho; yo++) {
        for (xo = 0; xo < wo; xo++) {
            xi = (int) (cos_angle * (float) xo + sin_angle * (float) yo + .5f);
            yi = (int) (-sin_angle * (float) xo + cos_angle * (float) yo + .5f);

            if ((xi >= 0) && (xi < wi) && (yi >= 0) && (yi < hi))
                nl_output->neuron_vector[xo + yo * wo].output = nl_input->neuron_vector[xi + yi * wi].output;
            else
                nl_output->neuron_vector[xo + yo * wo].output.ival = 0;
        }
    }
}
Beispiel #14
0
void ListaProcedimentos::AdicionaProcedimento(Procedimento * P) {
	

	std::pair<std::string, Procedimento *> new_proc(P->obtemNome(), P);
	bool OK = false;
	
	OK = this->procedimentos_do_prog->insert(new_proc).second;
	if (OK) return;
	else throw Erro("\nProcedimento declarado duas vezes"+P->obtemNome());
		
}
void translate_nl_filter(FILTER_DESC *filter_desc) {
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    float x_offset, y_offset;
    int xi, yi, wi, hi, xo, yo, wo, ho;

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 3) {
        Erro("Error: Wrong number of parameters. The rotate_nl_filter must have two parameters <x_offset> <y_offset>.", "", "");
        return;
    }

    // Gets the Filter Parameters - The Pointers And The Values - Void pointers must be casted
    x_offset = *((float*) (filter_desc->filter_params->next->param.pval));
    y_offset = *((float*) (filter_desc->filter_params->next->next->param.pval));

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    wi = nl_input->dimentions.x;
    hi = nl_input->dimentions.y;

    wo = nl_output->dimentions.x;
    ho = nl_output->dimentions.y;

    // Parallel translation filter capabilities where OpenMP available
    //#ifdef	_OPENMP
    //	#pragma omp parallel for private(yo,yi,xo,xi)
    //#endif
    for (yo = 0; yo < ho; yo++) {
        yi = (int) ((float) yo + y_offset + .5f);

        for (xo = 0; xo < wo; xo++) {
            xi = (int) ((float) xo + x_offset + .5f);

            if ((xi >= 0) && (xi < wi) && (yi >= 0) && (yi < hi))
                nl_output->neuron_vector[xo + yo * wo].output = nl_input->neuron_vector[xi + yi * wi].output;
            else
                nl_output->neuron_vector[xo + yo * wo].output.ival = 0;
        }
    }
}
//---------------------------------------------------------------------------
bool __fastcall TRawPrint::DispositivoAberto(void)
{
 const AnsiString cRaw = "RAW";
 _DOC_INFO_1A DocInfo;
 bool Retorno;

 Retorno = OpenPrinter(PChar(NomeDispositivo.c_str()), &hPrinter, NULL);

 try
  {
   if(Retorno)
    {
     DocInfo.pDocName = NomeTrabalho.c_str();
     DocInfo.pOutputFile = PChar(char(0));
     DocInfo.pDatatype = PChar(char(0));
     if (StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo) == 0)
      {
       Erro("Erro ao iniciar Documento para Impressora");
       ClosePrinter(hPrinter);
       Retorno = false;
      }
     else
      {
       DispAberto = True;
       NovaPagina();
       Retorno = true;
      }
    }
   else
    {
     Erro("Erro ao abrir a Impressora: " + NomeDispositivo);
     Retorno = false;
    }
  }
 catch(Exception & E)
  {
   Erro("Erro ao abrir a Impressora: " + NomeDispositivo + ".\r\n\r\n" + E.Message + "\r\n");
  }
 return(Retorno);
};
void
scale_and_translate_filter(FILTER_DESC *filter_desc)
{
	NEURON_LAYER_LIST *n_list = NULL;
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER *nl_input = NULL;
	int i, ho, wo, hi, wi, xo, yo, xi, yi;
	float scale_factor_x, scale_factor_y;

	// Checks Neuron Layers
	for (i = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, i++)
		;

	if (i != 1)
	{
		Erro ("Wrong number of neuron layers. Scale filter must be applied on only one neuron layer.", "", "");
		return;
	}

	// Gets the Inputs Neuron Layers
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Check Parameters
	for (i = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, i++)
		;

	// Gets the Input Neuron Layer Dimentions
	wi  = nl_input->dimentions.x;
	hi  = nl_input->dimentions.y;

	// Gets the Output Neuron Layer Dimentions
	wo  = filter_desc->output->dimentions.x;
	ho  = filter_desc->output->dimentions.y;

	scale_factor_x = (float) wi / (float) wo;
	scale_factor_y = (float) hi / (float) ho;

	for (xo = 0; xo < wo; xo++)
	{
		xi = scale_factor_x * xo + g_translate_x;

		for (yo = 0; yo < ho; yo++)
		{
			yi = scale_factor_y * yo + g_translate_y;

			if ((xi >= 0) && (xi < wi) && (yi >= 0) && (yi < hi))
				filter_desc->output->neuron_vector[(yo * wo) + xo].output = nl_input->neuron_vector[(yi * wi) + xi].output;
			else
				filter_desc->output->neuron_vector[(yo * wo) + xo].output.ival = 0;
		}
	}
}
void 
make_input_image_character(INPUT_DESC *input)
{
	int i;
	char message[256];
	int w, h;
	
	w = input->neuron_layer->dimentions.x;
	h = input->neuron_layer->dimentions.y;
	
	// Computes the input image dimentions
	input->tfw = nearest_power_of_2(w);
	input->tfh = nearest_power_of_2(h);

	// Saves the image dimentions
	input->ww = w;
	input->wh = h;
	
	// Computes the input image dimentions
	input->tfw = nearest_power_of_2(w);
	input->tfh = nearest_power_of_2(h);

	switch (TYPE_SHOW)
	{
		case SHOW_FRAME:
			input->vpw = input->neuron_layer->dimentions.x;
			input->vph = input->neuron_layer->dimentions.y;
			break;
		case SHOW_WINDOW:
			input->vpw = input->ww;
			input->vph = input->wh;
			break;
		default:
			sprintf(message,"%d. It can be SHOW_FRAME or SHOW_WINDOW.",TYPE_SHOW);
			Erro("Invalid Type Show ", message, " Error in update_input_image.");
			return;
	}
	
	input->vpxo = 0;
	input->vpyo = w - input->vph;
			
	if (input->image == (GLubyte *) NULL)
	{
		input->image = (GLubyte *) alloc_mem (3 * input->tfw * input->tfh * sizeof(GLubyte));

		for (i = 0; i < input->tfh * input->tfw * 3; i++)
			input->image[i] = 0;
	}		

	return;
}
Beispiel #19
0
/*
 *********************************************************************************
 * Function: translate_nl_filter	     	 				 *
 * Description: 			                        		 *
 * Inputs: 				                  			 *
 * Output: 				                			 *
 *********************************************************************************
 */
void gaussian_nl_filter(FILTER_DESC *filter_desc) {
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    //float x_offset, y_offset;
    //int xi, yi, wi, hi, xo, yo;
    int wi, hi;
    int i;
  //  float* input_image_r = NULL, *input_image_g = NULL, *input_image_b = NULL;
    float *output_image_r = NULL, *output_image_g = NULL, *output_image_b = NULL;
 //   int kernel_size; double sigma;

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 3) {
        Erro("Error: Wrong number of parameters. The rotate_nl_filter must have two parameters <x_offset> <y_offset>.", "", "");
        return;
    }

    // Gets the Filter Parameters - The Pointers And The Values - Void pointers must be casted
   // kernel_size = filter_desc->filter_params->next->param.ival;
   // sigma = filter_desc->filter_params->next->next->param.fval;

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    wi = nl_input->dimentions.x;
    hi = nl_input->dimentions.y;

    //wo = nl_output->dimentions.x;
    //ho = nl_output->dimentions.y;


//    	input_image_b[i]  = (float)(BLUE(nl_input->neuron_vector[i].output.ival) / 255.0);
//    	input_image_g[i]  = (float)(GREEN(nl_input->neuron_vector[i].output.ival) / 255.0);
//    	input_image_r[i]  = (float)(RED(nl_input->neuron_vector[i].output.ival) / 255.0);

    for(i = 0; i < wi * hi; i++)
    	nl_output->neuron_vector[i].output.ival = PIXEL((long int)(255 * output_image_r[i]), (long int)(255 * output_image_g[i]), (long int)(255 * output_image_b[i]));

}
//---------------------------------------------------------------------------
bool __fastcall TRawPrint::NovaPagina(void)
{
 bool Resultado = true;
 try
  {
   if (DispAberto)
    {
     if (PaginaAberta)
      if (!EndPagePrinter(hPrinter))
       Erro("Erro ao finalizar a Página");

     if (!StartPagePrinter(hPrinter))
      Resultado = false;
     else
      PaginaAberta = true;
    }
  }
 catch(Exception & E)
  {
   Erro("Erro ao gerar nova Página.\r\n\r\n" + E.Message + "\r\n");
  }
  return(Resultado);
};
//---------------------------------------------------------------------------
bool __fastcall TRawPrint::ImprimirLinha(AnsiString Linha)
{
 DWORD WrittenChars;
 bool Retorno = true;
 try
  {
   if (DispAberto)
    if (!WritePrinter(hPrinter, Linha.c_str(), Linha.Length(), &WrittenChars))
     Retorno = false;
  }
 catch(Exception & E)
  {
   Erro("Erro ao Imprimir Linha.\r\n\r\n" + E.Message + "\r\n");
  }
  return(Retorno);
};
void 
init_character_input(INPUT_DESC *input)
{
#ifndef	NO_INTERFACE
	int x, y;
#endif

	float f;
	char file_name[256];

	strcpy(file_name, input->name);
	strcat(file_name, ".in");

	if ((g_input_file = fopen(file_name, "r")) == NULL)
		Erro("cannot open input file: ", file_name, "");
	set_train_data_set(&character);

	make_input_image_character(input);

	f = 1.0;

	while ((((float)input->ww * f) < 128.0) || (((float)input->wh * f) < 128.0))
		f += 1.0;

	while ((((float)input->ww * f) > 1024.0) || (((float)input->wh * f) > 1024.0))
		f *= 0.9;

#ifndef	NO_INTERFACE
	glutInitWindowSize((int)((float)input->ww * f),(int)((float)input->wh * f));

	if (read_window_position(input->name, &x, &y))
		glutInitWindowPosition(x, y);
	else
		glutInitWindowPosition(-1, -1);

	input->win = glutCreateWindow(input->name);
	glGenTextures(1,(GLuint *)(& (input->tex)));
	input_init(input);
	glutReshapeFunc(input_reshape);
	glutDisplayFunc(input_display);
	glutMouseFunc(input_mouse);
	glutPassiveMotionFunc(input_passive_motion);
	glutKeyboardFunc(keyboard);
#endif

}
void hamming_distance_inhibition_filter(FILTER_DESC *filter_desc)
{
    PARAM_LIST *p_list = NULL;
    NEURON_LAYER_LIST *n_list = NULL;
    NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
    int nl_number, p_number;
    int xo, yo, wo, ho;

    //float avg_distance;

    // Checks the Neuron Layers Number
    for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
        ;

    // Checks the Parameters Number
    for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
        ;

    if (p_number != 1) {
        Erro("Error: Wrong number of parameters. The hamming_distance_filter must have no parameters", "", "");
        return;
    }

    // Gets the Filter Output
    nl_output = filter_desc->output;

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Input Neuron Layer
    nl_input = filter_desc->neuron_layer_list->neuron_layer;

    // Gets the Filter Output
    nl_output = filter_desc->output;

    wo = nl_output->dimentions.x;
    ho = nl_output->dimentions.y;

    // Copies the hamming distance into the output layer
    for (yo = 0; yo < ho; yo++)
        for (xo = 0; xo < wo; xo++)
            nl_output->neuron_vector[xo + yo * wo].output.fval = nl_input->neuron_vector[xo + yo * wo].output.fval * angular_similarity(sqrt(hamming_squared_cosine_int(nl_input->neuron_vector[xo + yo * wo].last_hamming_distance,INPUTS_PER_NEURON)));
}
Beispiel #24
0
short compara(char *um, char *dois){
  unsigned int lenght;

  if(um == NULL || dois == NULL)
    Erro("Null string ordenando");

  lenght = min(strlen(um), strlen(dois));

  do{
    if(*um == *dois){
      um++;
      dois++;
    }
    if(tolower(*um) < tolower(*dois))
      return 1;
    if(tolower(*dois) < tolower(*um))
      return 2;
  }while(--lenght);

  return strlen(um) < strlen(dois) ? 1 : 2;
}
Beispiel #25
0
void refresh(char *name, char *alvo){
  char *buf, *ptr, *ptr2, *tmp;
  FILE *target;

  if(name == NULL)
    return;

  if(alvo == NULL)
    target = stdout;
  else
    target = Fopen(alvo, "w");

  ptr = buf = pega(name);

  while(1){
    if(*ptr == '<'){
      if(++ptr == '\0')
        break;
      else
      if(ptr == strstr(ptr, "hts")){

        ptr2 = ptr + strlen("hts");
        ptr = tags(ptr2);
        if(ptr++ == NULL)
          Erro(">");

        tmp = Malloc(ptr - ptr2);
        strncpy(tmp, ptr2, ptr - ptr2 - 1);
        processa(tmp, target);
      }
      else fputc('<', target);
    }
    if(*ptr == '\0') break;
    fputc(*(ptr++), target);
  }

  if(target != stdout)
    fclose(target);
  free(buf);
}
void
read_data_set_order(int *order, int size, const char *file_name)
{
	int i = 0;
	FILE *file;

	if ((file = fopen(file_name, "r")) ==  NULL)
	{
		while(i < size)
		{
			order[i] = i;
			i++;
		}
	}
	else
	{
		while(!feof(file))
		{
			if (fscanf(file, "%d\n", &order[i]) < 0)
				Erro((char *)"Error reading order from file", (char *)file_name, (char *)"");
			i++;
		}
	}
}
Beispiel #27
0
void empilha(double x)
{
     if (topo < TAMPIL) pilha[topo++] = x;
     else Erro("Pilha cheia");
}
Beispiel #28
0
double desempilha()
{
     if (topo > 0) return pilha[--topo];
     else Erro ("Pilha vazia");
	 return 1.0;
}
Beispiel #29
0
void robot_reflectance_filter (FILTER_DESC *filter_desc)
{
	NEURON_LAYER_LIST *n_list;
	NEURON_LAYER *nl_image, *nl_illuminance;
	PARAM_LIST *p_list;
	int i, j;
	int w, h;
	int pixel;
	float I, L, R;

	for (i = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, i++);

	if (i != 2) 
	{
		Erro ("Wrong number of neuron layers. The robot_reflectance_filter must be applied on two neuron layers.", "", "");
		return;
	}
	
	if (filter_desc->neuron_layer_list->next->neuron_layer->output_type != GREYSCALE_FLOAT)
	{
		Erro ("The output type of the illuminance neuron layer must be greyscale_float.", "", "");
		return;
	}

	if (filter_desc->output->output_type != GREYSCALE_FLOAT)
	{
		Erro ("The output type of the robot_reflectance_filter output must be greyscale_float.", "", "");
		return;
	}

	for (i = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, i++);
	i--;

	if (i != 0) 
	{
		Erro ("Wrong number of parameters. The robot_reflectance_filter has no parameters.", "", "");
		return;
	}

	nl_image = filter_desc->neuron_layer_list->neuron_layer;
	nl_illuminance = filter_desc->neuron_layer_list->next->neuron_layer;

	w = filter_desc->output->dimentions.x;
	h = filter_desc->output->dimentions.y;

	for (i = 0; i < w; i++)
	{
		for (j = 0; j < h; j++)
		{
			pixel = nl_image->neuron_vector[j * w + i].output.ival;
			I = (float) (RED (pixel) + GREEN (pixel) + BLUE (pixel)) / 3.0;
			L = nl_illuminance->neuron_vector[j * w + i].output.fval;
			if (I == 0.0)
				R = 0.0;
			else if (L == 0.0)
				R = 1.0;
			else
				R = I / L;
			filter_desc->output->neuron_vector[j * w + i].output.fval =  R;
		}
	}
}
void 
hsv_h_filter(FILTER_DESC *filter_desc)
{
	// http://en.wikipedia.org/wiki/HSL_and_HSV
	// http://cs.haifa.ac.il/hagit/courses/ist/Lectures/Demos/ColorApplet2/t_convert.html
	
	PARAM_LIST *p_list = NULL;
	NEURON_LAYER_LIST *n_list = NULL;
	NEURON_LAYER *nl_output = NULL, *nl_input = NULL;
	int nl_number, p_number;
	int xo, yo, wi, hi, wo, ho;
	int r, g, b, max, min;
	double h, delta;

	// Checks the Neuron Layers Number
	for (nl_number = 0, n_list = filter_desc->neuron_layer_list; n_list != NULL; n_list = n_list->next, nl_number++)
            	;

	// Checks the Parameters Number
	for (p_number = 0, p_list = filter_desc->filter_params; p_list != NULL; p_list = p_list->next, p_number++)
            	;

	if (p_number != 1)
	{
		Erro ("Error: Wrong number of parameters. The blue_mask_filter must have no parameters.", "", "");
		return;
	}

	// Gets the Input Neuron Layer
	nl_input = filter_desc->neuron_layer_list->neuron_layer;

	// Gets the Filter Output 
	nl_output = filter_desc->output;
	
	// Input-Output width
	wi = nl_input->dimentions.x;
	hi = nl_input->dimentions.y;

	wo = nl_output->dimentions.x;
	ho = nl_output->dimentions.y;
	
	if (wi != wo || hi != ho)
	{
		Erro ("Error: Input and output layers on blue_channel_mask filter must have the same 2D size.", "", "");
		return;
	}
	
	for (yo = 0; yo < ho; yo++)
	{
		for (xo = 0; xo < wo; xo++)
		{
			r = RED(nl_input->neuron_vector[xo + yo * wo].output.ival);
			g = GREEN(nl_input->neuron_vector[xo + yo * wo].output.ival);
			b = BLUE(nl_input->neuron_vector[xo + yo * wo].output.ival);
			max = max_value(r, g, b);
			min = min_value(r, g, b);
			if ((max != 0) && (max != min))
			{
				delta = (double) max - (double) min;
				
				if (r == max)
					h = (double) (g - b) / delta;		// between yellow & magenta
				else if (g == max)
					h = 2.0 + (double) (b - r) / delta;	// between cyan & yellow
				else
					h = 4.0 + (double) (r - g) / delta;	// between magenta & cyan

				h *= 60.0;					// degrees
				if (h < 0.0)
					h += 360.0;

				nl_output->neuron_vector[xo + yo * wo].output.ival = (int) (255.0 * (h / 360.0) + 0.5);
			}
			else
				nl_output->neuron_vector[xo + yo * wo].output.ival = 0;
		}
	}
}