Example #1
0
void local_max(IMAGE *im, FITPAR par, OBJ_LIST *objects)
{
        int         nobj, is_max, i, j, k, l, nx, ny,
                    *obj_index;
        float       *tmp_flux;
        double      nsig2, nsig2_detect, bg, tmp_max;
        OBJECT      *obj;
        BKG_STRUCT  bkg;

  nx = im->nx;
  ny = im->ny;

  bkg.frac = par.bkg_frac;

  nobj = 0;
  if (!(obj=(OBJECT *)calloc(1,sizeof(OBJECT)))) errmess("calloc(obj)");

/* prepare some background stuff that is not changing to speed things up */
  init_bkg(im, &bkg, par.anrad1, par.anrad2);

/* loop over all pixels */

  nsig2_detect = par.nsig_detect*par.nsig_detect;

  for (i=par.psfhw; i<nx-par.psfhw; i++)
  {
    for (j=par.psfhw; j<ny-par.psfhw; j++)
    {
      tmp_max = im->pix[i+nx*j];

      is_max = 1;

      for (k=-par.maxhw; k<=par.maxhw && is_max; k++)
        for (l=-par.maxhw; l<=par.maxhw && is_max; l++)
          if (im->pix[i+k+nx*(j+l)] > tmp_max)  is_max = 0;

      if (is_max && is_peak(im, i, j, par.peakhw, par.contrast))
      {
        bg = getbkg(im, &bkg, i, j);

        nsig2 = (tmp_max - bg)*(tmp_max - bg)*im->gain/tmp_max;

        if (!(obj = (OBJECT *)realloc(obj, (nobj+1)*sizeof(OBJECT))))
          errmess("realloc(obj)");

        if ((nsig2 >= nsig2_detect) && (bg > 0.0))
        {
          obj[nobj].x = i;
          obj[nobj].y = j;
          obj[nobj].max = tmp_max;
          obj[nobj].bg = bg;
          obj[nobj].flux = silly_phot(im, &obj[nobj], (int)(par.aprad+0.5));
          obj[nobj].norm = obj[nobj].flux;

          nobj++;
        }
      }
/* end of loop over all pixels */
    }
  }

  if (par.verbose)  printf("Found %d good local maxima\n", nobj);

  objects->list = obj;
  objects->nobj = nobj;

  if (!(tmp_flux=(float *)malloc(nobj*sizeof(float))))
    errmess("malloc(tmp_flux)");

  if (!(obj_index = (int *)malloc(nobj*sizeof(int))))
    errmess("malloc(obj_index)");

  for (i=0; i<nobj; i++)  tmp_flux[i] = obj[i].flux;

  quick_sort(tmp_flux, obj_index, nobj);

  objects->index = obj_index;

  free(tmp_flux);

  return;
}
Example #2
0
void main()
{
	UBYTE key1, key2, i, j, pos_x, pos_y, ch_pos;
	UBYTE non_flick = OFF;
	UWORD on_time, off_time;

	char str[MAX_DTMF];
	char str_ms[10];

	/* default dialling time setting */
	on_time = DTMF_ON;
	off_time = DTMF_OFF;

	disable_interrupts();
	
	SPRITES_8x8;   /* sprites are 8x8 */

	init_dial();
	
	init_bkg();
	
	init_key();

	init_cursor();

	disp(TITLE);

	SHOW_BKG;
	SHOW_SPRITES;
	DISPLAY_ON;

	enable_interrupts();
	
	i = j = 0;

	ch_pos = 0;
	
	while(1) {
		wait_vbl_done();
		key1 = joypad();

		if(key1 != key2){
			pos_x = i * KEY_STEP + START_CURSOR_X;
			pos_y = j * KEY_STEP + START_CURSOR_Y;
			move_cursor(pos_x, pos_y);
		}

		if(key2 & J_A){
			if(key1 & J_A){
				/* value set for each sound reg only numeric key pad*/
				if(i <= 3 && j <= 3){
					/* frequncy register set up for DTMF */
					NR13_REG = row[i];
					NR23_REG = col[j];
					NR24_REG = 0x87U;

					/* sound output on */
					NR51_REG = 0x33U;
				}
				
				/* '?' button */
				/* appear the title during press A button */
				if(i == 5 && j == 0 && !non_flick){
					disp(TITLE);
					non_flick = ON;
				}

				/* incremental button */
				/* decremental button */
				/* appear the delay during press A button */
				if(i == 5 && (j == 1 || j == 2) && !non_flick){
					sprintf(str_ms, "%lu MS", on_time);
					disp(str_ms);
					non_flick = ON;
				}
			}
			else{
				/* sound output off */
				NR51_REG = 0x00U;

				break_button(i, j);

				/* '?' button */
				/* incremental button */
				/* decremental button */
				/* return to normal display at release the A button */
				if(i == 5 && (j == 0 || j == 1 || j == 2)){
					non_flick = OFF;
					if(ch_pos == 0)
						clr_disp();
					else
						disp(str);
				}
			}
		}
		else{
			if(key1 & J_A){
				/* button display handle */
				press_button(i, j);

				/* numeric key pad handling */
				if(i <= 3 && j <= 3){
					/* string length check */
					if(ch_pos < MAX_DTMF-1){
						str[ch_pos] = pad[j][i];
						ch_pos++;
						str[ch_pos] = 0x00;
						disp(str);
					}
				}

				/* ',' button */
				if(i == 4 && j == 2){
					/* string length check */
					if(ch_pos < MAX_DTMF-1){
						str[ch_pos] = pad[j][i];
						ch_pos++;
						str[ch_pos] = 0x00;
						disp(str);
					}
				}

				/* all clear button */
				if(i == 4 && j == 0){
					ch_pos = 0x00;
					strcpy(str,"");
					clr_disp();
				}

				/* delete button */
				if(i == 4 && j == 1){
					if(ch_pos > 0){
						ch_pos--;
						str[ch_pos] = 0x00;
						if(ch_pos == 0)
							clr_disp();
						else
							disp(str);
					}
				}

				/* incremental button */
				if(i == 5 && j == 1){
					if(on_time >= DTMF_ON / 2){
						on_time = on_time - 10;
						off_time = off_time - 10;
					}
				}

				/* decremental button */
				if(i == 5 && j == 2){
					if(on_time <= DTMF_ON * 2){
						on_time = on_time + 10;
						off_time = off_time + 10;
					}
				}

				/* dialing button */
				if((i==4 || i==5) && j==3){
					dialtone(on_time, off_time, str);
				}
			}
		}

		if(!(key1 & J_A)){
			if((key1 & J_UP) && !(key2 & J_UP) && j > 0)
				j--;
			else if((key1 & J_DOWN) && !(key2 & J_DOWN) && j < 3)
				j++;

			if((key1 & J_LEFT) && !(key2 & J_LEFT) && i > 0)
				i--;
			else if((key1 & J_RIGHT) && !(key2 & J_RIGHT) && i < 5)
				i++;
		}
		key2 = key1;
	}
}