Now after cubing the image let us see how to compute any power on the image.Since we have already have computed the cube of the image now let us try our hands on square rooting the image.
After trying to cube the image let us do some square rooting.Again we apply the same principle. First Divide the image numbers by 255, then apply the square root and then multiply back by 255.
#include "math.h"
#include "conio.h"
#include "cv.h"
#include "highgui.h"
#include "stdio.h"
#include <stdlib.h>
#define power 0.5
int main()
{
int i,j,k;double temp;
IplImage *frame=cvLoadImage("low.jpg",1);
IplImage *result=cvCreateImage( cvGetSize(frame), 8, 3 );
if(frame==NULL ) {
puts("unable to load the frame");exit(0);}
printf("Computing the power of an Image");
cvNamedWindow("original",CV_WINDOW_AUTOSIZE);
cvNamedWindow("Result",CV_WINDOW_AUTOSIZE);
int heightr = result->height;
int widthr = result->width;
int stepr=result->widthStep;
int channelsr=result->nChannels;
uchar *dataf=(uchar *)frame->imageData,*datar = (uchar *)result->imageData;
for(i=0;i<heightr;i++) for(j=0;j<widthr;j++) for(k=0;k<channelsr;k++)
{
temp=dataf[i*stepr+j*channelsr+k];
temp=(temp/255);
temp=pow(temp,power);/*using the power function from math.h*/
/*change the value of power to change the power applied on the image*/
temp*=255;
datar[i*stepr+j*channelsr+k]=cvRound(temp);//To avoid the truncation we would use cvRound
}
cvShowImage("Result", result);
cvShowImage("original", frame);
cvSaveImage("powerraised.jpg",result);
cvWaitKey(0);
cvDestroyWindow("original");
cvDestroyWindow("Result");
return 0;
}
Enhanced Image.If we observe closely the tower is more visible in the right image and the green area below the tower is more visible.
Advertisement


