[Insight-users] ITK versus Opencv

M Miller croow at yahoo.com
Fri Jul 8 00:39:28 EDT 2011


OpenMP was replaced in OpenCV code over a year ago with TBB. CUDA optimization 
was added in Dec 2010, with support from NVIDIA. Here's an example OpenCV code 
listing showing some arbitrary low level operations. As you can see it's 
readable, writable, and debuggable code.

#include "opencv2\opencv.hpp" 
#include "opencv2\gpu\gpu.hpp"

using namespace cv;

//read an image from disk into (Mat)rix 'source'
Mat source = imread("c:\\test\\src.tif",0);

//draw a circle in the middle of the image
Point center(source.cols/2,source.rows/2);
circle(source,center,50,Scalar(255),5);

//read value of center pixel
uchar centerVal = source.at<uchar>(center);

//upload the image to CUDA GPU
gpu::GpuMat g_source(source);

//blur image on GPU
gpu::GpuMat g_blurred;
gpu::GaussianBlur(g_source,g_blurred,Size(0,0),1.0);

//download to host memory
Mat dest;
g_blurred.download(dest);

//subtract center pixel value from dest image
dest = dest - centerVal;

//save file to disk
imwrite("c:\\test\\dest.jpg",dest);

//show image in popup window
imshow("Output Window",dest);


I'm not going to address ITK vs. OpenCV because I think it's a bad idea to 
choose one over the other. I use ITK to compliment OpenCV.


More information about the Insight-users mailing list