Created
December 3, 2015 10:16
-
-
Save raquel-oliveira/5acb3e0be41b1f88333a to your computer and use it in GitHub Desktop.
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
#include "image.h" | |
void loadImage(const IplImage* img, const char *filename){ | |
img = cvLoadImage(filename, 1); | |
if (!img) { | |
printf("Could not load image file"); | |
exit(0); | |
} | |
} | |
/*void getDataImage(const IplImage* img, int* height, int* width, int* step, int* channels, uchar* data ){ | |
height = getHeight(img); | |
width = getWidth(img); | |
step = getStep(img); | |
channels = getChannels(img); | |
data = (uchar *) img->imageData; | |
}*/ | |
/** | |
* @return height of a image | |
*/ | |
int getHeight(IplImage* img){ | |
return img->height; | |
} | |
/** | |
* @return @width of an image | |
*/ | |
int getWidth(IplImage* img){ | |
return img->width; | |
} | |
/** | |
* @return the steps to traverse using width | |
*/ | |
int getStep(IplImage* img){ | |
return img->widthStep; | |
} | |
/** | |
* return number of channel in a image | |
*/ | |
int getChannels(IplImage* img){ | |
return img->nChannels; | |
} | |
/** | |
* Show an image in the screen | |
*/ | |
void showImage(IplImage* img){ | |
//create the window | |
cvNamedWindow("ImageWindow", CV_WINDOW_AUTOSIZE); | |
cvMoveWindow("ImageWindow", 100, 100); | |
// show the image | |
cvShowImage("ImageWindow", img ); | |
// wait for a key | |
cvWaitKey(0); | |
// release the image | |
cvReleaseImage(&img ); | |
} | |
CvScalar* getIntensityPixel(IplImage* img){ | |
int count = 0; | |
int size = img->height * img->width; | |
CvScalar *pixel = malloc(size * sizeof(CvScalar)); | |
for (int row = 0; row < img->height; row++){ | |
for (int col = 0; col < img->width; col++){ | |
pixel[count] = cvGet2D(img, row, col); | |
count++; | |
} | |
} | |
return pixel; | |
} | |
double *redIntensity(IplImage* img){ | |
int size = img->height*img->width; | |
double* red = malloc(size * sizeof(double)); | |
CvScalar *pixel = malloc(size * sizeof(CvScalar)); | |
pixel = getIntensityPixel(img); | |
for(int i = 0; i < size; i++){ | |
red[i] = pixel->val[2]; | |
} | |
return red; | |
} | |
//to red, to 1 bit | |
double *bits(IplImage* img){ | |
int size = img->height*img->width; | |
double *message = malloc(size * sizeof(int)); | |
double *color = redIntensity(img); | |
int aux; | |
for (int i = 0; i < size; i++){ | |
for (int j = 7; j > 0 ;j-- ) { | |
aux = get_bit(color[i], 8); | |
message[i] = message[i] + (aux * pow(2,j)); | |
} | |
} | |
return message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment