void EdgeMag(int rows, int cols, unsigned char *img, float *edge_mag) { int i,j; float max_mag,min_mag; short int *delta_x, *delta_y; short int *smoothedim; gaussian_smooth(img, rows, cols, &smoothedim); derrivative_x_y(smoothedim, rows, cols, &delta_x, &delta_y); free(smoothedim); magnitude_x_y(delta_x, delta_y, rows, cols, edge_mag); free(delta_x); free(delta_y); max_mag = -99999; min_mag = 99999; for (j=0; j<rows; j++) for (i=0; i<cols; i++) { if (edge_mag[j*cols+i] > max_mag) max_mag = edge_mag[j*cols+i]; if (edge_mag[j*cols+i] < min_mag) min_mag = edge_mag[j*cols+i]; } for (j=0; j<rows; j++) for (i=0; i<cols; i++) edge_mag[j*cols+i] = 255*(edge_mag[j*cols+i]-min_mag)/ (max_mag-min_mag); }
//! Connect Image Processing Actions to Slots Methods //! void ImageView::connectActionToSlots() { connect(ui->actionMid_Filter_2, SIGNAL(triggered()), this, SLOT(median_smoooth())); connect(ui->actionGaussian, SIGNAL(triggered()), this, SLOT(gaussian_smooth())); connect(ui->actionBilateral_Smooth,SIGNAL(triggered()), this, SLOT(bilateral_smooth())); connect(ui->actionGLCM, SIGNAL(triggered()), this, SLOT(gLCM())); connect(ui->actionCanny, SIGNAL(triggered()), this, SLOT(canny())); connect(ui->actionLecel_Set, SIGNAL(triggered()), this, SLOT(levelSetSegmentation())); connect(ui->actionVideo_Camera_Track, SIGNAL(triggered()), this, SLOT(videoCameraTrack())); }
static GstFlowReturn gst_gaussianblur_transform_frame (GstVideoFilter * vfilter, GstVideoFrame * in_frame, GstVideoFrame * out_frame) { GstGaussianBlur *filter = GST_GAUSSIANBLUR (vfilter); GstClockTime timestamp; gint64 stream_time; gfloat sigma; guint8 *src, *dest; /* GstController: update the properties */ timestamp = GST_BUFFER_TIMESTAMP (in_frame->buffer); stream_time = gst_segment_to_stream_time (&GST_BASE_TRANSFORM (filter)->segment, GST_FORMAT_TIME, timestamp); GST_DEBUG_OBJECT (filter, "sync to %" GST_TIME_FORMAT, GST_TIME_ARGS (timestamp)); if (GST_CLOCK_TIME_IS_VALID (stream_time)) gst_object_sync_values (GST_OBJECT (filter), stream_time); GST_OBJECT_LOCK (filter); sigma = filter->sigma; GST_OBJECT_UNLOCK (filter); if (filter->cur_sigma != sigma) { g_free (filter->kernel); filter->kernel = NULL; g_free (filter->kernel_sum); filter->kernel_sum = NULL; filter->cur_sigma = sigma; } if (filter->kernel == NULL && !make_gaussian_kernel (filter, filter->cur_sigma)) { GST_ELEMENT_ERROR (filter, RESOURCE, NO_SPACE_LEFT, ("Out of memory"), ("Failed to allocation gaussian kernel")); return GST_FLOW_ERROR; } /* * Perform gaussian smoothing on the image using the input standard * deviation. */ src = GST_VIDEO_FRAME_COMP_DATA (in_frame, 0); dest = GST_VIDEO_FRAME_COMP_DATA (out_frame, 0); gst_video_frame_copy (out_frame, in_frame); gaussian_smooth (filter, src, dest); return GST_FLOW_OK; }
static GstFlowReturn gauss_blur_process_frame (GstBaseTransform * btrans, GstBuffer * in_buf, GstBuffer * out_buf) { GaussBlur *gb = GAUSS_BLUR (btrans); GstClockTime timestamp; gint64 stream_time; gfloat sigma; /* GstController: update the properties */ timestamp = GST_BUFFER_TIMESTAMP (in_buf); stream_time = gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp); if (GST_CLOCK_TIME_IS_VALID (stream_time)) gst_object_sync_values (G_OBJECT (gb), stream_time); GST_OBJECT_LOCK (gb); sigma = gb->sigma; GST_OBJECT_UNLOCK (gb); if (gb->cur_sigma != sigma) { g_free (gb->kernel); gb->kernel = NULL; g_free (gb->kernel_sum); gb->kernel_sum = NULL; gb->cur_sigma = sigma; } if (gb->kernel == NULL && !make_gaussian_kernel (gb, gb->cur_sigma)) { GST_ELEMENT_ERROR (btrans, RESOURCE, NO_SPACE_LEFT, ("Out of memory"), ("Failed to allocation gaussian kernel")); return GST_FLOW_ERROR; } /* * Perform gaussian smoothing on the image using the input standard * deviation. */ memcpy (GST_BUFFER_DATA (out_buf), GST_BUFFER_DATA (in_buf), gb->height * gb->stride); gaussian_smooth (gb, GST_BUFFER_DATA (in_buf), GST_BUFFER_DATA (out_buf)); return GST_FLOW_OK; }
/******************************************************************************* * PROCEDURE: canny * PURPOSE: To perform canny edge detection. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void canny(unsigned char *image, int rows, int cols, float sigma, float tlow, float thigh, unsigned char **edge, char *fname) { FILE *fpdir=NULL; /* File to write the gradient image to. */ unsigned char *nms; /* Points that are local maximal magnitude. */ short int *smoothedim, /* The image after gaussian smoothing. */ *delta_x, /* The first devivative image, x-direction. */ *delta_y, /* The first derivative image, y-direction. */ *magnitude; /* The magnitude of the gadient image. */ int r, c, pos; float *dir_radians=NULL; /* Gradient direction image. */ pthread_t radian_thread; thread_args_t targs; int rc; void *status; /**************************************************************************** * Perform gaussian smoothing on the image using the input standard * deviation. ****************************************************************************/ if(VERBOSE) printf("Smoothing the image using a gaussian kernel.\n"); gaussian_smooth(image, rows, cols, sigma, &smoothedim); /**************************************************************************** * Compute the first derivative in the x and y directions. ****************************************************************************/ if(VERBOSE) printf("Computing the X and Y first derivatives.\n"); derrivative_x_y(smoothedim, rows, cols, &delta_x, &delta_y); /**************************************************************************** * This option to write out the direction of the edge gradient was added * to make the information available for computing an edge quality figure * of merit. ****************************************************************************/ if (fname != NULL){ targs.delta_x = delta_x; targs.delta_y = delta_y; targs.rows = rows; targs.cols = cols; targs.fname = fname; rc = pthread_create(&radian_thread, NULL, radian_thread_function, (void *)&targs); if (rc){ printf("ERROR; return code from pthread_create() is %d\n", rc); exit(-1); } } /**************************************************************************** * Compute the magnitude of the gradient. ****************************************************************************/ if(VERBOSE) printf("Computing the magnitude of the gradient.\n"); magnitude_x_y(delta_x, delta_y, rows, cols, &magnitude); /**************************************************************************** * Perform non-maximal suppression. ****************************************************************************/ if(VERBOSE) printf("Doing the non-maximal suppression.\n"); if((nms = (unsigned char *) calloc(rows*cols,sizeof(unsigned char)))==NULL){ fprintf(stderr, "Error allocating the nms image.\n"); exit(1); } non_max_supp(magnitude, delta_x, delta_y, rows, cols, nms); /**************************************************************************** * Use hysteresis to mark the edge pixels. ****************************************************************************/ if(VERBOSE) printf("Doing hysteresis thresholding.\n"); if((*edge=(unsigned char *)calloc(rows*cols,sizeof(unsigned char))) ==NULL){ fprintf(stderr, "Error allocating the edge image.\n"); exit(1); } apply_hysteresis(magnitude, nms, rows, cols, tlow, thigh, *edge); if (fname != NULL){ rc = pthread_join(radian_thread, &status); if (rc){ printf("ERROR; return code from pthread_join() is %d\n", rc); exit(-1); } } /**************************************************************************** * Free all of the memory that we allocated except for the edge image that * is still being used to store out result. ****************************************************************************/ free(smoothedim); free(delta_x); free(delta_y); free(magnitude); free(nms); }
/******************************************************************************* * PROCEDURE: canny * PURPOSE: To perform canny edge detection. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void canny(unsigned char *image, int rows, int cols, float sigma, float tlow, float thigh, unsigned char **edge, char *fname) { FILE *fpdir=NULL; /* File to write the gradient image to. */ unsigned char *nms; /* Points that are local maximal magnitude. */ short int *smoothedim, /* The image after gaussian smoothing. */ *delta_x, /* The first devivative image, x-direction. */ *delta_y, /* The first derivative image, y-direction. */ *magnitude; /* The magnitude of the gadient image. */ float *dir_radians=NULL; /* Gradient direction image. */ /**************************************************************************** * Perform gaussian smoothing on the image using the input standard * deviation. ****************************************************************************/ if(VERBOSE) printf("Smoothing the image using a gaussian kernel.\n"); smoothedim = gaussian_smooth(image, rows, cols, sigma); /**************************************************************************** * Compute the first derivative in the x and y directions. ****************************************************************************/ if(VERBOSE) printf("Computing the X and Y first derivatives.\n"); derrivative_x_y(smoothedim, rows, cols, &delta_x, &delta_y); /**************************************************************************** * This option to write out the direction of the edge gradient was added * to make the information available for computing an edge quality figure * of merit. ****************************************************************************/ if(fname != NULL) { /************************************************************************* * Compute the direction up the gradient, in radians that are * specified counteclockwise from the positive x-axis. *************************************************************************/ radian_direction(delta_x, delta_y, rows, cols, &dir_radians, -1, -1); /************************************************************************* * Write the gradient direction image out to a file. *************************************************************************/ if((fpdir = fopen(fname, "wb")) == NULL) { fprintf(stderr, "Error opening the file %s for writing.\n", fname); exit(1); } fwrite(dir_radians, sizeof(float), rows*cols, fpdir); fclose(fpdir); free(dir_radians); } /**************************************************************************** * Compute the magnitude of the gradient. ****************************************************************************/ /**************************************************************************** * Allocate an image to store the magnitude of the gradient. ****************************************************************************/ if((magnitude = (short *) malloc(rows*cols* sizeof(short))) == NULL) { fprintf(stderr, "Error allocating the magnitude image.\n"); exit(1); } if(VERBOSE) printf("Computing the magnitude of the gradient.\n"); magnitude_x_y(delta_x, delta_y, rows, cols, magnitude); /**************************************************************************** * Perform non-maximal suppression. ****************************************************************************/ if(VERBOSE) printf("Doing the non-maximal suppression.\n"); if((nms = (unsigned char *) malloc(rows*cols*sizeof(unsigned char)))==NULL) { fprintf(stderr, "Error allocating the nms image.\n"); exit(1); } non_max_supp(magnitude, delta_x, delta_y, rows, cols, nms); /**************************************************************************** * Use hysteresis to mark the edge pixels. ****************************************************************************/ if(VERBOSE) printf("Doing hysteresis thresholding.\n"); if( (*edge=(unsigned char *)malloc(rows*cols*sizeof(unsigned char))) == NULL ) { fprintf(stderr, "Error allocating the edge image.\n"); exit(1); } apply_hysteresis(magnitude, nms, rows, cols, tlow, thigh, *edge); /**************************************************************************** * Free all of the memory that we allocated except for the edge image that * is still being used to store out result. ****************************************************************************/ free(smoothedim); free(delta_x); free(delta_y); free(magnitude); free(nms); }
/******************************************************************************* * PROCEDURE: canny * PURPOSE: To perform canny edge detection. * NAME: Mike Heath * DATE: 2/15/96 *******************************************************************************/ void canny(unsigned char *image, int rows, int cols, float sigma, float tlow, float thigh, unsigned char **edge) { unsigned char *nms; /* Points that are local maximal magnitude. */ short int *smoothedim, /* The image after gaussian smoothing. */ *delta_x, /* The first devivative image, x-direction. */ *delta_y, /* The first derivative image, y-direction. */ *magnitude; /* The magnitude of the gadient image. */ float *dir_radians=NULL; /* Gradient direction image. */ /**************************************************************************** * Perform gaussian smoothing on the image using the input standard * deviation. ****************************************************************************/ if(VERBOSE) mexPrintf("Smoothing the image using a gaussian kernel.\n"); gaussian_smooth(image, rows, cols, sigma, &smoothedim); /**************************************************************************** * Compute the first derivative in the x and y directions. ****************************************************************************/ if(VERBOSE) mexPrintf("Computing the X and Y first derivatives.\n"); derrivative_x_y(smoothedim, rows, cols, &delta_x, &delta_y); /**************************************************************************** * Compute the magnitude of the gradient. ****************************************************************************/ if(VERBOSE) mexPrintf("Computing the magnitude of the gradient.\n"); magnitude_x_y(delta_x, delta_y, rows, cols, &magnitude); /**************************************************************************** * Perform non-maximal suppression. ****************************************************************************/ if(VERBOSE) mexPrintf("Doing the non-maximal suppression.\n"); if((nms = (unsigned char *) calloc(rows*cols,sizeof(unsigned char)))==NULL){ fprintf(stderr, "Error allocating the nms image.\n"); exit(1); } non_max_supp(magnitude, delta_x, delta_y, rows, cols, nms); /**************************************************************************** * Use hysteresis to mark the edge pixels. ****************************************************************************/ if(VERBOSE) mexPrintf("Doing hysteresis thresholding.\n"); if((*edge=(unsigned char *)calloc(rows*cols,sizeof(unsigned char))) ==NULL){ fprintf(stderr, "Error allocating the edge image.\n"); exit(1); } apply_hysteresis(magnitude, nms, rows, cols, tlow, thigh, *edge); /**************************************************************************** * Free all of the memory that we allocated except for the edge image that * is still being used to store out result. ****************************************************************************/ free(smoothedim); free(delta_x); free(delta_y); free(magnitude); free(nms); }