Hey guys I have a problem with my code…I’m writing with Java and using Macros. So far so good but I don’t get the image I want to at the end.
What I’m doing:
I select 2 images, do an image calculation like AND and merge the red and blue channel of the image with the image itself but let the green channel empty --> I get a purple image and it’s what I expect. Now I do an image calculation with OR with the selected 2 images and convert it into RGB.
When I do a final image calculation with the operator difference of the merged channeled image and the or calculated image, there should be something green in the new image, but it’s just all white… Any Ideas how to solve this?
Code:
The 2 images were simply selected by a dialog box which works correct…
ImageCalculator ic = new ImageCalculator();
//Perform selected Operator
ImagePlus imageFour;
ImagePlus imageThree = ic.run("Or create", imageOne, imageTwo);
new ImageConverter(imageThree).convertToRGB();
imageThree.setTitle("Union RGB");
imageThree.show();
if(operator == "Durchschnitt") {
imageFour = ic.run("And create", imageOne, imageTwo);
} else if(operator == "Differenz") {
imageFour = ic.run("Subtract create", imageOne, imageTwo);
} else if(operator == "Symmetrische Differenz") {
imageFour = ic.run("Difference create", imageOne, imageTwo);
} else return;
//Merge Channels
ImagePlus impRB = imageFour.duplicate();
impRB.setTitle("Red-Blue");
impRB.show();
IJ.run("Merge Channels...", "c1=Red-Blue c3=Red-Blue");
//Merge Union + Result
ImagePlus imageFive = ic.run("Difference create", imageThree, imageFour); //<-- This is the part where I want the green image output, if I'm using impRB I get a Null Pointer Exception
imageFive.setTitle("Union + Result");
imageFive.show();
Edit:
Image 1:
Image 2:
And the result at the end should look like this:
but all I get is this image without the green part, so that’s the problem.