error in assignment size mismatch

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

error in assignment size mismatch

Postby chfeilong » Tue Nov 12, 2013 11:45 pm

QQ截图20131113113831.png
QQ截图20131113113831.png (5.17 KiB) Viewed 9619 times

as the picture shows :
I don't know source is 206116,destination 207025
I do not alloc memory at all ?
I use cout<<dims() to find bug,it seems in second for loop in GaborFilters.

Code: Select all
#include <stdio.h>
#include <arrayfire.h>
#include <iostream>
#include <math.h>
using namespace af;
using namespace std;

static void gabor(int w,double omega,double theta,array & G)
{
   // creat a specail Gabor wave;
   //G=gabor(w,omega,theta);
   //w :window size for example w=30;
   //omega: pi/2;
   //theta:radian ,stand for orientation;
   //omega=pi/(2*sqrt(2).^u);
   //theta=(pi*v)/8;

   int nx,ny;
   nx=w; ny= w;

   double k = 3*sqrt(2*log(2));
   double sigma = k/omega;
   // Parittomalla pituudella indeksit -(n-1)/2:(n-1)/2;
   // Parillisella -(n/2):(n/2-1);
   // Esim. 9 -> -4:4, 8 -> -4:3;
   array X,Y;
   if(nx%2>0)
      nx-=1;
   seq tx((-nx/2),1,nx/2-1);
   X=tile(array(tx,1,nx),nx);

   if(ny%2>0)
      ny-=1;
   seq ty((-ny/2),1,ny/2-1);
   Y=tile(array(ty,1,ny),ny);
   Y=-Y;
   G = 1/(2*Pi*sigma*sigma)* exp( -1/(2*sigma*sigma) * ( pow2(X*cos(theta)+Y*sin(theta))
      +pow2(-X*sin(theta)+Y*cos(theta))) + i*(omega*(X*cos(theta)+Y*sin(theta))) );
   //cout<<"G="<<(G.dims(0))<<"\n"<<(G.dims(1));
}

static void GaborFilters(int size,int vNum,int uNum,array &filters)
{
// The function creat a group of Gabor waves
//    filters = GaborFilters( size, vNum, uNum)
//    v = 0--4, vNum = 5
//    u = 0---7, uNum = 8
   const double Wmax = Pi/2;
   filters = constant(0,size,size,vNum*uNum,c32);
         
   for (int v = 0;v<vNum;v++){
      double omega = Wmax/ pow(sqrt(2),v);
      for (int u=0 ;u< uNum;u++) {
         int k = v*uNum + u ;
         const double Theta = (Pi/uNum)*u;
         array filter;
         gabor(size,omega,Theta,filter);
         cout<<(filter.dims(0))<<"\n"<<(filter.dims(1))<<"\n";
         filters(span,span,k) = filter;
         //fig("color", "heat");
         //fig("sub",vNum,uNum,k+1);
         //image(real(filters(span,span,k)));
         }
   }
}

int main(int argc, char ** argv)
{
    try {

        info();
      //timer t1=timer::start();
      array B=loadimage("E:\\iamge\\13.jpg",0);//B=768*1366
      array gabout=constant(0,B.dims(0),B.dims(1));
      int kernel=B.dims(1)/3;
      int vnum=5;
      int unum =8;
      array G1;

      GaborFilters(kernel,vnum,unum, G1);

      //gfor (array k,5,8,40)
      for(int k=5;k<40;k+=8)
      {
      array Imgabout = convolve(B,imag(G1(span,span,k)));
      array Regabout = convolve(B,real(G1(span,span,k)));
      array gab = sqrt( Imgabout*Imgabout +Regabout*Regabout );
      gabout = (gabout+gab)/5 ;
      //fig("sub",5,8,k);
      //image(gab);
         
      }
      //double t2=timer::stop(t1);
      //printf("time spand=%0.6f s \n",t2);
      image(gabout);


    } catch (af::exception& e) {
        fprintf(stderr, "%s\n", e.what());
    }

    #ifdef WIN32 // pause in Windows
    if (!(argc == 2 && argv[1][0] == '-')) {
        printf("hit [enter]...");
        fflush(stdout);
        getchar();
    }
    #endif
    return 0;
}
chfeilong
 
Posts: 104
Joined: Sun Aug 15, 2010 11:28 pm

Re: error in assignment size mismatch

Postby shehzan » Tue Nov 19, 2013 2:45 pm

Hi,

Can you upload the test image you are using to test the application?
----
Shehzan
Developer
AccelerEyes
User avatar
shehzan
 
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Re: error in assignment size mismatch

Postby chfeilong » Thu Nov 21, 2013 1:31 am

sorry!cause the image large, you can test with use your image,as if the size is large.
chfeilong
 
Posts: 104
Joined: Sun Aug 15, 2010 11:28 pm


Return to [archive-commercial] Programming & Development with ArrayFire

cron