Skip to content

Instantly share code, notes, and snippets.

@raunaqbn
Last active June 14, 2016 10:44
Show Gist options
  • Save raunaqbn/f0d332ac51e5447b4526685f58e2710f to your computer and use it in GitHub Desktop.
Save raunaqbn/f0d332ac51e5447b4526685f58e2710f to your computer and use it in GitHub Desktop.
#include "chapter2.h"
void display_image(char** argv, int task)
{
// Load the image passed by the user
IplImage *pImage = cvLoadImage(argv[1]);
// Create a window using the HighGUI library.
// Give the window a title and assign a name to the window for future reference.
// Setting to autosize to take the size of image. If set to zero image will be scaled to fit window
cvNamedWindow("Original Image", CV_WINDOW_AUTOSIZE );
// Now we can use the image pointer and the display window to show the image
cvShowImage("Original Image" , pImage);
IplImage* pOut = NULL;
switch (task)
{
case APPLY_GAUSS:
pOut = smooth_display(pImage);
break;
case APPLY_PYR_DOWN:
pOut = apply_pyr_dow(pImage);
break;
case APPLY_CANNY:
pOut = apply_canny(pImage, 10, 100, 3);
if(pOut == NULL)
{
cout<<"Please feed greyscale image! the number of channels:"<<pImage->nChannels<<endl;
}
break;
default:
cout <<"Please enter a valid task choice"<<endl;
break;
}
if (pOut)
{
cvNamedWindow("Transformed output", CV_WINDOW_AUTOSIZE );
// Now we can use the image pointer and the display window to show the image
cvShowImage("Transformed output" , pOut);
}
cvWaitKey();
// Free allocated space for image
cvReleaseImage(&pImage);
if (pOut)
{
cvReleaseImage(&pOut);
cvDestroyWindow("Transformed output");
}
// Destroy the window you created
cvDestroyWindow("Original Image");
}
IplImage* smooth_display(IplImage* pImage)
{
IplImage* pImageSmooth = NULL;
// Create and image of the same size of 3 channels with 8bits/channel
pImageSmooth = cvCreateImage(cvGetSize(pImage),
IPL_DEPTH_8U,3);
// Call smoothing function to apply a 3x3 gaussian filter centered at each pixel
cvSmooth(pImage,pImageSmooth,CV_GAUSSIAN,3,3);
return pImageSmooth;
}
IplImage* apply_pyr_dow(IplImage* pImage)
{
IplImage* pOut = cvCreateImage(cvSize(pImage->width/2,pImage->height/2),pImage->depth,pImage->nChannels);
cvPyrDown(pImage,pOut,CV_GAUSSIAN_5x5);
return pOut;
}
IplImage* apply_canny(IplImage* pImage, double lowThresh, double highThresh, double aperture)
{
/*if (pImage->nChannels != 1)return NULL; /*For some reason even greyscale images ended up with 3 channels
need to investigate futher when I have time*/
IplImage* pOut = cvCreateImage(cvGetSize(pImage),
IPL_DEPTH_8U,1);
cvCanny(pImage, pOut, lowThresh, highThresh, aperture);
return pOut;
}
/*
void cvSmooth(const CvArr* src, CvArr* dst, int smoothtype=CV_GAUSSIAN, int size1=3, int size2=0, double sigma1=0, double sigma2=0 )
src – The source image
dst – The destination image
smoothtype –
Type of the smoothing:
CV_BLUR_NO_SCALE
CV_BLUR
CV_GAUSSIAN
CV_MEDIAN
CV_BILATERAL
size1 – The first parameter of the smoothing operation, the aperture width. Must be a positive odd number (1, 3, 5, ...)
size2 – The second parameter of the smoothing operation, the aperture height. Ignored by CV_MEDIAN and CV_BILATERAL methods.
In the case of simple scaled/non-scaled and Gaussian blur if size2 is zero, it is set to size1 .
Otherwise it must be a positive odd number.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment