3 Replies - 756 Views - Last Post: 10 July 2012 - 11:56 AM Rate Topic: -----

#1 mhunck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-July 12

Plotting an array in Java

Posted 10 July 2012 - 11:38 AM

I am having trouble tweaking some code for ImageJ. I am fairly new to Java, and some help on the basics would be great.
I want to be able to plot the relationship between two values (r and g). These are the red and green RGB values. I created a for loop to plot the relationship:
   
  for (i=0; i<20; i++)
     rg=r[i]/g[i];  
  Plot.setColor("red");
  Plot.add("line", x, rg);
  Plot.update();


An error says that it is looking for an array for the variable rg. Basically, the rg variable is not an array.

The full code is as follows:
  ylabel = "Intensity";
  if (bitDepth!=24)
     exit("RGB image required");
  setKeyDown("none");
  setRGBWeights(1,0,0); r=getProfile();
  setRGBWeights(0,1,0); g=getProfile();
  setRGBWeights(0,0,1); b=getProfile();
  getVoxelSize(vw, vh, vd, unit);
  x = newArray(r.length);
  for (i=0; i<x.length; i++)
     x[i] = i*vw;
  Plot.create("RGB Profiles","Distance ("+unit+")", ylabel);
  ymax = getMax(r,g,B)/>+5;
  //if (ymax>255) ymax=255;
  Plot.setLimits(0, (r.length-1)*vw, 0, ymax);

  for (i=0; i<20; i++)
     rg=r[i]/g[i];  
  Plot.setColor("red");
  Plot.add("line", x, rg);
  Plot.update();

  function getMax(a,b,c) {
      max=a[0];
     for (i=0; i<a.length; i++) {
        max = maxOf(max,a[i]);
        max = maxOf(max,b[i]);
        max = maxOf(max,c[i]);
     }
     return max;
  }


Could you help by explaining how to write the for loop so that it creates an array of data in order to plot it?

Is This A Good Question/Topic? 0
  • +

Replies To: Plotting an array in Java

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10186
  • View blog
  • Posts: 37,614
  • Joined: 27-December 08

Re: Plotting an array in Java

Posted 10 July 2012 - 11:42 AM

Java doesn't have a function keyword. So your code should fail to compile. Also, your code is hard to read. You need to work on your indentation conventions.
Was This Post Helpful? 0
  • +
  • -

#3 mhunck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-July 12

Re: Plotting an array in Java

Posted 10 July 2012 - 11:55 AM

I got this macro from a ImageJ site and it does run when I plot the single arrays of r, g, and b.

I am trying to alter it so I can see the relationship between the r&g, the r&b, and the b&g.
That is why I did this:
 	
for (i=0; i<20; i++)
   rg=r[i]/g[i]; 



I wanted to be able to create an array with the r and g arrays.
I am sure there is a way to divide r by g and still get an array (mainly because r and g are the same length).

Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10186
  • View blog
  • Posts: 37,614
  • Joined: 27-December 08

Re: Plotting an array in Java

Posted 10 July 2012 - 11:56 AM

This isn't Java, though, if it runs. There is no function keyword in Java. I'll move this to Other Languages, then.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1