Details of the AND function in ImageJ

I used the AND function on 2 Images in ImageJ for my Bachelor Thesis.
And it might be pretty clear what an AND will do (thats why i used it) but im trying to find a clear definition about what ImageJ does with each Pixel when it compares them. Like if it has a Pixelvalue 200 and 500 and uses AND on that Pixel, does it give 200 because both have 200 in it but the rest (300) is just in one?
Or does ImageJ do something else?

Does anyone know what ImageJ exactly do?

Thanks for help!

Hi @MrBang,

From the code (Googling “ImageJ ImageCalculator Github”) , the image to image AND operation performs a “bitwise AND”.

This is why this result here looks weird at first sight:

Regarding your example: In the case of two 16-bit images where one pixel is 200 and another 500, the AND operation does this:

200: 011001000 // in binary
500: 111110100 // in binary

200 & 500 results in the following operation

& 111110100
= 011000000 // 192 when converted back to decimal

You can test this yourself by creating two images, making their values 200 and 500 respectively and applying the ImageCalculator AND

For 99% of intents and purposes, the AND operation is applied on binary images, which have values of either 0 or 255 pixels.
This results in the more common assumption that the AND operation will result in a pixel value of 255 only if the pixels in both images are 255, and 0 otherwise.

So there is no “comparison” of the values per-se, but a comparison of each bit that makes up the value.