Open Computer Vision

November 11, 2010

Computing Cube of an Image

Filed under: OpenCV — colouredpages @ 1:13 pm

Let us see what changes happen when we cube the image. There are some special charecteristics which the numbers exhibit in the range of 0-1.When we apply some transformations let us see what affects they have on the image.


Consider 2 numbers 210 and 255.lets divde both of them by 250.They become 0.8235 and 0.98039.Now lets square them and they become 0.6781 and 0.9611.Now when we multiply both of them back by 255 they come back to the range 0-255 and the values are 172.9155 and 245.08.
Now observe the difference.
210 transformed to 172
250 transformed to 245
250-210=40
245-172=73
Which directly means that a lower range of numbers are converted to a wider range of numbers.Which once again means that if an object is not visible to the eye that clearly it might be more clearer after this transformation. In technical terms now there is a good contrast.Objects are more differentiable than they were previously.


#include "math.h"
 #include "conio.h"
 #include "cv.h"
 #include "highgui.h"
 #include "stdio.h"

 int main()
 {
     int i,j,k;
   double temp;
   uchar *datar,*dataf;
     IplImage *frame=cvLoadImage("airplane.jpg",1);
     int heightr,widthr,stepr,channelsr;
IplImage *result=cvCreateImage( cvGetSize(frame), 8, 3 );
printf("we are now going to square the image..we are going to apply the square function on the image ");
if(frame==NULL ) {
puts("unable to load the frame");exit(0);}
cvNamedWindow("original",CV_WINDOW_AUTOSIZE);
cvNamedWindow("Result",CV_WINDOW_AUTOSIZE);

heightr = result->height;
widthr = result->width;
stepr=result->widthStep;
channelsr=result->nChannels;
datar = (uchar *)result->imageData;

dataf = (uchar *)frame->imageData;

/*We would like to use the charecteristics of the numbers which numbers exhibit between zero and one ...
please observe the log and the power transformations on the image before having a look at the program..*/

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);/*to convert the number first in the range of 0-1*/
temp*=temp;temp*=temp;
temp*=255;/*converting back numbers in the range from 0-1 to 0-255*/
datar[i*stepr+j*channelsr+k]=cvRound(temp);}/*Here a truncation from double to integer would happen
and hence to avoid the same used cvRound*/
cvShowImage("Result", result);
cvShowImage("original", frame);

 cvSaveImage("airplane cube.jpg",result);
 cvWaitKey(0);
 cvDestroyWindow("original");
 cvDestroyWindow("Result");
 return 0;
 }

Now let us see what were the affects of this cubing on the image.

 

Before Cubing

After cubing

After Cubing

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.