Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
C++
void CannyThreshold(int, void*)
{
  /// Reduce noise with a kernel 3x3
  blur( src_gray, detected_edges, Size(3,3) );
 
  /// Canny detector
  Canny( detected_edges, detected_edges, lowThreshold, lowThreshold*ratio, kernel_size );
 
  /// Using Canny's output as a mask, we display our result
  dst = Scalar::all(0);
 
  src.copyTo( dst, detected_edges);
  imshow( window_name, dst );
  
  /// Wait until user exit program by pressing a key

 
    int m = getOptimalDFTSize( dst.rows );
    int n = getOptimalDFTSize( dst.cols ); // on the border add zero values
   copyMakeBorder(dst, padded, 0, m - dst.rows, 0, n - dst.cols, BORDER_CONSTANT, Scalar::all(0));
 
    Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
    Mat complexdst;
    merge(planes, 2, complexdst);         // Add to the expanded another plane with zeros

    dft(complexdst, complexdst);            // this way the result may fit in the source matrix
Posted
Comments
[no name] 24-Apr-14 8:22am    
Pretend for a second that no one in the world can read your mind.

1 solution

The line you specified creates an array of two Mat objects. The first object is the padded image of the original image (padding means adding a black border to the original image in order to make it optimal size for find the DFT as it should be a factor of 2 I guess). The second object is simply a black image which's the size is equal to padded image. This part will be used to store the complex part of the DFT image. Finally the two images in the planes are correspond to real and complex images of DFT. The function merge is used to create a two channel image out of the two planes.

C++
Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};</float>

You can change the type "float" to higher precision if you wish but do not use a type with lower precisions.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900