Login  Register

Texture Direction ( angle of Dominating Texture in Image)

Posted by ashamim on Aug 11, 2011; 8:57am
URL: http://imagej.273.s1.nabble.com/Texture-Direction-angle-of-Dominating-Texture-in-Image-tp3683524.html

Hello Everyone

I have been trying to calculate the Texture direction of some sample images for example to remove some strips from the images I need to know their direction first. I don't know why but every time i get either 0 degrees or 90 degrees. I have even tried to create sample images on my own in which i have different angles for the dominating texture. On fourier transform plot the dominating direction is visible and is perpendicular to the one in spatial domain direction but i dont know why i dont get the right angle.

Following is my code.

Any help will be highly appreciated

 void calculate_std_stdi(Rectangle r)
          {
         
          double M  = r.width;
          double pi = Math.PI;
          double angle = pi/M;
          float [][]aspec = new float[r.width][r.height];
          double temp_aas = 0.0;   // average amplitude sum for stdi
         
          double temp_ang = 0.0;   // temporary angle having max amplitude sum for Fourier Spectrum
          double temp_ang2 = 0.0;  // temporary angle having max amplitude sum for Power Spectrum
          double temp = -Float.MAX_VALUE;   // temp values to check the max amplitude sum of fourier spectrum
          double temp2 = -Float.MAX_VALUE;  // temp value to check the max amplitude sum of Power Spectrum
         
         
          double i = 0;
          for(int x = 0 ; x<r.width; x++)
                {
                angle = pi/M;
                angle = angle*i;
                double temp_amp = 0.0;
                double temp_amp2 = 0.0;
                double j =1;
                        for(int y = 1; y<(r.width/2)-1; y++)
                        {
                        double  u1 = M/2.0 + (j * Math.cos(angle));
                        double  v1 = M/2.0 + (j * Math.sin(angle));
                        double u11 = M/2.0 - (j * Math.cos(angle));
                        double v11 = M/2.0 - (j * Math.sin(angle));
                        int u = (int)(u1+0.5);
                        int v = (int)(v1+0.5);
                        double temp_u = (double)u;
                        double temp_v = (double)v;
                       
                                if(temp_u == u1 && temp_v == v1)
                                        {
                                        temp_amp += (double)temp_mag[(int)u1][(int)v1];
                                        temp_amp2 += ip1.getPixelValue((int)u1,(int)v1);
                                        aspec[(int)u11][(int)v11] = (float)temp_mag[(int)u11][(int)v11];
                                        }
                   
                                        else
                                        {
                                        temp_amp += (double)(temp_mag[u][v]*(1.0-(u1-temp_u))*(1.0-(v1-temp_v)) + temp_mag[u+1][v]*((u1-temp_u))*(1.0-(v1-temp_v)) + temp_mag[u][v+1]*(1.0-(u1-temp_u))*((v1-temp_v)) + temp_mag[u+1][v+1]*((u1-temp_u))*((v1-temp_v)));
                                        aspec[(int)u11][(int)v11] = (float)(temp_mag[u][v]*(1.0-(u1-temp_u))*(1.0-(v1-temp_v)) + temp_mag[u+1][v]*((u1-temp_u))*(1.0-(v1-temp_v)) + temp_mag[u][v+1]*(1.0-(u1-temp_u))*((v1-temp_v)) + temp_mag[u+1][v+1]*((u1-temp_u))*((v1-temp_v)));
                                        temp_amp2 += (ip1.getPixelValue(u,v)*(1.0-(u1-temp_u))*(1.0-(v1-temp_v)) + ip1.getPixelValue(u+1,v)*((u1-temp_u))*(1.0-(v1-temp_v)) + ip1.getPixelValue(u,v+1)*(1.0-(u1-temp_u))*((v1-temp_v)) + ip1.getPixelValue(u+1,v+1)*((u1-temp_u))*((v1-temp_v)));
                                        }
                    j+=1.0;
                        }
                       
               
                                        if (temp_amp > temp)
                                        {
                                        temp = temp_amp;
                                        temp_ang = angle;
                                        }
                                        if(temp_amp2 > temp2)
                                        {
                                        temp2 = temp_amp2;
                                        temp_ang2 = angle;
                                        }
                temp_aas += temp_amp2;
                i+=1.0;
                }
                 
                 
               
                /*ImageProcessor ipp = new FloatProcessor(aspec);
                ImagePlus impp = new ImagePlus("Angular Spectrum", ipp);
                impp.show();
                */
               
                double temp_stdi = temp_aas/(M*temp2);
                std = temp_ang *(180.0/pi);
                //if(std >= 90.0)
                //std = std - 90.0;
                //std = temp_ang;
                //std2 = temp_ang2;
                //else
                //std = std+90.0;
                std2 = temp_ang2 * (180.0/pi);
                //if(std2 >= 90)
                //std2= std2 - 90;
                //else
                //std2 = std2+90;
                stdi = temp_stdi;
         }

Best Regards

Ahsan