Beispiel #1
0
void idwt_wp(Image_tree dwts, gray **pixels) {
  Image image;
  int i, j;

  image = inv_transform(dwts, dwt_filters, dwt_method + 1);

  for (i = 0; i < dwt_rows; i++)
    for (j = 0; j < dwt_cols; j++)
      pixels[i][j] = PIXELRANGE((int) (get_pixel(image, j, i) + 0.5));
  printf("idwt_wp(): working!!\n");
  free_image(image);
}
Beispiel #2
0
void embed_image(image source, image dest, int dx, int dy)
{
    int x,y,k;
    for(k = 0; k < source.c; ++k){
        for(y = 0; y < source.h; ++y){
            for(x = 0; x < source.w; ++x){
                float val = get_pixel(source, x,y,k);
                set_pixel(dest, dx+x, dy+y, k, val);
            }
        }
    }
}
Beispiel #3
0
/*!
 * Recursive fill using the boundary-fill algorithm. This function should not be called by the
 * user.
 *
 * \param x The x position of the fill (0 to 319).
 * \param y The y position of the fill (0 to 199).
 * \param color The fill color.
 * \param empty_color The color of the area to be filled.
 */
void boundary_fill( int x, int y, byte color, byte empty_color )
{
    if( x > SCREEN_HEIGHT || x < 0 ) { return; }
    if( y > SCREEN_WIDTH  || y < 0 ) { return; }
    if( get_pixel(x, y) == empty_color ) {
        put_pixel(x, y, color);
        boundary_fill( x + 1, y    , color, empty_color );
        boundary_fill( x    , y - 1, color, empty_color );
        boundary_fill( x - 1, y    , color, empty_color );
        boundary_fill( x    , y + 1, color, empty_color );
    }
}
Beispiel #4
0
void hsv_to_rgb(image im)
{
    assert(im.c == 3);
    int i, j;
    float r, g, b;
    float h, s, v;
    float f, p, q, t;
    for(j = 0; j < im.h; ++j){
        for(i = 0; i < im.w; ++i){
            h = get_pixel(im, i , j, 0);
            s = get_pixel(im, i , j, 1);
            v = get_pixel(im, i , j, 2);
            if (s == 0) {
                r = g = b = v;
            } else {
                int index = floor(h);
                f = h - index;
                p = v*(1-s);
                q = v*(1-s*f);
                t = v*(1-s*(1-f));
                if(index == 0){
                    r = v; g = t; b = p;
                } else if(index == 1){
                    r = q; g = v; b = p;
                } else if(index == 2){
                    r = p; g = v; b = t;
                } else if(index == 3){
                    r = p; g = q; b = v;
                } else if(index == 4){
                    r = t; g = p; b = v;
                } else {
                    r = v; g = p; b = q;
                }
            }
            set_pixel(im, i, j, 0, r);
            set_pixel(im, i, j, 1, g);
            set_pixel(im, i, j, 2, b);
        }
    }
}
// Compute image error metrics.
static void image_compare(image_compare_results &results, int width, int height, const uint8 *pComp_image, int comp_image_comps, const uint8 *pUncomp_image_data, int uncomp_comps, bool luma_only)
{
    double hist[256];
    memset(hist, 0, sizeof(hist));

    const uint first_channel = 0, num_channels = 3;
    for (int y = 0; y < height; y++) {
        for (int x = 0; x < width; x++) {
            int a[3]; get_pixel(a, pComp_image + (y * width + x) * comp_image_comps, luma_only, comp_image_comps);
            int b[3]; get_pixel(b, pUncomp_image_data + (y * width + x) * uncomp_comps, luma_only, uncomp_comps);
            for (uint c = 0; c < num_channels; c++)
                hist[labs(a[first_channel + c] - b[first_channel + c])]++;
        }
    }

    results.max_err = 0;
    double sum = 0.0f, sum2 = 0.0f;
    for (uint i = 0; i < 256; i++) {
        if (!hist[i])
            continue;
        if (i > results.max_err)
            results.max_err = i;
        double x = i * hist[i];
        sum += x;
        sum2 += i * x;
    }

    // See http://bmrc.berkeley.edu/courseware/cs294/fall97/assignment/psnr.html
    double total_values = width * height;

    results.mean = sum / total_values;
    results.mean_squared = sum2 / total_values;

    results.root_mean_squared = sqrt(results.mean_squared);

    if (!results.root_mean_squared)
        results.peak_snr = 1e+10f;
    else
        results.peak_snr = log10(255.0f / results.root_mean_squared) * 20.0f;
}
Beispiel #6
0
void UnaryCompositeLayer<Dtype>::Forward_cpu(const vector<Blob<Dtype>*>& bottom,
                                               const vector<Blob<Dtype>*>& top)
{
    top[0]->CopyFrom(*bottom[0], false);// data is copied
    
    Dtype user_interaction_potential = this->layer_param_.multi_stage_crf_param().user_interaction_potential();
    Dtype dis_mean = this->layer_param_.multi_stage_crf_param().interaction_dis_mean();
    Dtype dis_std  = this->layer_param_.multi_stage_crf_param().interaction_dis_std();
    Dtype dis_cv = dis_mean/dis_std;
    
    const Dtype * bottom_data = bottom[0]->cpu_data();
    const Dtype * image_data = bottom[1]->cpu_data();
    Dtype * top_data = top[0]->mutable_cpu_data();
    Dtype * mask_data = top[1]->mutable_cpu_data();
    int scribble_point = 0;
    for(int n=0; n<num_; n++)
    {
        for(int h=0; h<height_; h++)
        {
            for(int w=0; w<width_; w++)
            {
                int scribble_channel = -1;
                for(int c = 0; c<unary_channels_; c++)
                {
                    int ci = image_channels_-unary_channels_ + c;
                    Dtype d = get_pixel(image_data, num_, image_channels_, height_, width_,
                                        n, ci, h, w);
                    if((d + dis_cv) < 1e-5 && (d + dis_cv) > -1e-5)
                    {
                        scribble_channel = c;
                        scribble_point++;
                        break;
                    }
                }
                
                Dtype mask_value = (scribble_channel>-1)? 1.0 : 0.0;
                set_pixel(mask_data, num_, 1, height_, width_, n, 0, h, w, mask_value);
                if(scribble_channel > -1)
                {
                    for (int c = 0; c<unary_channels_; c++)
                    {
                        Dtype u_value = 0;//get_pixel(bottom_data, num_, unary_channels_, height_, width_,n, c, h, w);
                        u_value = (c == scribble_channel)? u_value + user_interaction_potential :
                                                           u_value - user_interaction_potential;
                        set_pixel(top_data, num_, unary_channels_, height_, width_, n, c, h, w, u_value);
                    }
                }
            } //for w
        } // for h
    } // for n
    LOG(INFO)<<"scribble point: "<<scribble_point;
}
Beispiel #7
0
int styledredraw()
{
    /*
     * this function redraws the canvas using 
     * the plot function, thus applying
     * pixelstyle
     */
    int x;
    int y;
    int xr;
    int yr;

    struct Color tempcolor;

    //store buffer in temp mem  
    memcpy(dummy_buf, tmp_buf, screensize); 
  
    tempcolor.r = currentcolor->r;
    tempcolor.g = currentcolor->g;
    tempcolor.b = currentcolor->b;
    tempcolor.a = currentcolor->a;
  
    //redraw buffer form temp mem
    //first clear it

    clearbuffer(tmp_buf);

    for (x=0; x<width;x++){
        for (y=0;y<height;y++){
            get_pixel(x, y, currentcolor, dummy_buf); 
            currentcolor->a = tempcolor.a; 
            xr = x;
            yr = y;  
            if ((currentcolor->r!=0) || (currentcolor->g!=0) || (currentcolor->b!=0)){
            //aint gonna tranform nonvisible pixels pixels. cmon.
                transform(&xr, &yr);
                if ((xr>0) && (xr<width)){
                    if ((yr>0)&&(yr<height)){
                        pPlot(xr,yr);
                    }
                }
            }
        }
    } 
    
    currentcolor->a = tempcolor.a;
    currentcolor->r = tempcolor.r;
    currentcolor->g = tempcolor.g;
    currentcolor->b = tempcolor.b;
    
    return 0;
}
Beispiel #8
0
int Sprite::getPixel(int x, int y, FrameNumber frame) const
{
  int color = 0;

  if ((x >= 0) && (y >= 0) && (x < m_width) && (y < m_height)) {
    base::UniquePtr<Image> image(Image::create(m_format, 1, 1));
    clear_image(image, (m_format == IMAGE_INDEXED ? getTransparentColor(): 0));
    render(image, -x, -y, frame);
    color = get_pixel(image, 0, 0);
  }

  return color;
}
Beispiel #9
0
/**
 * @brief Write normalised pixel values to an 8 bit greyscale image.
 *
 * Normalises image first, which replaces all pixel values. Call this function
 * after any other processing has been completed.
 */
void Image::ouput_to_file(std::string file_name) {
    normalise();
    boost::gil::gray8_image_t img(rows+1, cols+1);
    boost::gil::gray8_view_t view = boost::gil::view(img);

    for (int i = 1; i < rows+1; ++i) {
        for (int j = 1; j < cols+1; ++j) {
            view(i, j) = boost::gil::gray8_pixel_t((uint8_t)(
                                                get_pixel(i, j)*254));
        }
    }
    boost::gil::png_write_view(file_name, view);
}
Beispiel #10
0
void idwt(Image_tree dwts, gray *pixels) {
  Image image;
  int i, j;

  image = inv_transform(dwts, dwt_filters, dwt_method + 1);
  for (i = 0; i < dwt_rows; i++)
    for (j = 0; j < dwt_cols; j++)
    //  pixels[i][j] = PIXELRANGE((int) (get_pixel(image, j, i) + 0.5));
		pixels[j + (i*(image->width))] = PIXELRANGE((int) (get_pixel(image, j, i) + 0.5));
 // for (i = 0; i < (dwt_cols*dwt_rows); i++) pixels[i] = PIXELRANGE((int)(image->data[i] + 0.5));
 
  free_image(image);
  free_image_tree(dwts);
}
Beispiel #11
0
bool lose_line(){
  int white=0;
  for(int num=0;num<320;num++){
    int value=get_pixel(num, 160, 3);
    if(value>110){
      white+=1;
      if(white>=10){
        return false;
      }
    }else{
      white=0;
    }
  }return true;
}
Beispiel #12
0
static void draw_tile(GContext* ctx, size_t x, size_t y, bool fg) {
  for (size_t j = 0; j < TILE_SIZE; j++) {
    for (size_t i = 0; i < TILE_SIZE; i++) {
      if (get_pixel(i, j, fg)) {
        graphics_context_set_stroke_color(ctx, backColor);
      } else {
        graphics_context_set_stroke_color(ctx, foreColor);
      }

      graphics_draw_pixel(ctx, GPoint(
        ORIGIN_X + x*TILE_SIZE + i,
        ORIGIN_Y + y*TILE_SIZE + j));
    }
  }
};
Beispiel #13
0
image grayscale_image(image im)
{
    assert(im.c == 3);
    int i, j, k;
    image gray = make_image(im.w, im.h, 1);
    float scale[] = {0.587, 0.299, 0.114};
    for(k = 0; k < im.c; ++k){
        for(j = 0; j < im.h; ++j){
            for(i = 0; i < im.w; ++i){
                gray.data[i+im.w*j] += scale[k]*get_pixel(im, i, j, k);
            }
        }
    }
    return gray;
}
Beispiel #14
0
void write_image(int* pixels, int* sizes, int w, int h)
{
    int x, y;
    FILE* out = fopen("image.ppm", "w");
    fprintf(out, "P3 %d %d 255\n", w, h);
    for (y = 0; y < h; y++)
    {
        for (x = 0; x < w; x++)
        {
            int c = get_pixel(pixels, sizes, w, h, x, y);
            fprintf(out, "%d\t%d\t%d\t\t", c, c, c);
        }
        fprintf(out, "\n");
    }
}
Beispiel #15
0
void draw_sprite(Sprite* sprt, char *base)
{
	char* dSprt = sprt->map;
	char* bgMap = sprt->bgmap;
	sprt->on_screen = true;
	
	int i,k;
	for(i=0; i < sprt->height; i++)
		for(k=0; k < sprt->width; k++)
		{
			if(bgMap) *(bgMap + sprt->width*i + k) = get_pixel(sprt->x+k, sprt->y+i, base); //guarda o valor antigo
			if(*dSprt != 0) set_pixel(sprt->x+k,sprt->y+i, *dSprt, base);  //actualiza com o valor actual
			dSprt++;
		}
}
Beispiel #16
0
int getLineValue() {
    char c;
    //the first array getting the camera input
    int whiteness[320];
    //whether the number is white enough
    int white_thr = 127;
    // the second array to compare to (- on left, + on the right)
    int white_compare[320];
    // what should be the multiplied version of the two above arrays
    int white_final[320];
    //the sum of all the white final numbers added 
    int sum = 0;
    // a count of how many white spots have been counted( to check if we can still see the line)
    int n_whites = 0;
    // left motor vroom vroom
    int leftMotor = 0;
    // right motor also vroom vroom
    int rightMotor = 0;
    float kp = 0.005;
    double proportional_signal =0;
    take_picture();
    for (int i = 0; i < 320; i++) {
        //Take picture with camera
        
        //get pixel "whiteness" from centre of image
        c = get_pixel(i, 120, 3);
        //printf("%d\n", c);
        if (c > white_thr) {
            // if its greater than the threshold, the number is a one, and therefore white, so count increases
            whiteness[i] = 1;
            n_whites++;
        }
        else {
            whiteness[i] = 0;
        }
        white_compare[i] = i - 160;
        white_final[i] = whiteness[i] * white_compare[i];
    }

    // what should be the sum of white final working
    for (int i = 0; i < 320; i++) {
        sum = sum + white_final[i];
    }
    proportional_signal = sum*kp
    printf("%d\n", sum);
    return proportional_signal;

}
Beispiel #17
0
static IplImage* do_bin(IplImage* im, int s)
{
  /* image pixel binning */
  /* s the scaling factor */

  const int ss = s * s;

  IplImage* bin_im = NULL;
  CvSize bin_size;
  int x;
  int y;
  int i;
  int j;
  unsigned int sum[3];
  unsigned char rgb[3];

  bin_size.width = im->width / s - ((im->width % s) ? 1 : 0);
  bin_size.height = im->height / s - ((im->height % s) ? 1 : 0);
  bin_im = cvCreateImage(bin_size, IPL_DEPTH_8U, 3);

  for (y = 0; y < bin_size.height; ++y)
  {
    for (x = 0; x < bin_size.width; ++x)
    {
      sum[0] = 0;
      sum[1] = 0;
      sum[2] = 0;

      for (i = 0; i < s; ++i)
	for (j = 0; j < s; ++j)
	{
	  get_pixel(im, x * s, y * s, rgb);

	  sum[0] += rgb[0];
	  sum[1] += rgb[1];
	  sum[2] += rgb[2];
	}

      rgb[0] = sum[0] / ss;
      rgb[1] = sum[1] / ss;
      rgb[2] = sum[2] / ss;

      set_pixel(bin_im, x, y, rgb);
    }
  }

  return bin_im;
}
Beispiel #18
0
int cam_error(){
  //Initialises variables for finding colour of pixel, the running total, and the number of white pixels for averaging
  long total = 0;
  int white = 0;
  int pixel;
  //Takes picture to analyse
  take_picture();
  for(int y=115;y<125;y++){
    for(int x=0;x<320;x++){
      //Read pixel
      pixel = get_pixel(x,y,3);
      //If pixel is white, add to total
      if(pixel>128){
        total = total + (x-160);
        white++;
        };
      };
    };
  //Find average if white pixels were present
  if(white>0){
    total=total/white;
    };
  //Print total
  printf("%s", "Base error value: ");
  printf("%d\n",total);
  
  //Perform PID
  int pid_sum; //Declares sum error variable
  int int_error; //Declares integral error variable
  int prop_error = total*kp; //Find proportional error
  int der_error = ((prop_error-prev_error)/0.2)*kd; //Find derivative error (assume camera check is every 2 seconds)
  prev_error = prop_error; //Update previous error for next iteration
  total_error = total_error + prop_error; //Update total error for integration
  int_error = total_error*ki; //Find integration error
  pid_sum = prop_error+der_error+int_error; //Find sum error
  printf("%s", "Sum error value: ");
  printf("%d\n",pid_sum);
  printf("%s", "Potential error value: ");
  printf("%d\n",prop_error);
  printf("%s", "Derivative error value: ");
  printf("%d\n",der_error);
  printf("%s", "Integration error value: ");
  printf("%d\n",int_error);
  printf("%s", "Previous error value: ");
  printf("%d\n",prev_error);
  printf("%s", "Total error value: ");
  printf("%d\n\n",total_error);
return pid_sum;}
int main(){
    //This sets up the RPi hardware and ensures
    //everything is working correctly
    init(1);
    char c;
    while(true){
       //Take picture with camera
       take_picture();
       //get pixel "whiteness" from centre of image (160x120)
       c = get_pixel(160,120,3);
       //Prints read pixel value 
       printf("%d\n",c); 
       //Waits for 0.5 seconds (500000 microseconds)
       Sleep(0,500000);
       } 
return 0;}
Beispiel #20
0
/* Paste part of one image into another, with all necessary clipping.
   Alpha controls the blending of the new image into the old image
    (and any alpha already in the new image is also taken into account.)
  If override_fg/bg is an RGB value (0xNNNNNN) then any dark/light values
    in the source image are assumed to be that, and only the source image's
    intensity and alpha are used.  (Note that 0 is a color: black.  To not
    specify override_color at all, pass in -1 (or ~0, which is the same
    thing.)
 */
void
paste_ppm (struct ppm *into, int to_x, int to_y,
           struct ppm *from, int from_x, int from_y, int w, int h,
           unsigned char fg, unsigned char bg)
{
  int i, j;

  for (j = 0; j < h; j++)
    for (i = 0; i < w; i++)
      {
        unsigned char pixel;

        get_pixel (from, from_x + i, from_y + j, &pixel);
        put_pixel (into,   to_x + i,   to_y + j,  (pixel != 0) ? fg : bg);
      }
}
Beispiel #21
0
bmp_t* convert_24bpp(bmp_t *bmp){
	bmp_t *converted = create_bmp(bmp->info.w, bmp->info.h, 24);
	if (!converted){
		fprintf(stderr, "convert_24bpp error: Failed to allocate room for conversion\n");
		return NULL;
	}
	int w = bmp->info.w, h = bmp->info.h;
	for (int i = 0; i < h; ++i){
		for (int j = 0; j < w; ++j){
			uint8_t color[3];
			get_pixel(bmp, j, i, &color[0], &color[1], &color[2]);
			set_pixel(converted, j, i, color[0], color[1], color[2]);
		}
	}
	return converted;
}
static inline void 
moverender_rider(struct state *st, Drawable drawable, 
                 GC fgc, struct field *f, PxRider *rid, 
                 float x, float y, float r) 
{
    float px, py;
    unsigned long int c;
    double cv;

    /* add velocity to theta */
    rid->t = fmod((rid->t + rid->vt + M_PI), (2 * M_PI)) - M_PI;
    
    rid->vt += frand(0.002) - 0.001;

    /* apply friction brakes */
    if (abs(rid->vt) > 0.02)
        rid->vt *= 0.9;

    /* draw */
    px = x + r * cos(rid->t);
    py = y + r * sin(rid->t);

    if ((px < 0) || (px >= f->width) || (py < 0) || (py >= f->height))
        return;

    /* max brightness seems to be 0.003845 */

    c = ref_pixel(f, (int) px, (int) py);
    cv = c / 255.0;

    /* guestimated - 40 is 18% of 255, so scale this to 0.0 to 0.003845 */
    if (cv > 0.0006921) {
        draw_glowpoint(st, drawable, fgc, f, px, py); 

        rid->mycharge = 0.003845;
    } else {
        rid->mycharge *= 0.98;

        c = 255 * rid->mycharge;

        trans_point(st, px, py, c, 0.5, f);

        XSetForeground(st->dpy, fgc, get_pixel(st, c));
        XDrawPoint(st->dpy, drawable, fgc, px, py);
        XSetForeground(st->dpy, fgc, f->fgcolor);
    }
}
Beispiel #23
0
t_bunny_response	on_palette_event_click(t_bunny_event_state state,
					       t_bunny_mousebutton key,
					       void *datas)
{
  t_tekpaint		*tekpaint;
  t_palette		*palette;
  unsigned int		color;

  tekpaint = (t_tekpaint*) datas;
  palette = &tekpaint->tool.palette;
  tekpaint->tool.current_tool = 0;
  color = get_pixel(palette->buffer,
    bunny_get_mouse_position()->x,
    bunny_get_mouse_position()->y);
  tekpaint->tool.color = color;
  return (EXIT_ON_CROSS);
}
Beispiel #24
0
image grayscale_image(image im)
{
    assert(im.c == 3);
    int i, j, k;
    image gray = make_image(im.w, im.h, im.c);
    float scale[] = {0.587, 0.299, 0.114};
    for(k = 0; k < im.c; ++k){
        for(j = 0; j < im.h; ++j){
            for(i = 0; i < im.w; ++i){
                gray.data[i+im.w*j] += scale[k]*get_pixel(im, i, j, k);
            }
        }
    }
    memcpy(gray.data + im.w*im.h*1, gray.data, sizeof(float)*im.w*im.h);
    memcpy(gray.data + im.w*im.h*2, gray.data, sizeof(float)*im.w*im.h);
    return gray;
}
Beispiel #25
0
void Sprite::pickCels(int x, int y, frame_t frame, int opacityThreshold, CelList& cels) const
{
  std::vector<Layer*> layers;
  getLayersList(layers);

  for (int i=(int)layers.size()-1; i>=0; --i) {
    Layer* layer = layers[i];
    if (!layer->isImage() || !layer->isVisible())
      continue;

    Cel* cel = layer->cel(frame);
    if (!cel)
      continue;

    Image* image = cel->image();
    if (!image)
      continue;

    if (!cel->bounds().contains(gfx::Point(x, y)))
      continue;

    color_t color = get_pixel(image,
      x - cel->x(),
      y - cel->y());

    bool isOpaque = true;

    switch (image->pixelFormat()) {
      case IMAGE_RGB:
        isOpaque = (rgba_geta(color) >= opacityThreshold);
        break;
      case IMAGE_INDEXED:
        isOpaque = (color != image->maskColor());
        break;
      case IMAGE_GRAYSCALE:
        isOpaque = (graya_geta(color) >= opacityThreshold);
        break;
    }

    if (!isOpaque)
      continue;

    cels.push_back(cel);
  }
  fflush(stdout);
}
Beispiel #26
0
/**
 *	1 -> Passou da linha final
 *	2 -> Colidiu com espermicida
 *
 *
 */
int check_zoid_colision(Sprite *zoid, int x, int y, char* base) {

	if (y > VRES - 90) return 1;
	
	int limitx = x + zoid->width;
	int limity = y + zoid->height;

	for(; x < limitx; x++) {
		for( y /= 2; y < limity; y++)
			if (get_pixel(x, y, base) == SPMCD_COLOR) {
				//score += 500;
				return 2;	
			}
	}
	
	return 0;
}
Beispiel #27
0
/**
 * \brief Returns whether a pixel is transparent.
 *
 * A pixel is transparent if it corresponds to the colorkey
 * or if its alpha channel is equal to 0.
 *
 * \param index The index of the pixel to test.
 * \return \c true if the pixel is transparent.
 */
bool Surface::is_pixel_transparent(int index) const {
  
  uint32_t pixel = get_pixel(index);
  
  if (with_colorkey && pixel == colorkey) {
    // The pixel has the transparency color.
    return true;
  }

  if (internal_surface->format->Amask != 0               // There exists an alpha channel.
      && (pixel & internal_surface->format->Amask) == 0  // The pixel is fully transparent.
      ) {
    return true;
  }
  
  return false;
}
Beispiel #28
0
static void load_program(const char *filename, unsigned int codel)
{
	unsigned char *p;
	int x, y;
	SDL_Surface *image;

	image = IMG_Load(filename);

	if (!image)
		goto bad;

	/* Ensure the program.image is sane. */
	if (image->h == 0 || image->w == 0)
		goto bad;

	if (image->h % codel || image->w % codel)
		goto bad;

	if (image->format->BytesPerPixel != 1 &&
		image->format->BytesPerPixel != 3 &&
		image->format->BytesPerPixel != 4)
		goto bad;

	program.w = image->w / codel;
	program.h = image->h / codel;

	/* Transcribe the program in something more palatable. */
	program.image = malloc(program.w * program.h);
	if (!program.image)
		goto bad;

	p = program.image;
	for(y = 0; y < program.h; y++) {
		for(x = 0; x < program.w; x++) {
			int color = get_pixel(image, x*codel, y*codel);
			*p = convert_to_code(color);
			p ++;
		}
	}

bad:
	if (image) {
		SDL_FreeSurface(image);
	}
}
Beispiel #29
0
/**
 * Antud funktsioon kasutab genereeritud mapi ja tekitab sellest pildi
 * */
void generate_image_from_map(char *fname){
	int x,y;
	int H=pixel_map.H;
	int W=pixel_map.W;



	create_img(W,H);

	for(y=0;y<H;y++){
	     for(x=0;x<W;x++){
		   point p=pixel_map.map[y][x];
		   set_pixel(x,y, get_pixel(p.x, p.y));
	     }
		}
	save_img(fname);
	return;
	}
Beispiel #30
0
void test_local_thresholding(){
	int text_width = 3;
	IplImage* edges_image = cvLoadImage("images/otsu_edges.png",0);
	display_image("edges image",edges_image);
	IplImage* original_image = image;
	//IplImage* local_thresholding(IplImage * compensate_img, IplImage * edges_img,int text_width){
    int window_size = text_width * 2;
    if(window_size%2==0) // to make it odd
        window_size++;
    
    int radius = floor((float)window_size /2);
    
    int Nmin = window_size;
    IplImage * rimage = cvCloneImage(image);
	int height_limit  = image->height-radius;
	int width_limit = image->width-radius;

	for(int j=0; j< image->height ;j++){ //change radius to 130 ie to debug windows size
		for(int i=0 ; i < image->width;i++){
			if(j <radius || i < radius || j>= height_limit ||i >= width_limit){ //This is to make whie the borders, we assume there is no text in the borders
					set_pixel(rimage,j,i,255);
					continue;
			}

            int Ne = get_number_edge_pixels(edges_image,i,j,radius);
            float Emean = get_edges_mean(edges_image,image,i,j,radius);
			float Estd = get_edges_std(edges_image,image,Emean,i,j,radius);
			int pixel = get_pixel(image,j,i);
			if( Ne >= Nmin && pixel <= (Emean+Estd/2)){
				set_pixel(rimage,j,i,0);
			}
			else{
				set_pixel(rimage,j,i,255);
			}
		}
	}
    
    //return rimage;

	display_image("local thresholding",rimage);
	cvSaveImage("images/localt.png",rimage);

	
}