Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "cv.h"
- #include "highgui.h"
- int main(int argc, char* argv[])
- {
- int w, h, nc; int step;
- int x, y, i;
- IplImage* img; IplImage* img2;
- int Y, R, G, B;
- int *ary[9]={0};
- //if( argc == 2 && (img = cvLoadImage(argv[1], -1)) != 0 )
- if( (img = cvLoadImage("step_up_rev.jpg", CV_LOAD_IMAGE_GRAYSCALE )) != 0 ) //
- {
- printf("Channels %d depth %d widthStep %d \n",
- img->nChannels, img->depth, img->widthStep);
- printf("The image Width by Height is %d * %d \n", img->width,img->height);
- printf("The image origin is %d\n", img->origin);
- step = img->widthStep;
- w = img->width;
- h = img->height;
- nc = img->nChannels;
- img2 = cvCreateImage(
- cvSize(w, h), //CvSize size,
- IPL_DEPTH_8U , //int depth,
- nc //int channels
- );
- cvNamedWindow( "Image 2", 1 );
- cvShowImage( "Image 2", img2 );
- cvNamedWindow( "Image 1", 1 );
- cvShowImage( "Image 1", img );
- cvWaitKey(0);
- uchar* ptr;
- uchar* ptr2;
- int temp;
- for (y = 1; y < h-1; y++) // using macro
- {
- for (x = 1; x < w-1; x++)
- {
- ptr = &CV_IMAGE_ELEM(img, uchar, y, x * img->nChannels);
- ptr2 = &CV_IMAGE_ELEM(img2, uchar, y, x * img2->nChannels);
- //CV_IMAGE_ELEM( image, elemtype, row, col )
- temp =
- 0*ptr[-2-2*step] + ptr[-1-2*step] + 2*ptr[-2*step] + ptr[1-2*step] + 0*ptr[2-2*step] +
- ptr[-2-step] + 3*ptr[-1-step] + 5*ptr[0-step] + 3*ptr[1-step] + ptr[2-step] +
- 2*ptr[-2] + 5*ptr[-1] + 9*ptr[0] + 5*ptr[1] + 2*ptr[2] +
- ptr[step-2] + 3*ptr[step-1] + 5*ptr[step+0] + 3*ptr[step+1] + ptr[step+2] +
- 0*ptr[2*step-2] + ptr[-1+2*step] + 2*ptr[2*step] + ptr[1+2*step] + 0*ptr[2+2*step] ;
- // 5*5 Filter
- ptr2[0] = temp/25;
- }
- }
- cvShowImage( "Image 2", img2 );
- cvWaitKey(0);
- cvDestroyWindow( "Image 2" );
- cvDestroyWindow( "Image 1" );
- cvReleaseImage( &img );
- cvReleaseImage( &img2 );
- return 0;
- }
- printf("Can't opne image file\n");system("PAUSE"); return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment