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[])
- {
- IplImage *img1; IplImage *img2;
- int w,h,nc,step;
- if((img1 = cvLoadImage("step_up_rev.jpg", CV_LOAD_IMAGE_GRAYSCALE ))== 0) //CV_LOAD_IMAGE_GRAYSCALE ==> gray
- { printf("Can't opne image file\n");system("PAUSE"); return -1; }
- printf("Channels %d depth %d widthStep %d \n",
- img1->nChannels, img1->depth, img1->widthStep);
- printf("The image Width by Height is %d * %d \n", img1->width,img1->height);
- printf("The image origin is %d\n", img1->origin);
- w = img1 -> width ;
- h = img1 -> height ;
- nc = img1 -> nChannels ;
- step = img1 -> widthStep ;
- img2 = cvCreateImage(
- cvSize(w, h), //CvSize size,
- IPL_DEPTH_8U , //int depth,
- nc ); //int channel
- cvNamedWindow( "Image 2", 1 );
- cvShowImage( "Image 2", img2 );
- cvNamedWindow( "Image 1", 1 );
- cvShowImage( "Image 1", img1 );
- cvWaitKey(0);
- uchar* ptr ;
- uchar* ptr2;
- int s=0,sum1 ,sum2;
- int x,y;
- for(x = 1 ; x < w-1 ; x ++)
- for(y = 1 ; y < h-1 ; y ++)
- {
- ptr = &CV_IMAGE_ELEM(img1, uchar, y, x * img1->nChannels);
- ptr2 = &CV_IMAGE_ELEM(img2, uchar, y, x * img2->nChannels);
- sum1 =
- (-1)*ptr[-1-step] + 0*ptr[-step] + ptr[1-step] +
- (-1)*ptr[-1] + 0*ptr[0] + ptr[1] +
- (-1)*ptr[-1+step] + 0*ptr[step] + ptr[step+1] ;
- sum2=
- (-1)*ptr[-1-step] + (-1)*ptr[-step] + (-1)*ptr[1-step] +
- 0*ptr[-1] + 0*ptr[0] + 0*ptr[1] +
- ptr[-1+step] + ptr[step] + ptr[step+1] ;
- if(sum1>255) sum1 = 255 ;
- else if(sum1<0) sum1 = -sum1 ;
- if(sum2>255) sum2 = 255 ;
- else if(sum2<0) sum2 = -sum2 ;
- sum1 = sum1 ;
- sum2 = sum2 ;
- s = sum1+sum2 ;
- ptr2[0] = s ;
- }
- cvShowImage( "Image 2", img2 );
- cvWaitKey(0);
- cvDestroyWindow( "Image 2" );
- cvDestroyWindow( "Image 1" );
- cvReleaseImage( &img1 );
- cvReleaseImage( &img2 );
- return 0;
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment