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 |
sorry i didnt mention in my code
temp_amp is the fourier transform i have calculated my self and temp_amp2 is the power spectrum from the FHT class. B.R |
In reply to this post by ashamim
Hi Ahsan
For directionality of structures Jean-Yvez Tinevez wrote a nice plugin for us which is bundled in Fiji. Its called Directionality: http://fiji.sc/wiki/index.php/Directionality It uses Fourier components or local gradient. @Pasi - did you know you have a colleague at Abo.fi who is doing image analysis in Java? cheers Dan On Aug 12, 2011, at 6:00 AM, IMAGEJ automatic digest system wrote: > > Date: Thu, 11 Aug 2011 01:57:13 -0700 > From: ashamim <[hidden email]> > Subject: Texture Direction ( angle of Dominating Texture in Image) > > 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 > > ----- > Ahsan > -- > View this message in context: http://imagej.588099.n2.nabble.com/Texture-Direction-angle-of-Dominating-Texture-in-Image-tp6675577p6675577.html > Sent from the ImageJ mailing list archive at Nabble.com. Dr. Daniel James White BSc. (Hons.) PhD Senior Microscopist / Image Visualisation, Processing and Analysis Light Microscopy and Image Processing Facilities Max Planck Institute of Molecular Cell Biology and Genetics Pfotenhauerstrasse 108 01307 DRESDEN Germany +49 (0)15114966933 (German Mobile) +49 (0)351 210 2627 (Work phone at MPI-CBG) +49 (0)351 210 1078 (Fax MPI-CBG LMF) http://www.bioimagexd.net BioImageXD http://pacific.mpi-cbg.de Fiji - is just ImageJ (Batteries Included) http://www.chalkie.org.uk Dan's Homepages https://ifn.mpi-cbg.de Dresden Imaging Facility Network dan (at) chalkie.org.uk ( white (at) mpi-cbg.de ) |
Hello Dan
Thanks alot for the reply I really appreciate that. Though I have solved the problem at my end but this is a very useful link for me and some nice work done. B.R Ahsan |
Free forum by Nabble | Edit this page |