Created
November 29, 2013 12:20
-
-
Save kumarkrishna/7704926 to your computer and use it in GitHub Desktop.
Creating knaive binary image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Author : Kumar Keishna Agarwal | |
//Mail : kumar.1994.14@gmail.com | |
#include <iostream> | |
#include <highgui.h> | |
#include <cv.h> | |
int main() | |
{ | |
IplImage* img,*gray; | |
//Creating Image | |
img=cvLoadImage("road7.jpg"); //Load image | |
gray=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,1); | |
/* cvCreateImage(cvGetSize(<name of source image>),<depth of source image>,<no. of channels>) */ | |
CvScalar pixel,pix,pix2; //structure to store four values | |
cvNamedWindow("window",0); | |
cvNamedWindow("win",0); | |
int i,j; | |
for(i=0;i<img->height;i++) | |
{ | |
for(j=0;j<img->width;j++) | |
{ | |
pix=cvGet2D(img,i,j); //Getting pixel from loaded image | |
/* cvGet2D(<image name>,<x coord>,<y coord>) */ | |
pixel.val[0]=pix.val[0]+pix.val[1]+pix.val[2]; | |
pixel.val[0]/=3; | |
if(pixel.val[0]>75) | |
pixel.val[0]=255; | |
else | |
pixel.val[0]=0; | |
cvSet2D(gray,i,j,pixel); //Set pixel | |
/*cvSet2D(<image name>,<x coord>,<y coord>, <name of pixel>) */ | |
} | |
} | |
cvShowImage("window",img); //Show Image | |
cvShowImage("win",gray); | |
cvWaitKey(0); //Wait Key (Default is keyStroke) | |
cvReleaseImage(&img); //Release image | |
cvDestroyWindow("window"); //Destroy window | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment