Image Multiplication issue



Hi all…!

I am doing some steps to a image. Here I am taking and image and doing some processing on that and creating an mask. Then I multiply those two to get final result.

When I do this in separate steps using Fiji it works fine. 1st I have create the mask then save it. The Open both images and multiply it.

My actual task is to automate this process. So following is my sample code in java.

ImagePlus img = IJ.openImage();;

ImagePlus image2 = image1.duplicate();;

           // Steps to create the mask from image two

        ImageCalculator Cal1 = new ImageCalculator();
        ImagePlus FinalImage ="Multiply create 32-bit", img, image2);;

From these steps I cant the the expected result. When a user using this user has to open the image one time the rest of the steps should automate. Can any one tell whats the step I am doing wrong. I thing something happen with the memory.

This is the result what I get through coding…!

Thank you very much…!


could you please upload here the mask image file and original image file.?


Thank you for the quick response. Here you can find the images.

It is working when we load two images separately and do the calculation. The problem is when it try to load original image -> make the mask(keep that in the RAM) -> and then multiply with the 1st image(or a copy of 1st image) we load 1st.


so think the code to generate the mask is needed, in order to help you If this is the part where your code has problems

In any case, pay attention when you multiply in ImageJ/Fiji the mask image you’ve sent me has 255 and 0 values.
So if you multiply you are multiplying all your “good” values with 255, some times it’s not what you really want.
So basically, you can divide your mask image by 255 before multiiplying or use the AND operation in the image calculator dialog box, in both of these ways you can also avoid to generate a 32-bit image.


what is image1 in your code?


emartini is right, if you are using 8bit files, and your mask is white=255 and black=0, you use the AND operator to keep in the new image what was white in the mask.