Various imageJ questions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Various imageJ questions

meastwood98
Hi, i have a few questions regarding imageJ and java plugins that i would like to ask.

-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?

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

-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?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Various imageJ questions

Sami Badawi-2
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
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: Various imageJ questions

Joachim Wesner
Hi again,

ImageJ Interest Group <[hidden email]> schrieb am 22.02.2008 14:59:37:

> 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);
>

I assume the original poster was more thinking along ending the *plugin*
from
somewhere deep in a method stack with a custom error message and returning
to ImageJ.
AFAIK this would require defining a user exception, "throwing" it when the
error occurs
and "catching" it at the upper plugin level, terminating the plugin
regularly.
Or is there already an IJ exception one can "throw" from a plugin without
terminating
IJ?

JW


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________