Ask Your Question

anatrong0's profile - activity

2020-05-11 13:44:55 -0600 received badge  Famous Question (source)
2018-04-18 04:19:46 -0600 received badge  Notable Question (source)
2017-05-10 03:08:04 -0600 received badge  Popular Question (source)
2015-09-10 10:05:20 -0600 commented question strategy to build asynchronic subpixel registration analysis

6.64 ms if I use codes inside int main and not sepparate function

2015-09-10 09:57:15 -0600 commented question strategy to build asynchronic subpixel registration analysis

tried linear case, with single Stream but that is roughly same speed as w/o

with stream: 7.4745 ms w/o: 7.57892 ms

(averaged over 1000 readouts)

for (int i=0; i<1000;i++){
g_disk.upload(readDisk(fs,tmp0, disk),myStream);
cudaDFT2D(g_disk, G_disk, G_gauss_dx, G_gauss_dy, g_disk_dx, g_disk_dy, G_magnitude, myStream);  
g_disk_dx.download(disk,myStream);}

compared with functions without myStream. I also made sepparate function so need to check whether this dos not influence speed

2015-09-10 07:31:31 -0600 commented question strategy to build asynchronic subpixel registration analysis

I will try. My analysis has 5x dft + 2x mulSpectrum + 1x magnitude per each image 512x512 (zero padded due to the features close to image border) and these are done without CPU code in-line, therefore I thought if CUDA may be better here. It may be faster on CPU but not so parallel (at least I think)

2015-09-09 16:56:53 -0600 received badge  Scholar (source)
2015-09-09 13:46:04 -0600 answered a question cross-correlation of 2 same sized images

to cross-correlate same size images:

//FORWARD TRANSFORMS
cv::cuda::dft(image1, G_image1, Size(SIZE,SIZE), DFT_SCALE);        
cv::cuda::dft(image2, G_image2, Size(SIZE,SIZE), DFT_SCALE);        

//MULTIPLY CONJUGATE
cv::cuda::mulSpectrums(G_image1,G_image2,G_image1,true);    

//BACKWARD TRANSFORM
cv::cuda::dft(G_image1,RESULT,Size(SIZE,SIZE),DFT_REAL_OUTPUT | DFT_SCALE);
  • result in unscaled cross-correlation
  • to scale between (-1,1): normalize source images to have mean(src's) = 0, StdDev(src's) = 1 before computation
2015-09-09 13:13:44 -0600 asked a question strategy to build asynchronic subpixel registration analysis

Hi, I am analysing set of images for subpixel image shifts. I have code which essantially loops through:

loop(){

  • read binary image, send it to GpuMat/cuda

//next 2 points are based on dft, mulSpectrums, magnitude (all cuda "Streamable")

  • convolve with smoothing/gradient kernels (cuda)
  • cross-correlate (phase-correlate) with base image (cuda)

// next are locating maximum of correlation pattern with subpixel precision

  • find maxLoc (cuda, but value sent to Point.x/Point.y on CPU)
  • copy maxLoc 3x3 neighbours into Mat (CPU)
  • subpixel registration by quadratic fit of 3x3 maxima neighbours (CPU)
  • resulting (x,y) pixel shifts are placed in shift maps (CPU) }

All this is computed ~65000 times, it takes about 8 minutes to compute (256x256 base 16 bit B&W images). Cuda card is not even heating up (nvidia-smi shows 6% GPU-Util).

Any suggestions on how to parallelize (the faster the better) this?

(also thanks to L.Berger who got me this far)

2015-09-01 05:14:01 -0600 received badge  Enthusiast
2015-08-29 06:58:47 -0600 commented answer cross-correlation of 2 same sized images

cuda::createLinearFilter() is the way to go

2015-08-28 15:27:13 -0600 commented answer cross-correlation of 2 same sized images

yes,

Ptr<cuda::convolution> conv = cuda::createConvolution(); conv->convolve(zero_padded_source1, source2 ,result, true);

But filter 2D will do all this better I guess

2015-08-28 10:14:27 -0600 answered a question cross-correlation of 2 same sized images

just zero pad one of the images to (double -1) size of the other and do

convolve(zero_padded_source1, source2 ,result, true);

2015-08-28 10:10:38 -0600 commented answer cross-correlation of 2 same sized images

Thanks, other software I used did not say how is the cross-correlation produced. I realised you just need to zero pad one of the images and use openCV convolution(ccor=true)

2015-08-23 18:36:57 -0600 asked a question cross-correlation of 2 same sized images

Is there a way to compute full cross-correlation (or phase correlation) for two images of same size?

-resulting image should be same size as 2 source images. Convolution will only give me one pixel image the way it is implemented.

Or do I have to compute it by dft and therefore code it manually? Essentially I am looking for subpixel template matching (for 2 same sized images where an object within shifts)

2015-06-09 21:30:02 -0600 received badge  Necromancer (source)
2015-06-09 14:24:56 -0600 commented answer 16bit raw file stream analysis

cool, I am not sure how much is this applicable but will give it a try. Images here are from Scanning TEM detector so it might be a little bit different

2015-06-09 13:57:00 -0600 commented answer 16bit raw file stream analysis

thanks for help, camera itself has 12bit counter and this is saved as 16bit raw file. It depends on our experiment how much of this space is filled. Counts are <20 in my example file (waste of space), but we do not have direct access to drivers or FPGA card which saves datasets. I'm doing analysis of data in proprietary software but I want to try something different.

2015-06-09 13:37:31 -0600 commented answer 16bit raw file stream analysis

ok, I am not programmer as is clear I think :) is your suggestion faster?

2015-06-09 13:19:05 -0600 received badge  Editor (source)
2015-06-09 13:17:09 -0600 answered a question 16bit raw file stream analysis

for anyone doing simmilar, to display normalised first image from 16bit 256x256 raw binary file with 256 bytes header, there is also endian conversion (many thanks to L.Berger)

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <fstream>          

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
        //file read
        ifstream fs;
        fs.open(argv[1], ios::in | ios::binary);
        unsigned short *tmp = new unsigned short [256*256];
        fs.seekg(256);
        fs.read((char*)tmp, 256*256*2 );
        fs.close();

    //endian conversion
    unsigned char*c = (unsigned char*)tmp;
    for (int i = 0; i < 65536*2; i += 2)
    swap(c[i], c[i + 1]);
    Mat imAcq = Mat(256, 256, CV_16UC1,tmp);// , tmp, 256 * 256 * sizeof(unsigned short));

    normalize(imAcq, imAcq, 0, 65536, NORM_MINMAX, -1, Mat() );

    //convert to 8bit for imshow
    Mat img8bit;
    imAcq.convertTo(img8bit,CV_8UC1,1/256.0);
    namedWindow( "8bit normalised", WINDOW_AUTOSIZE );
    imshow( "8bit normalised", img8bit );                   // Show image

    waitKey(0);                                          // Wait for a keystroke in the window
    return 0;
}
2015-06-09 12:20:41 -0600 commented answer 16bit raw file stream analysis

this seems to work:

Mat imAcq=Mat(256,256,CV_16UC1,tmp);
Mat mat1;
mat1 = imAcq/256;
imAcq = (imAcq - (256*mat1))*256+mat1;
2015-06-09 11:39:44 -0600 commented answer cv::Mat incorrect reading binary data

Can you please comment on this, I have same trouble.

2015-06-09 11:27:53 -0600 commented answer 16bit raw file stream analysis

OK thanks, that one works fine now. Other problem is now endians. Value 1 is given as 256 in my Mat. Is there any simple workaround? (if I multiply whole array by 256 in imageJ it gives me 1 for same pixel)

2015-06-09 10:24:33 -0600 commented answer 16bit raw file stream analysis

Hi, I got back to this and I am stuck bit further.. this code:

    int main( int argc, char** argv )
{
        ifstream fs;
        fs.open(argv[1], ios::in | ios::binary);
        unsigned short *tmp = new unsigned short[256*256];
        fs.seekg(256);
        fs.read(reinterpret_cast<char*>(tmp), 256*256*sizeof(unsigned short) );
        fs.close();

    Mat imAcq=Mat(256,256,CV_16UC1,&tmp,256*256*sizeof(unsigned short));
    for (long i=0; i<30000; i++)
    {
    cout << " "  << tmp[i]/256;
    }

creates tmp array with everything 256 x bigger, then if it is read in Mat imAcq=Mat(... it gets to segmentation fault. I am pretty sure my file is 16bit (unsigned short) and if I display values of tmp as in example it gets it right, any suggestions for quick, non all array fix?

2015-06-09 10:13:09 -0600 received badge  Supporter (source)