Please help to complete beginner in programming.
I work with binary stack of 2 pictures and here is the plugin I use:
import ij.*;
import ij.plugin.filter.PlugInFilter;
import ij.process.*;
import java.awt.*;
protected ImageStack stack;
public int setup(String arg, ImagePlus imp) {
stack =imp.getStack();
return DOES_8G+STACK_REQUIRED;
}
public void run(ImageProcessor ip) {
BinaryProcessor bp
= new BinaryProcessor((ByteProcessor)ip);
bp.outline();
byte[] pixels;
int dimension = stack.getWidth()*stack.getHeight();
int[] sum = new int[dimension];
for (int i=1;i<=stack.getSize();i++) {
pixels = (byte[]) stack.getPixels(i);
for (int j=0;j<dimension;j++) {
sum[j] += pixels[j];
}
}
byte[] average = new byte[dimension];
for (int j=0;j<dimension;j++) {
average[j] = (byte) ((sum[j]/stack.getSize()) & 0xff);
}
stack.addSlice("Average",average);
}
}
As a result I see black pixels what are common for 2 pictures only. The rest of the picture is white.
But when & 0xFF is added after sum[j] += pixels[j], the plugin does averaging and I see gray also.
Please, answer in simpliest way as I scarcely understand how -128-+127 is converted in 0-255.
What values mean white, gray and black in java?
Thanks in advance...