Login  Register

Re: Various imageJ questions

Posted by Sami Badawi-2 on Feb 22, 2008; 1:59pm
URL: http://imagej.273.s1.nabble.com/Various-imageJ-questions-tp3697110p3697111.html

Hi meastwood98,

-If i was in the middle of a method(function) and i wanted to end the
program immediately with a custom error message, how would i do this?

You can try:
javax.swing.JOptionPane.showMessageDialog(null,"Goodbye World!");
System.exit(0);

-If i have an array of values, what is the easiet way to arrange them in
descending order in the array?

Use: Arrays.sort(yourArray);
This method comes in different versions. Here is a link:
http://www.leepoint.net/notes-java/data/arrays/70sorting.html

-I can find the higest grey value using the measurement option in imageJ but
is there a way i can write something in a plugin to return the hightest grey
value to a variable?

Just running through all the byte values, mask and cast them to int to avoid
sign problems, should be pretty easy:

byte[] pixels = (byte[]) ip.getPixels();
int mask = 0xff;
int maxValue=0;
for (int i=0; i<pixels; i++) {
    int grayValue = pixels[i] & mask;
    maxValue = Math.max(maxValue,grayValue);
}
But there is probably a simpler way to do this.

-Sami Badawi
http://www.shapelogic.org